mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-23 14:25:37 +00:00
MemoryCard: Sanitize game titles for file names
This commit is contained in:
parent
ee5bf410e6
commit
bced237034
|
@ -24,6 +24,20 @@ MemoryCard::~MemoryCard()
|
||||||
SaveIfChanged(false);
|
SaveIfChanged(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MemoryCard::SanitizeGameTitleForFileName(const std::string_view& name)
|
||||||
|
{
|
||||||
|
std::string ret(name);
|
||||||
|
|
||||||
|
const u32 len = static_cast<u32>(ret.length());
|
||||||
|
for (u32 i = 0; i < len; i++)
|
||||||
|
{
|
||||||
|
if (ret[i] == '\\' || ret[i] == '/' || ret[i] == '?' || ret[i] == '*')
|
||||||
|
ret[i] = '_';
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
TickCount MemoryCard::GetSaveDelayInTicks()
|
TickCount MemoryCard::GetSaveDelayInTicks()
|
||||||
{
|
{
|
||||||
return System::GetTicksPerSecond() * SAVE_DELAY_IN_SECONDS;
|
return System::GetTicksPerSecond() * SAVE_DELAY_IN_SECONDS;
|
||||||
|
|
|
@ -15,6 +15,8 @@ public:
|
||||||
MemoryCard();
|
MemoryCard();
|
||||||
~MemoryCard();
|
~MemoryCard();
|
||||||
|
|
||||||
|
static std::string SanitizeGameTitleForFileName(const std::string_view& name);
|
||||||
|
|
||||||
static std::unique_ptr<MemoryCard> Create();
|
static std::unique_ptr<MemoryCard> Create();
|
||||||
static std::unique_ptr<MemoryCard> Open(std::string_view filename);
|
static std::unique_ptr<MemoryCard> Open(std::string_view filename);
|
||||||
|
|
||||||
|
|
|
@ -1815,7 +1815,8 @@ void UpdateMemoryCards()
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
card = MemoryCard::Open(g_host_interface->GetGameMemoryCardPath(s_running_game_title.c_str(), i));
|
card = MemoryCard::Open(g_host_interface->GetGameMemoryCardPath(
|
||||||
|
MemoryCard::SanitizeGameTitleForFileName(s_running_game_title).c_str(), i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "core/cheats.h"
|
#include "core/cheats.h"
|
||||||
#include "core/controller.h"
|
#include "core/controller.h"
|
||||||
#include "core/gpu.h"
|
#include "core/gpu.h"
|
||||||
|
#include "core/memory_card.h"
|
||||||
#include "core/system.h"
|
#include "core/system.h"
|
||||||
#include "frontend-common/fullscreen_ui.h"
|
#include "frontend-common/fullscreen_ui.h"
|
||||||
#include "frontend-common/game_list.h"
|
#include "frontend-common/game_list.h"
|
||||||
|
@ -1045,7 +1046,8 @@ void QtHostInterface::populateGameListContextMenu(const GameListEntry* entry, QW
|
||||||
paths[i] = QString::fromStdString(GetGameMemoryCardPath(entry->code.c_str(), i));
|
paths[i] = QString::fromStdString(GetGameMemoryCardPath(entry->code.c_str(), i));
|
||||||
break;
|
break;
|
||||||
case MemoryCardType::PerGameTitle:
|
case MemoryCardType::PerGameTitle:
|
||||||
paths[i] = QString::fromStdString(GetGameMemoryCardPath(entry->title.c_str(), i));
|
paths[i] = QString::fromStdString(
|
||||||
|
GetGameMemoryCardPath(MemoryCard::SanitizeGameTitleForFileName(entry->title).c_str(), i));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue