GCMemcard: Implement ExportFile() to get a file on a card with a single method call.

This commit is contained in:
Admiral H. Curtiss 2020-07-15 23:59:17 +02:00
parent 9b14cc8ea2
commit 3e7f537a9d
2 changed files with 19 additions and 0 deletions

View File

@ -909,6 +909,22 @@ GCMemcardImportFileRetVal GCMemcard::ImportFile(const DEntry& direntry,
return GCMemcardImportFileRetVal::SUCCESS;
}
std::optional<Savefile> GCMemcard::ExportFile(u8 index) const
{
if (!m_valid || index >= DIRLEN)
return std::nullopt;
Savefile savefile;
savefile.dir_entry = GetActiveDirectory().m_dir_entries[index];
if (savefile.dir_entry.m_gamecode == DEntry::UNINITIALIZED_GAMECODE)
return std::nullopt;
if (GetSaveData(index, savefile.blocks) != GCMemcardGetSaveDataRetVal::SUCCESS)
return std::nullopt;
return savefile;
}
GCMemcardRemoveFileRetVal GCMemcard::RemoveFile(u8 index) // index in the directory array
{
if (!m_valid)

View File

@ -505,6 +505,9 @@ public:
// adds the file to the directory and copies its contents
GCMemcardImportFileRetVal ImportFile(const DEntry& direntry, std::vector<GCMBlock>& saveBlocks);
// Fetches the savefile at the given directory index, if any.
std::optional<Savefile> ExportFile(u8 index) const;
// delete a file from the directory
GCMemcardRemoveFileRetVal RemoveFile(u8 index);