|
|
@ -293,27 +293,27 @@ std::unique_ptr<MemoryCard> MemoryCard::Create()
|
|
|
|
return mc;
|
|
|
|
return mc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<MemoryCard> MemoryCard::Open(std::string_view filename)
|
|
|
|
std::unique_ptr<MemoryCard> MemoryCard::Open(std::string_view path)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::unique_ptr<MemoryCard> mc = std::make_unique<MemoryCard>();
|
|
|
|
std::unique_ptr<MemoryCard> mc = std::make_unique<MemoryCard>();
|
|
|
|
mc->m_filename = filename;
|
|
|
|
mc->m_path = path;
|
|
|
|
|
|
|
|
|
|
|
|
Error error;
|
|
|
|
Error error;
|
|
|
|
if (!FileSystem::FileExists(mc->m_filename.c_str())) [[unlikely]]
|
|
|
|
if (!FileSystem::FileExists(mc->m_path.c_str())) [[unlikely]]
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mc->Format();
|
|
|
|
mc->Format();
|
|
|
|
mc->m_changed = false;
|
|
|
|
mc->m_changed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!MemoryCardImage::LoadFromFile(&mc->m_data, mc->m_filename.c_str(), &error)) [[unlikely]]
|
|
|
|
else if (!MemoryCardImage::LoadFromFile(&mc->m_data, mc->m_path.c_str(), &error)) [[unlikely]]
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Host::AddIconOSDMessage(
|
|
|
|
Host::AddIconOSDMessage(
|
|
|
|
fmt::format("memory_card_{}", filename), ICON_FA_SD_CARD,
|
|
|
|
fmt::format("memory_card_{}", path), ICON_FA_SD_CARD,
|
|
|
|
fmt::format(TRANSLATE_FS("MemoryCard", "{} could not be read:\n{}\nThe memory card will NOT be saved.\nYou must "
|
|
|
|
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."),
|
|
|
|
"delete the memory card manually if you want to save."),
|
|
|
|
Path::GetFileName(filename), error.GetDescription()),
|
|
|
|
Path::GetFileName(path), error.GetDescription()),
|
|
|
|
Host::OSD_CRITICAL_ERROR_DURATION);
|
|
|
|
Host::OSD_CRITICAL_ERROR_DURATION);
|
|
|
|
mc->Format();
|
|
|
|
mc->Format();
|
|
|
|
mc->m_filename = {};
|
|
|
|
mc->m_path = {};
|
|
|
|
mc->m_changed = false;
|
|
|
|
mc->m_changed = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -335,21 +335,21 @@ bool MemoryCard::SaveIfChanged(bool display_osd_message)
|
|
|
|
|
|
|
|
|
|
|
|
m_changed = false;
|
|
|
|
m_changed = false;
|
|
|
|
|
|
|
|
|
|
|
|
if (m_filename.empty())
|
|
|
|
if (m_path.empty())
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
std::string osd_key;
|
|
|
|
std::string osd_key;
|
|
|
|
std::string display_name;
|
|
|
|
std::string display_name;
|
|
|
|
if (display_osd_message)
|
|
|
|
if (display_osd_message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
osd_key = fmt::format("memory_card_save_{}", m_filename);
|
|
|
|
osd_key = fmt::format("memory_card_save_{}", m_path);
|
|
|
|
display_name = FileSystem::GetDisplayNameFromPath(m_filename);
|
|
|
|
display_name = FileSystem::GetDisplayNameFromPath(m_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
INFO_LOG("Saving memory card to {}...", Path::GetFileTitle(m_filename));
|
|
|
|
INFO_LOG("Saving memory card to {}...", Path::GetFileTitle(m_path));
|
|
|
|
|
|
|
|
|
|
|
|
Error error;
|
|
|
|
Error error;
|
|
|
|
if (!MemoryCardImage::SaveToFile(m_data, m_filename.c_str(), &error))
|
|
|
|
if (!MemoryCardImage::SaveToFile(m_data, m_path.c_str(), &error))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (display_osd_message)
|
|
|
|
if (display_osd_message)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -376,7 +376,7 @@ bool MemoryCard::SaveIfChanged(bool display_osd_message)
|
|
|
|
void MemoryCard::QueueFileSave()
|
|
|
|
void MemoryCard::QueueFileSave()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// skip if the event is already pending, or we don't have a backing file
|
|
|
|
// skip if the event is already pending, or we don't have a backing file
|
|
|
|
if (m_save_event.IsActive() || m_filename.empty())
|
|
|
|
if (m_save_event.IsActive() || m_path.empty())
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
// save in one second, that should be long enough for everything to finish writing
|
|
|
|
// save in one second, that should be long enough for everything to finish writing
|
|
|
|