From daa76183edded04cc40a2bc57c331fff53f4c5bd Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 1 Aug 2020 14:17:00 +0200 Subject: [PATCH] GCMemcard: Let ImportFile() take a Savefile instead of a direntry and a vector of blocks. --- Source/Core/Core/HW/GCMemcard/GCMemcard.cpp | 12 +++++++----- Source/Core/Core/HW/GCMemcard/GCMemcard.h | 4 ++-- Source/Core/DolphinQt/GCMemcardManager.cpp | 3 +-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp index 473a9d795d..931db7d119 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp @@ -834,12 +834,13 @@ GCMemcardGetSaveDataRetVal GCMemcard::GetSaveData(u8 index, std::vector& 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 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 diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.h b/Source/Core/Core/HW/GCMemcard/GCMemcard.h index ca8c709716..0cea51a017 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.h +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.h @@ -481,8 +481,8 @@ public: GCMemcardGetSaveDataRetVal GetSaveData(u8 index, std::vector& saveBlocks) const; - // adds the file to the directory and copies its contents - GCMemcardImportFileRetVal ImportFile(const DEntry& direntry, std::vector& 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 ExportFile(u8 index) const; diff --git a/Source/Core/DolphinQt/GCMemcardManager.cpp b/Source/Core/DolphinQt/GCMemcardManager.cpp index 6c05dd4b93..0edc29d8e5 100644 --- a/Source/Core/DolphinQt/GCMemcardManager.cpp +++ b/Source/Core/DolphinQt/GCMemcardManager.cpp @@ -503,8 +503,7 @@ void GCMemcardManager::ImportFiles(int slot, const std::vector 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