diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp index 1580ac56e0..e64a3d98a6 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.cpp @@ -595,13 +595,12 @@ std::string GCMemcard::GetSaveComment2(u8 index) const DENTRY_STRLEN); } -bool GCMemcard::GetDEntry(u8 index, DEntry& dest) const +std::optional GCMemcard::GetDEntry(u8 index) const { if (!m_valid || index >= DIRLEN) - return false; + return std::nullopt; - dest = GetActiveDirectory().m_dir_entries[index]; - return true; + return GetActiveDirectory().m_dir_entries[index]; } u16 BlockAlloc::GetNextBlock(u16 Block) const @@ -803,8 +802,8 @@ u32 GCMemcard::CopyFrom(const GCMemcard& source, u8 index) if (!m_valid || !source.m_valid) return NOMEMCARD; - DEntry tempDEntry; - if (!source.GetDEntry(index, tempDEntry)) + std::optional tempDEntry = source.GetDEntry(index); + if (!tempDEntry) return NOMEMCARD; u32 size = source.DEntry_BlockCount(index); @@ -821,7 +820,7 @@ u32 GCMemcard::CopyFrom(const GCMemcard& source, u8 index) return NOMEMCARD; default: FixChecksums(); - return ImportFile(tempDEntry, saveData); + return ImportFile(*tempDEntry, saveData); } } @@ -976,14 +975,12 @@ u32 GCMemcard::ExportGci(u8 index, const std::string& fileName, const std::strin break; } - DEntry tempDEntry; - if (!GetDEntry(index, tempDEntry)) - { + std::optional tempDEntry = GetDEntry(index); + if (!tempDEntry) return NOMEMCARD; - } - Gcs_SavConvert(tempDEntry, offset); - gci.WriteBytes(&tempDEntry, DENTRY_SIZE); + Gcs_SavConvert(*tempDEntry, offset); + gci.WriteBytes(&tempDEntry.value(), DENTRY_SIZE); u32 size = DEntry_BlockCount(index); if (size == 0xFFFF) diff --git a/Source/Core/Core/HW/GCMemcard/GCMemcard.h b/Source/Core/Core/HW/GCMemcard/GCMemcard.h index 77f0165663..4df8412fff 100644 --- a/Source/Core/Core/HW/GCMemcard/GCMemcard.h +++ b/Source/Core/Core/HW/GCMemcard/GCMemcard.h @@ -397,8 +397,9 @@ public: u32 DEntry_CommentsAddress(u8 index) const; std::string GetSaveComment1(u8 index) const; std::string GetSaveComment2(u8 index) const; - // Copies a DEntry from u8 index to DEntry& data - bool GetDEntry(u8 index, DEntry& dest) const; + + // Fetches a DEntry from the given file index. + std::optional GetDEntry(u8 index) const; u32 GetSaveData(u8 index, std::vector& saveBlocks) const; diff --git a/Source/Core/DolphinQt/GCMemcardManager.cpp b/Source/Core/DolphinQt/GCMemcardManager.cpp index c3b4ce855a..a74a5dc01e 100644 --- a/Source/Core/DolphinQt/GCMemcardManager.cpp +++ b/Source/Core/DolphinQt/GCMemcardManager.cpp @@ -199,12 +199,11 @@ void GCMemcardManager::UpdateSlotTable(int slot) auto* icon = new QTableWidgetItem; icon->setData(Qt::DecorationRole, frames[0]); - DEntry d; - memcard->GetDEntry(file_index, d); + std::optional entry = memcard->GetDEntry(file_index); // TODO: This is wrong, the animation speed is not static and is already correctly calculated in // GetIconFromSaveFile(), just not returned - const u16 animation_speed = d.m_animation_speed; + const u16 animation_speed = entry ? entry->m_animation_speed : 1; const auto speed = (((animation_speed >> 8) & 1) << 2) + (animation_speed & 1); m_slot_active_icons[slot].push_back({speed, frames});