mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-22 05:45:38 +00:00
MemoryCard: Defer creation of card until first save
Also do not overwrite the card if it failed to load.
This commit is contained in:
parent
cf9ef3d2ac
commit
94d0dd7b42
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue