FullscreenUI: Fix shared memory card selection

pull/3782/head
Stenzek 2 months ago
parent 48a1a06f59
commit 2f9c587622
No known key found for this signature in database

@ -4278,10 +4278,9 @@ void FullscreenUI::DrawMemoryCardSettingsPage()
.c_str())
.value_or(default_type);
const bool is_shared = (effective_type == MemoryCardType::Shared);
std::optional<SmallString> path_value(bsi->GetOptionalSmallStringValue(
std::optional<SmallString> path_value = bsi->GetOptionalSmallStringValue(
"MemoryCards", path_keys[i],
IsEditingGameSettings(bsi) ? std::nullopt :
std::optional<const char*>((i == 0) ? "shared_card_1.mcd" : "shared_card_2.mcd")));
IsEditingGameSettings(bsi) ? std::nullopt : std::make_optional(Settings::GetDefaultSharedMemoryCardName(i)));
TinyString title;
title.format("{}##card_name_{}", FSUI_ICONVSTR(ICON_FA_FILE, "Shared Card Name"), i);
@ -4290,12 +4289,11 @@ void FullscreenUI::DrawMemoryCardSettingsPage()
{
ChoiceDialogOptions options;
std::vector<std::string> names;
bool current_value_added = false;
if (IsEditingGameSettings(bsi))
options.emplace_back("Use Global Setting", !path_value.has_value());
if (path_value.has_value() && !path_value->empty())
{
options.emplace_back(fmt::format("{} (Current)", path_value.value()), true);
names.emplace_back(path_value.value().view());
current_value_added |= !path_value.has_value();
options.emplace_back(FSUI_STR("Use Global Setting"), !path_value.has_value());
}
FileSystem::FindResultsArray results;
@ -4305,29 +4303,39 @@ void FullscreenUI::DrawMemoryCardSettingsPage()
for (FILESYSTEM_FIND_DATA& ffd : results)
{
const bool selected = (path_value.has_value() && path_value.value() == ffd.FileName);
options.emplace_back(std::move(ffd.FileName), selected);
current_value_added |= selected;
options.emplace_back(ffd.FileName, selected);
names.push_back(std::move(ffd.FileName));
}
OpenChoiceDialog(
title, false, std::move(options),
[game_settings = IsEditingGameSettings(bsi), i](s32 index, const std::string& title, bool checked) {
if (index < 0)
return;
// add current entry if it's missing, e.g. the file was removed
if (!current_value_added && path_value.has_value() && !path_value->empty())
{
options.emplace_back(fmt::format(FSUI_FSTR("{0} (Missing)"), Path::GetFileName(path_value.value())), true);
names.emplace_back(path_value.value().view());
}
const auto lock = Core::GetSettingsLock();
SettingsInterface* bsi = GetEditingSettingsInterface(game_settings);
if (game_settings && index == 0)
{
bsi->DeleteValue("MemoryCards", path_keys[i]);
}
else
{
if (game_settings)
index--;
bsi->SetStringValue("MemoryCards", path_keys[i], title.c_str());
}
SetSettingsChanged(bsi);
});
OpenChoiceDialog(title, false, std::move(options),
[names = std::move(names), i,
game_settings = IsEditingGameSettings(bsi)](s32 index, const std::string& title, bool checked) {
if (index < 0)
return;
const auto lock = Core::GetSettingsLock();
SettingsInterface* bsi = GetEditingSettingsInterface(game_settings);
if (game_settings && index == 0)
{
bsi->DeleteValue("MemoryCards", path_keys[i]);
}
else
{
if (game_settings)
index--;
bsi->SetStringValue("MemoryCards", path_keys[i],
Path::MakeRelative(names[index], EmuFolders::MemoryCards).c_str());
}
SetSettingsChanged(bsi);
});
}
}

@ -932,6 +932,7 @@ TRANSLATE_NOOP("FullscreenUI", "\"PlayStation\" and \"PSX\" are registered trade
TRANSLATE_NOOP("FullscreenUI", "change disc");
TRANSLATE_NOOP("FullscreenUI", "restart");
TRANSLATE_NOOP("FullscreenUI", "shut down");
TRANSLATE_NOOP("FullscreenUI", "{0} (Missing)");
TRANSLATE_NOOP("FullscreenUI", "{0} achievement unlocks have not been confirmed by the server. Continuing to {1} will result in loss of these unlocks. Once network connectivity has been re-established, these unlocks will be confirmed automatically.\n\nDo you want to {1} anyway?");
TRANSLATE_NOOP("FullscreenUI", "{} Frames");
TRANSLATE_NOOP("FullscreenUI", "{} deleted.");

@ -2599,9 +2599,19 @@ const char* Settings::GetMemoryCardTypeDisplayName(MemoryCardType type)
"MemoryCardType");
}
std::string Settings::GetDefaultSharedMemoryCardName(u32 slot)
{
return fmt::format("shared_card_{}.mcd", slot + 1);
const char* Settings::GetDefaultSharedMemoryCardName(u32 slot)
{
static constexpr std::array<const char*, NUM_CONTROLLER_AND_CARD_PORTS> default_names = {{
"shared_card_1.mcd",
"shared_card_2.mcd",
"shared_card_3.mcd",
"shared_card_4.mcd",
"shared_card_5.mcd",
"shared_card_6.mcd",
"shared_card_7.mcd",
"shared_card_8.mcd",
}};
return default_names[std::min(slot, NUM_CONTROLLER_AND_CARD_PORTS - 1)];
}
std::string Settings::GetSharedMemoryCardPath(u32 slot) const

@ -423,7 +423,7 @@ struct Settings : public GPUSettings
bool HasAnyPerGameMemoryCards() const;
/// Returns the default path to a memory card.
static std::string GetDefaultSharedMemoryCardName(u32 slot);
static const char* GetDefaultSharedMemoryCardName(u32 slot);
std::string GetSharedMemoryCardPath(u32 slot) const;
/// Returns the default path to a memory card for a specific game.

@ -5817,7 +5817,7 @@ std::string System::GetGameMemoryCardPath(std::string_view custom_title, std::st
{
const TinyString path_key = TinyString::from_format("Card{}Path", slot + 1);
std::string global_path =
Core::GetBaseStringSettingValue(section, path_key, Settings::GetDefaultSharedMemoryCardName(slot + 1).c_str());
Core::GetBaseStringSettingValue(section, path_key, Settings::GetDefaultSharedMemoryCardName(slot + 1));
if (ini && ini->ContainsValue(section, path_key))
ret = ini->GetStringValue(section, path_key, global_path.c_str());
else

@ -309,7 +309,7 @@ void MemoryCardSettingsWidget::onResetMemoryCardPathClicked(u32 index)
if (m_dialog->isPerGameSettings())
m_dialog->removeSettingValue("MemoryCards", key);
else
m_dialog->setStringSettingValue("MemoryCards", key, Settings::GetDefaultSharedMemoryCardName(index).c_str());
m_dialog->setStringSettingValue("MemoryCards", key, Settings::GetDefaultSharedMemoryCardName(index));
updateMemoryCardPath(index);
}
@ -318,7 +318,7 @@ void MemoryCardSettingsWidget::updateMemoryCardPath(u32 index)
{
const auto key = TinyString::from_format("Card{}Path", index + 1);
std::string path(
m_dialog->getEffectiveStringValue("MemoryCards", key, Settings::GetDefaultSharedMemoryCardName(index).c_str()));
m_dialog->getEffectiveStringValue("MemoryCards", key, Settings::GetDefaultSharedMemoryCardName(index)));
if (!Path::IsAbsolute(path))
path = Path::Canonicalize(Path::Combine(EmuFolders::MemoryCards, path));

Loading…
Cancel
Save