GCMemcard: Let GetDEntry() return std::optional<DEntry>.
This commit is contained in:
parent
860e003b0c
commit
2351a60567
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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});
|
||||
|
|
Loading…
Reference in New Issue