Merge pull request #5522 from leoetlino/simpler-gettitleid

DiscIO: Use std::optional for GetTitleID instead of pointer
This commit is contained in:
JosJuice 2017-06-04 08:57:36 +02:00 committed by GitHub
commit 703858e217
9 changed files with 31 additions and 26 deletions

View File

@ -719,9 +719,10 @@ void SConfig::ResetRunningGameMetadata()
void SConfig::SetRunningGameMetadata(const DiscIO::IVolume& volume, void SConfig::SetRunningGameMetadata(const DiscIO::IVolume& volume,
const DiscIO::Partition& partition) const DiscIO::Partition& partition)
{ {
u64 title_id = 0; const std::optional<u64> title_id = volume.GetTitleID(partition);
volume.GetTitleID(&title_id, partition); if (!title_id)
SetRunningGameMetadata(volume.GetGameID(partition), title_id, volume.GetRevision(partition), return;
SetRunningGameMetadata(volume.GetGameID(partition), *title_id, volume.GetRevision(partition),
Core::TitleDatabase::TitleType::Other); Core::TitleDatabase::TitleType::Other);
} }

View File

@ -219,11 +219,8 @@ bool UpdateRunningGameMetadata(const DiscIO::Partition& partition, std::optional
if (title_id) if (title_id)
{ {
u64 volume_title_id; const std::optional<u64> volume_title_id = s_disc->GetTitleID(partition);
if (!s_disc->GetTitleID(&volume_title_id, partition)) if (!volume_title_id || *volume_title_id != *title_id)
return false;
if (volume_title_id != *title_id)
return false; return false;
} }

View File

@ -8,6 +8,7 @@
#include <limits> #include <limits>
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional>
#include <string> #include <string>
#include <vector> #include <vector>
@ -53,8 +54,8 @@ public:
} }
virtual std::vector<Partition> GetPartitions() const { return {}; } virtual std::vector<Partition> GetPartitions() const { return {}; }
virtual Partition GetGamePartition() const { return PARTITION_NONE; } virtual Partition GetGamePartition() const { return PARTITION_NONE; }
bool GetTitleID(u64* buffer) const { return GetTitleID(buffer, GetGamePartition()); } std::optional<u64> GetTitleID() const { return GetTitleID(GetGamePartition()); }
virtual bool GetTitleID(u64* buffer, const Partition& partition) const { return false; } virtual std::optional<u64> GetTitleID(const Partition& partition) const { return {}; }
virtual const IOS::ES::TicketReader& GetTicket(const Partition& partition) const virtual const IOS::ES::TicketReader& GetTicket(const Partition& partition) const
{ {
return INVALID_TICKET; return INVALID_TICKET;

View File

@ -107,9 +107,12 @@ std::string CVolumeWAD::GetMakerID(const Partition& partition) const
return DecodeString(temp); return DecodeString(temp);
} }
bool CVolumeWAD::GetTitleID(u64* buffer, const Partition& partition) const std::optional<u64> CVolumeWAD::GetTitleID(const Partition& partition) const
{ {
return ReadSwapped(m_offset + 0x01DC, buffer, partition); u64 title_id;
if (!ReadSwapped(m_offset + 0x01DC, &title_id, partition))
return {};
return title_id;
} }
u16 CVolumeWAD::GetRevision(const Partition& partition) const u16 CVolumeWAD::GetRevision(const Partition& partition) const
@ -141,11 +144,11 @@ std::vector<u32> CVolumeWAD::GetBanner(int* width, int* height) const
*width = 0; *width = 0;
*height = 0; *height = 0;
u64 title_id; const std::optional<u64> title_id = GetTitleID();
if (!GetTitleID(&title_id)) if (!title_id)
return std::vector<u32>(); return std::vector<u32>();
return GetWiiBanner(width, height, title_id); return GetWiiBanner(width, height, *title_id);
} }
BlobType CVolumeWAD::GetBlobType() const BlobType CVolumeWAD::GetBlobType() const

View File

@ -6,6 +6,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional>
#include <string> #include <string>
#include <vector> #include <vector>
@ -33,7 +34,7 @@ public:
~CVolumeWAD(); ~CVolumeWAD();
bool Read(u64 offset, u64 length, u8* buffer, bool Read(u64 offset, u64 length, u8* buffer,
const Partition& partition = PARTITION_NONE) const override; const Partition& partition = PARTITION_NONE) const override;
bool GetTitleID(u64* buffer, const Partition& partition = PARTITION_NONE) const override; std::optional<u64> GetTitleID(const Partition& partition = PARTITION_NONE) const override;
const IOS::ES::TMDReader& GetTMD(const Partition& partition = PARTITION_NONE) const override; const IOS::ES::TMDReader& GetTMD(const Partition& partition = PARTITION_NONE) const override;
std::string GetGameID(const Partition& partition = PARTITION_NONE) const override; std::string GetGameID(const Partition& partition = PARTITION_NONE) const override;
std::string GetMakerID(const Partition& partition = PARTITION_NONE) const override; std::string GetMakerID(const Partition& partition = PARTITION_NONE) const override;

View File

@ -181,13 +181,12 @@ Partition CVolumeWiiCrypted::GetGamePartition() const
return m_game_partition; return m_game_partition;
} }
bool CVolumeWiiCrypted::GetTitleID(u64* buffer, const Partition& partition) const std::optional<u64> CVolumeWiiCrypted::GetTitleID(const Partition& partition) const
{ {
const IOS::ES::TicketReader& ticket = GetTicket(partition); const IOS::ES::TicketReader& ticket = GetTicket(partition);
if (!ticket.IsValid()) if (!ticket.IsValid())
return false; return {};
*buffer = ticket.GetTitleId(); return ticket.GetTitleId();
return true;
} }
const IOS::ES::TicketReader& CVolumeWiiCrypted::GetTicket(const Partition& partition) const const IOS::ES::TicketReader& CVolumeWiiCrypted::GetTicket(const Partition& partition) const
@ -289,11 +288,11 @@ std::vector<u32> CVolumeWiiCrypted::GetBanner(int* width, int* height) const
*width = 0; *width = 0;
*height = 0; *height = 0;
u64 title_id; const std::optional<u64> title_id = GetTitleID(GetGamePartition());
if (!GetTitleID(&title_id, GetGamePartition())) if (!title_id)
return std::vector<u32>(); return std::vector<u32>();
return GetWiiBanner(width, height, title_id); return GetWiiBanner(width, height, *title_id);
} }
u64 CVolumeWiiCrypted::GetFSTSize(const Partition& partition) const u64 CVolumeWiiCrypted::GetFSTSize(const Partition& partition) const

View File

@ -7,6 +7,7 @@
#include <map> #include <map>
#include <mbedtls/aes.h> #include <mbedtls/aes.h>
#include <memory> #include <memory>
#include <optional>
#include <string> #include <string>
#include <vector> #include <vector>
@ -33,7 +34,7 @@ public:
bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, const Partition& partition) const override; bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, const Partition& partition) const override;
std::vector<Partition> GetPartitions() const override; std::vector<Partition> GetPartitions() const override;
Partition GetGamePartition() const override; Partition GetGamePartition() const override;
bool GetTitleID(u64* buffer, const Partition& partition) const override; std::optional<u64> GetTitleID(const Partition& partition) const override;
const IOS::ES::TicketReader& GetTicket(const Partition& partition) const override; const IOS::ES::TicketReader& GetTicket(const Partition& partition) const override;
const IOS::ES::TMDReader& GetTMD(const Partition& partition) const override; const IOS::ES::TMDReader& GetTMD(const Partition& partition) const override;
std::string GetGameID(const Partition& partition) const override; std::string GetGameID(const Partition& partition) const override;

View File

@ -161,7 +161,8 @@ bool GameFile::TryLoadVolume()
m_game_id = QString::fromStdString(volume->GetGameID()); m_game_id = QString::fromStdString(volume->GetGameID());
std::string maker_id = volume->GetMakerID(); std::string maker_id = volume->GetMakerID();
volume->GetTitleID(&m_title_id); if (std::optional<u64> title_id = volume->GetTitleID())
m_title_id = *title_id;
m_maker = QString::fromStdString(DiscIO::GetCompanyFromID(maker_id)); m_maker = QString::fromStdString(DiscIO::GetCompanyFromID(maker_id));
m_maker_id = QString::fromStdString(maker_id); m_maker_id = QString::fromStdString(maker_id);
m_revision = volume->GetRevision(); m_revision = volume->GetRevision();

View File

@ -108,7 +108,8 @@ GameListItem::GameListItem(const std::string& _rFileName, const Core::TitleDatab
m_VolumeSize = volume->GetSize(); m_VolumeSize = volume->GetSize();
m_game_id = volume->GetGameID(); m_game_id = volume->GetGameID();
volume->GetTitleID(&m_title_id); if (std::optional<u64> title_id = volume->GetTitleID())
m_title_id = *title_id;
m_disc_number = volume->GetDiscNumber(); m_disc_number = volume->GetDiscNumber();
m_Revision = volume->GetRevision(); m_Revision = volume->GetRevision();