GCMemcard: Let ImportFile() take a Savefile instead of a direntry and a vector of blocks.
This commit is contained in:
parent
c95f3cbb61
commit
daa76183ed
|
@ -834,12 +834,13 @@ GCMemcardGetSaveDataRetVal GCMemcard::GetSaveData(u8 index, std::vector<GCMBlock
|
||||||
return GCMemcardGetSaveDataRetVal::SUCCESS;
|
return GCMemcardGetSaveDataRetVal::SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
GCMemcardImportFileRetVal GCMemcard::ImportFile(const DEntry& direntry,
|
GCMemcardImportFileRetVal GCMemcard::ImportFile(const Savefile& savefile)
|
||||||
std::vector<GCMBlock>& saveBlocks)
|
|
||||||
{
|
{
|
||||||
if (!m_valid)
|
if (!m_valid)
|
||||||
return GCMemcardImportFileRetVal::NOMEMCARD;
|
return GCMemcardImportFileRetVal::NOMEMCARD;
|
||||||
|
|
||||||
|
const DEntry& direntry = savefile.dir_entry;
|
||||||
|
|
||||||
if (GetNumFiles() >= DIRLEN)
|
if (GetNumFiles() >= DIRLEN)
|
||||||
{
|
{
|
||||||
return GCMemcardImportFileRetVal::OUTOFDIRENTRIES;
|
return GCMemcardImportFileRetVal::OUTOFDIRENTRIES;
|
||||||
|
@ -876,8 +877,9 @@ GCMemcardImportFileRetVal GCMemcard::ImportFile(const DEntry& direntry,
|
||||||
|
|
||||||
int fileBlocks = direntry.m_block_count;
|
int fileBlocks = direntry.m_block_count;
|
||||||
|
|
||||||
FZEROGX_MakeSaveGameValid(m_header_block, direntry, saveBlocks);
|
std::vector<GCMBlock> blocks = savefile.blocks;
|
||||||
PSO_MakeSaveGameValid(m_header_block, direntry, saveBlocks);
|
FZEROGX_MakeSaveGameValid(m_header_block, direntry, blocks);
|
||||||
|
PSO_MakeSaveGameValid(m_header_block, direntry, blocks);
|
||||||
|
|
||||||
BlockAlloc UpdatedBat = GetActiveBat();
|
BlockAlloc UpdatedBat = GetActiveBat();
|
||||||
u16 nextBlock;
|
u16 nextBlock;
|
||||||
|
@ -886,7 +888,7 @@ GCMemcardImportFileRetVal GCMemcard::ImportFile(const DEntry& direntry,
|
||||||
{
|
{
|
||||||
if (firstBlock == 0xFFFF)
|
if (firstBlock == 0xFFFF)
|
||||||
PanicAlertFmt("Fatal Error");
|
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)
|
if (i == fileBlocks - 1)
|
||||||
nextBlock = 0xFFFF;
|
nextBlock = 0xFFFF;
|
||||||
else
|
else
|
||||||
|
|
|
@ -481,8 +481,8 @@ public:
|
||||||
|
|
||||||
GCMemcardGetSaveDataRetVal GetSaveData(u8 index, std::vector<GCMBlock>& saveBlocks) const;
|
GCMemcardGetSaveDataRetVal GetSaveData(u8 index, std::vector<GCMBlock>& saveBlocks) const;
|
||||||
|
|
||||||
// adds the file to the directory and copies its contents
|
// Adds the given savefile to the memory card, if possible.
|
||||||
GCMemcardImportFileRetVal ImportFile(const DEntry& direntry, std::vector<GCMBlock>& saveBlocks);
|
GCMemcardImportFileRetVal ImportFile(const Savefile& savefile);
|
||||||
|
|
||||||
// Fetches the savefile at the given directory index, if any.
|
// Fetches the savefile at the given directory index, if any.
|
||||||
std::optional<Savefile> ExportFile(u8 index) const;
|
std::optional<Savefile> ExportFile(u8 index) const;
|
||||||
|
|
|
@ -503,8 +503,7 @@ void GCMemcardManager::ImportFiles(int slot, const std::vector<Memcard::Savefile
|
||||||
|
|
||||||
for (const Memcard::Savefile& savefile : savefiles)
|
for (const Memcard::Savefile& savefile : savefiles)
|
||||||
{
|
{
|
||||||
std::vector<Memcard::GCMBlock> blocks(savefile.blocks);
|
const auto result = card->ImportFile(savefile);
|
||||||
const auto result = card->ImportFile(savefile.dir_entry, blocks);
|
|
||||||
|
|
||||||
// we've already checked everything that could realistically fail here, so this should only
|
// 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
|
// happen if the memory card data is corrupted in some way
|
||||||
|
|
Loading…
Reference in New Issue