GCMemcard: Let ImportFile() take a Savefile instead of a direntry and a vector of blocks.

This commit is contained in:
Admiral H. Curtiss 2020-08-01 14:17:00 +02:00
parent c95f3cbb61
commit daa76183ed
3 changed files with 10 additions and 9 deletions

View File

@ -834,12 +834,13 @@ GCMemcardGetSaveDataRetVal GCMemcard::GetSaveData(u8 index, std::vector<GCMBlock
return GCMemcardGetSaveDataRetVal::SUCCESS;
}
GCMemcardImportFileRetVal GCMemcard::ImportFile(const DEntry& direntry,
std::vector<GCMBlock>& saveBlocks)
GCMemcardImportFileRetVal GCMemcard::ImportFile(const Savefile& savefile)
{
if (!m_valid)
return GCMemcardImportFileRetVal::NOMEMCARD;
const DEntry& direntry = savefile.dir_entry;
if (GetNumFiles() >= DIRLEN)
{
return GCMemcardImportFileRetVal::OUTOFDIRENTRIES;
@ -876,8 +877,9 @@ GCMemcardImportFileRetVal GCMemcard::ImportFile(const DEntry& direntry,
int fileBlocks = direntry.m_block_count;
FZEROGX_MakeSaveGameValid(m_header_block, direntry, saveBlocks);
PSO_MakeSaveGameValid(m_header_block, direntry, saveBlocks);
std::vector<GCMBlock> blocks = savefile.blocks;
FZEROGX_MakeSaveGameValid(m_header_block, direntry, blocks);
PSO_MakeSaveGameValid(m_header_block, direntry, blocks);
BlockAlloc UpdatedBat = GetActiveBat();
u16 nextBlock;
@ -886,7 +888,7 @@ GCMemcardImportFileRetVal GCMemcard::ImportFile(const DEntry& direntry,
{
if (firstBlock == 0xFFFF)
PanicAlertFmt("Fatal Error");
m_data_blocks[firstBlock - MC_FST_BLOCKS] = saveBlocks[i];
m_data_blocks[firstBlock - MC_FST_BLOCKS] = blocks[i];
if (i == fileBlocks - 1)
nextBlock = 0xFFFF;
else

View File

@ -481,8 +481,8 @@ public:
GCMemcardGetSaveDataRetVal GetSaveData(u8 index, std::vector<GCMBlock>& saveBlocks) const;
// adds the file to the directory and copies its contents
GCMemcardImportFileRetVal ImportFile(const DEntry& direntry, std::vector<GCMBlock>& saveBlocks);
// Adds the given savefile to the memory card, if possible.
GCMemcardImportFileRetVal ImportFile(const Savefile& savefile);
// Fetches the savefile at the given directory index, if any.
std::optional<Savefile> ExportFile(u8 index) const;

View File

@ -503,8 +503,7 @@ void GCMemcardManager::ImportFiles(int slot, const std::vector<Memcard::Savefile
for (const Memcard::Savefile& savefile : savefiles)
{
std::vector<Memcard::GCMBlock> blocks(savefile.blocks);
const auto result = card->ImportFile(savefile.dir_entry, blocks);
const auto result = card->ImportFile(savefile);
// we've already checked everything that could realistically fail here, so this should only
// happen if the memory card data is corrupted in some way