diff options
| author | Admiral H. Curtiss <pikachu025@gmail.com> | 2018-12-01 18:17:18 +0100 |
|---|---|---|
| committer | Admiral H. Curtiss <pikachu025@gmail.com> | 2018-12-10 20:24:20 +0100 |
| commit | 2351a6056749ffcd24779767c452ecfbff88c8d8 (patch) | |
| tree | 78eca0d6d04c21eaa63e5b0bbe0bf94b3bbf2c1c /Source/Core | |
| parent | 860e003b0c5f49c82b32b2787c5053d0ba821a99 (diff) | |
GCMemcard: Let GetDEntry() return std::optional<DEntry>.
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Core/HW/GCMemcard/GCMemcard.cpp | 23 | ||||
| -rw-r--r-- | Source/Core/Core/HW/GCMemcard/GCMemcard.h | 5 | ||||
| -rw-r--r-- | Source/Core/DolphinQt/GCMemcardManager.cpp | 5 |
3 files changed, 15 insertions, 18 deletions
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<DEntry> 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<DEntry> 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<DEntry> 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<DEntry> GetDEntry(u8 index) const; u32 GetSaveData(u8 index, std::vector<GCMBlock>& 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<DEntry> 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}); |
