MemoryCard: Defer creation of card until first save

Also do not overwrite the card if it failed to load.
This commit is contained in:
Stenzek 2024-09-03 20:13:03 +10:00
parent 44ba39e3ef
commit 4a8abbe342
No known key found for this signature in database
1 changed files with 14 additions and 8 deletions

View File

@ -302,17 +302,23 @@ std::unique_ptr<MemoryCard> MemoryCard::Open(std::string_view filename)
if (!FileSystem::FileExists(mc->m_filename.c_str())) [[unlikely]]
{
Host::AddIconOSDMessage(fmt::format("memory_card_{}", filename), ICON_FA_SD_CARD,
fmt::format(TRANSLATE_FS("OSDMessage", "Memory card '{}' does not exist, creating."),
Path::GetFileName(filename), Host::OSD_INFO_DURATION));
fmt::format(TRANSLATE_FS("MemoryCard", "{} does not exist, using empty memory card."),
Path::GetFileName(filename)),
Host::OSD_INFO_DURATION);
mc->Format();
mc->SaveIfChanged(true);
mc->m_changed = false;
}
else if (!MemoryCardImage::LoadFromFile(&mc->m_data, mc->m_filename.c_str(), &error)) [[unlikely]]
{
Host::AddIconOSDMessage(fmt::format("memory_card_{}", filename), ICON_FA_SD_CARD,
fmt::format(TRANSLATE_FS("OSDMessage", "Memory card '{}' could not be read: {}"),
Path::GetFileName(filename), Host::OSD_INFO_DURATION));
Host::AddIconOSDMessage(
fmt::format("memory_card_{}", filename), ICON_FA_SD_CARD,
fmt::format(TRANSLATE_FS("MemoryCard", "{} could not be read:\n{}\nThe memory card will NOT be saved.\nYou must "
"delete the memory card manually if you want to save."),
Path::GetFileName(filename), error.GetDescription()),
Host::OSD_CRITICAL_ERROR_DURATION);
mc->Format();
mc->m_filename = {};
mc->m_changed = false;
}
return mc;
@ -352,7 +358,7 @@ bool MemoryCard::SaveIfChanged(bool display_osd_message)
if (display_osd_message)
{
Host::AddIconOSDMessage(std::move(osd_key), ICON_FA_SD_CARD,
fmt::format(TRANSLATE_FS("OSDMessage", "Failed to save memory card to '{}': {}"),
fmt::format(TRANSLATE_FS("MemoryCard", "Failed to save memory card to '{}': {}"),
Path::GetFileName(display_name), error.GetDescription()),
Host::OSD_ERROR_DURATION);
}
@ -364,7 +370,7 @@ bool MemoryCard::SaveIfChanged(bool display_osd_message)
{
Host::AddIconOSDMessage(
std::move(osd_key), ICON_FA_SD_CARD,
fmt::format(TRANSLATE_FS("OSDMessage", "Saved memory card to '{}'."), Path::GetFileName(display_name)),
fmt::format(TRANSLATE_FS("MemoryCard", "Saved memory card to '{}'."), Path::GetFileName(display_name)),
Host::OSD_QUICK_DURATION);
}