System: Add file title memory card type

This commit is contained in:
Connor McLaughlin 2021-05-21 13:18:32 +10:00
parent 6aa78b11fe
commit ff0bd7abc4
4 changed files with 35 additions and 3 deletions

View file

@ -908,11 +908,13 @@ const char* Settings::GetControllerTypeDisplayName(ControllerType type)
return s_controller_display_names[static_cast<int>(type)]; return s_controller_display_names[static_cast<int>(type)];
} }
static std::array<const char*, 4> s_memory_card_type_names = {{"None", "Shared", "PerGame", "PerGameTitle"}}; static std::array<const char*, 5> s_memory_card_type_names = {
static std::array<const char*, 4> s_memory_card_type_display_names = { {"None", "Shared", "PerGame", "PerGameTitle", "PerGameFileTitle"}};
static std::array<const char*, 5> s_memory_card_type_display_names = {
{TRANSLATABLE("MemoryCardType", "No Memory Card"), TRANSLATABLE("MemoryCardType", "Shared Between All Games"), {TRANSLATABLE("MemoryCardType", "No Memory Card"), TRANSLATABLE("MemoryCardType", "Shared Between All Games"),
TRANSLATABLE("MemoryCardType", "Separate Card Per Game (Game Code)"), TRANSLATABLE("MemoryCardType", "Separate Card Per Game (Game Code)"),
TRANSLATABLE("MemoryCardType", "Separate Card Per Game (Game Title)")}}; TRANSLATABLE("MemoryCardType", "Separate Card Per Game (Game Title)"),
TRANSLATABLE("MemoryCardType", "Separate Card Per Game (File Title)")}};
std::optional<MemoryCardType> Settings::ParseMemoryCardTypeName(const char* str) std::optional<MemoryCardType> Settings::ParseMemoryCardTypeName(const char* str)
{ {

View file

@ -1821,6 +1821,28 @@ void UpdateMemoryCards()
} }
break; break;
case MemoryCardType::PerGameFileTitle:
{
const std::string display_name(FileSystem::GetDisplayNameFromPath(s_running_game_path));
const std::string_view file_title(FileSystem::GetFileTitleFromPath(display_name));
if (file_title.empty())
{
g_host_interface->AddFormattedOSDMessage(
5.0f,
g_host_interface->TranslateString("System",
"Per-game memory card cannot be used for slot %u as the running "
"game has no path. Using shared card instead."),
i + 1u);
card = MemoryCard::Open(g_host_interface->GetSharedMemoryCardPath(i));
}
else
{
card = MemoryCard::Open(
g_host_interface->GetGameMemoryCardPath(MemoryCard::SanitizeGameTitleForFileName(file_title).c_str(), i));
}
}
break;
case MemoryCardType::Shared: case MemoryCardType::Shared:
{ {
if (g_settings.memory_card_paths[i].empty()) if (g_settings.memory_card_paths[i].empty())

View file

@ -134,6 +134,7 @@ enum class MemoryCardType
Shared, Shared,
PerGame, PerGame,
PerGameTitle, PerGameTitle,
PerGameFileTitle,
Count Count
}; };

View file

@ -1050,6 +1050,13 @@ void QtHostInterface::populateGameListContextMenu(const GameListEntry* entry, QW
paths[i] = QString::fromStdString( paths[i] = QString::fromStdString(
GetGameMemoryCardPath(MemoryCard::SanitizeGameTitleForFileName(entry->title).c_str(), i)); GetGameMemoryCardPath(MemoryCard::SanitizeGameTitleForFileName(entry->title).c_str(), i));
break; break;
case MemoryCardType::PerGameFileTitle:
{
const std::string display_name(FileSystem::GetDisplayNameFromPath(entry->path));
paths[i] = QString::fromStdString(GetGameMemoryCardPath(
MemoryCard::SanitizeGameTitleForFileName(FileSystem::GetFileTitleFromPath(display_name)).c_str(), i));
}
break;
default: default:
break; break;
} }