System: Fix incorrect sanitization of memcard filenames

This commit is contained in:
Stenzek 2024-03-25 23:15:04 +10:00
parent 315524a89c
commit 7b8704aba1
No known key found for this signature in database
4 changed files with 12 additions and 34 deletions

View File

@ -36,20 +36,6 @@ MemoryCard::~MemoryCard()
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()
{
return System::GetTicksPerSecond() * SAVE_DELAY_IN_SECONDS;

View File

@ -20,8 +20,6 @@ public:
static constexpr u32 STATE_SIZE = 1 + 1 + 2 + 1 + 1 + 1 + MemoryCardImage::DATA_SIZE + 1;
static std::string SanitizeGameTitleForFileName(const std::string_view& name);
static std::unique_ptr<MemoryCard> Create();
static std::unique_ptr<MemoryCard> Open(std::string_view filename);

View File

@ -3068,21 +3068,18 @@ std::unique_ptr<MemoryCard> System::GetMemoryCardForSlot(u32 slot, MemoryCardTyp
// Playlist - use title if different.
if (HasMediaSubImages() && s_running_game_entry && s_running_game_title != s_running_game_entry->title)
{
card_path =
g_settings.GetGameMemoryCardPath(MemoryCard::SanitizeGameTitleForFileName(s_running_game_title), slot);
card_path = g_settings.GetGameMemoryCardPath(Path::SanitizeFileName(s_running_game_title), slot);
}
// Multi-disc game - use disc set name.
else if (s_running_game_entry && !s_running_game_entry->disc_set_name.empty())
{
card_path = g_settings.GetGameMemoryCardPath(
MemoryCard::SanitizeGameTitleForFileName(s_running_game_entry->disc_set_name), slot);
card_path =
g_settings.GetGameMemoryCardPath(Path::SanitizeFileName(s_running_game_entry->disc_set_name), slot);
}
// But prefer a disc-specific card if one already exists.
std::string disc_card_path =
g_settings.GetGameMemoryCardPath(MemoryCard::SanitizeGameTitleForFileName(
s_running_game_entry ? s_running_game_entry->title : s_running_game_title),
slot);
std::string disc_card_path = g_settings.GetGameMemoryCardPath(
Path::SanitizeFileName(s_running_game_entry ? s_running_game_entry->title : s_running_game_title), slot);
if (disc_card_path != card_path)
{
if (card_path.empty() || !g_settings.memory_card_use_playlist_title ||
@ -3122,8 +3119,7 @@ std::unique_ptr<MemoryCard> System::GetMemoryCardForSlot(u32 slot, MemoryCardTyp
else
{
Host::RemoveKeyedOSDMessage(std::move(message_key));
return MemoryCard::Open(
g_settings.GetGameMemoryCardPath(MemoryCard::SanitizeGameTitleForFileName(file_title).c_str(), slot));
return MemoryCard::Open(g_settings.GetGameMemoryCardPath(Path::SanitizeFileName(file_title).c_str(), slot));
}
}

View File

@ -856,12 +856,11 @@ void MainWindow::populateGameListContextMenu(const GameList::Entry* entry, QWidg
break;
case MemoryCardType::PerGameTitle:
{
paths[i] = QString::fromStdString(
g_settings.GetGameMemoryCardPath(MemoryCard::SanitizeGameTitleForFileName(entry->title), i));
paths[i] = QString::fromStdString(g_settings.GetGameMemoryCardPath(Path::SanitizeFileName(entry->title), i));
if (!entry->disc_set_name.empty() && g_settings.memory_card_use_playlist_title && !QFile::exists(paths[i]))
{
paths[i] = QString::fromStdString(
g_settings.GetGameMemoryCardPath(MemoryCard::SanitizeGameTitleForFileName(entry->disc_set_name), i));
paths[i] =
QString::fromStdString(g_settings.GetGameMemoryCardPath(Path::SanitizeFileName(entry->disc_set_name), i));
}
}
break;
@ -869,8 +868,8 @@ void MainWindow::populateGameListContextMenu(const GameList::Entry* entry, QWidg
case MemoryCardType::PerGameFileTitle:
{
const std::string display_name(FileSystem::GetDisplayNameFromPath(entry->path));
paths[i] = QString::fromStdString(g_settings.GetGameMemoryCardPath(
MemoryCard::SanitizeGameTitleForFileName(Path::GetFileTitle(display_name)), i));
paths[i] = QString::fromStdString(
g_settings.GetGameMemoryCardPath(Path::SanitizeFileName(Path::GetFileTitle(display_name)), i));
}
break;
default:
@ -1086,8 +1085,7 @@ void MainWindow::onCheatsActionTriggered()
void MainWindow::onCheatsMenuAboutToShow()
{
m_ui.menuCheats->clear();
connect(m_ui.menuCheats->addAction(tr("Cheat Manager")), &QAction::triggered, this,
&MainWindow::openCheatManager);
connect(m_ui.menuCheats->addAction(tr("Cheat Manager")), &QAction::triggered, this, &MainWindow::openCheatManager);
m_ui.menuCheats->addSeparator();
populateCheatsMenu(m_ui.menuCheats);
}