MemoryCard: Filename -> Path
This commit is contained in:
parent
e0620fcd40
commit
f4aa5e1b98
|
@ -293,27 +293,27 @@ std::unique_ptr<MemoryCard> MemoryCard::Create()
|
|||
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>();
|
||||
mc->m_filename = filename;
|
||||
mc->m_path = path;
|
||||
|
||||
Error error;
|
||||
if (!FileSystem::FileExists(mc->m_filename.c_str())) [[unlikely]]
|
||||
if (!FileSystem::FileExists(mc->m_path.c_str())) [[unlikely]]
|
||||
{
|
||||
mc->Format();
|
||||
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(
|
||||
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 "
|
||||
"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);
|
||||
mc->Format();
|
||||
mc->m_filename = {};
|
||||
mc->m_path = {};
|
||||
mc->m_changed = false;
|
||||
}
|
||||
|
||||
|
@ -335,21 +335,21 @@ bool MemoryCard::SaveIfChanged(bool display_osd_message)
|
|||
|
||||
m_changed = false;
|
||||
|
||||
if (m_filename.empty())
|
||||
if (m_path.empty())
|
||||
return false;
|
||||
|
||||
std::string osd_key;
|
||||
std::string display_name;
|
||||
if (display_osd_message)
|
||||
{
|
||||
osd_key = fmt::format("memory_card_save_{}", m_filename);
|
||||
display_name = FileSystem::GetDisplayNameFromPath(m_filename);
|
||||
osd_key = fmt::format("memory_card_save_{}", m_path);
|
||||
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;
|
||||
if (!MemoryCardImage::SaveToFile(m_data, m_filename.c_str(), &error))
|
||||
if (!MemoryCardImage::SaveToFile(m_data, m_path.c_str(), &error))
|
||||
{
|
||||
if (display_osd_message)
|
||||
{
|
||||
|
@ -376,7 +376,7 @@ bool MemoryCard::SaveIfChanged(bool display_osd_message)
|
|||
void MemoryCard::QueueFileSave()
|
||||
{
|
||||
// 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;
|
||||
|
||||
// save in one second, that should be long enough for everything to finish writing
|
||||
|
|
|
@ -23,12 +23,12 @@ public:
|
|||
static constexpr u32 STATE_SIZE = 1 + 1 + 2 + 1 + 1 + 1 + MemoryCardImage::DATA_SIZE + 1;
|
||||
|
||||
static std::unique_ptr<MemoryCard> Create();
|
||||
static std::unique_ptr<MemoryCard> Open(std::string_view filename);
|
||||
static std::unique_ptr<MemoryCard> Open(std::string_view path);
|
||||
|
||||
const MemoryCardImage::DataArray& GetData() const { return m_data; }
|
||||
MemoryCardImage::DataArray& GetData() { return m_data; }
|
||||
const std::string& GetFilename() const { return m_filename; }
|
||||
void SetFilename(std::string filename) { m_filename = std::move(filename); }
|
||||
const std::string& GetFilename() const { return m_path; }
|
||||
void SetFilename(std::string filename) { m_path = std::move(filename); }
|
||||
|
||||
void Reset();
|
||||
bool DoState(StateWrapper& sw);
|
||||
|
@ -107,7 +107,7 @@ private:
|
|||
bool m_changed = false;
|
||||
|
||||
TimingEvent m_save_event;
|
||||
std::string m_filename;
|
||||
std::string m_path;
|
||||
|
||||
MemoryCardImage::DataArray m_data{};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue