Merge pull request #8900 from JosJuice/disc-deduplicate

DiscIO: Deduplicate some VolumeGC/VolumeWii code
This commit is contained in:
Tilka 2020-06-25 16:10:04 +01:00 committed by GitHub
commit 98de22a1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 139 additions and 167 deletions

View File

@ -58,7 +58,7 @@ namespace fs = std::filesystem;
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "DiscIO/Enums.h" #include "DiscIO/Enums.h"
#include "DiscIO/Volume.h" #include "DiscIO/VolumeDisc.h"
#include "DiscIO/VolumeWad.h" #include "DiscIO/VolumeWad.h"
static std::vector<std::string> ReadM3UFile(const std::string& m3u_path, static std::vector<std::string> ReadM3UFile(const std::string& m3u_path,

View File

@ -16,7 +16,7 @@
#include "Core/IOS/IOSC.h" #include "Core/IOS/IOSC.h"
#include "DiscIO/Blob.h" #include "DiscIO/Blob.h"
#include "DiscIO/Enums.h" #include "DiscIO/Enums.h"
#include "DiscIO/Volume.h" #include "DiscIO/VolumeDisc.h"
#include "DiscIO/VolumeWad.h" #include "DiscIO/VolumeWad.h"
namespace File namespace File

View File

@ -33,7 +33,7 @@
#include "Core/PowerPC/PowerPC.h" #include "Core/PowerPC/PowerPC.h"
#include "DiscIO/Enums.h" #include "DiscIO/Enums.h"
#include "DiscIO/Volume.h" #include "DiscIO/VolumeDisc.h"
namespace namespace
{ {

View File

@ -38,7 +38,7 @@
#include "DiscIO/Blob.h" #include "DiscIO/Blob.h"
#include "DiscIO/Enums.h" #include "DiscIO/Enums.h"
#include "DiscIO/Volume.h" #include "DiscIO/VolumeDisc.h"
#include "DiscIO/VolumeWii.h" #include "DiscIO/VolumeWii.h"
#include "VideoCommon/OnScreenDisplay.h" #include "VideoCommon/OnScreenDisplay.h"

View File

@ -40,7 +40,7 @@
#include "DiscIO/DiscExtractor.h" #include "DiscIO/DiscExtractor.h"
#include "DiscIO/Enums.h" #include "DiscIO/Enums.h"
#include "DiscIO/Filesystem.h" #include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h" #include "DiscIO/VolumeDisc.h"
#include "DiscIO/VolumeFileBlobReader.h" #include "DiscIO/VolumeFileBlobReader.h"
#include "DiscIO/VolumeWad.h" #include "DiscIO/VolumeWad.h"

View File

@ -32,6 +32,8 @@ add_library(discio
TGCBlob.h TGCBlob.h
Volume.cpp Volume.cpp
Volume.h Volume.h
VolumeDisc.cpp
VolumeDisc.h
VolumeFileBlobReader.cpp VolumeFileBlobReader.cpp
VolumeFileBlobReader.h VolumeFileBlobReader.h
VolumeGC.cpp VolumeGC.cpp

View File

@ -60,6 +60,7 @@
<ClCompile Include="ScrubbedBlob.cpp" /> <ClCompile Include="ScrubbedBlob.cpp" />
<ClCompile Include="TGCBlob.cpp" /> <ClCompile Include="TGCBlob.cpp" />
<ClCompile Include="Volume.cpp" /> <ClCompile Include="Volume.cpp" />
<ClCompile Include="VolumeDisc.cpp" />
<ClCompile Include="VolumeFileBlobReader.cpp" /> <ClCompile Include="VolumeFileBlobReader.cpp" />
<ClCompile Include="VolumeGC.cpp" /> <ClCompile Include="VolumeGC.cpp" />
<ClCompile Include="VolumeVerifier.cpp" /> <ClCompile Include="VolumeVerifier.cpp" />
@ -89,6 +90,7 @@
<ClInclude Include="ScrubbedBlob.h" /> <ClInclude Include="ScrubbedBlob.h" />
<ClInclude Include="TGCBlob.h" /> <ClInclude Include="TGCBlob.h" />
<ClInclude Include="Volume.h" /> <ClInclude Include="Volume.h" />
<ClInclude Include="VolumeDisc.h" />
<ClInclude Include="VolumeFileBlobReader.h" /> <ClInclude Include="VolumeFileBlobReader.h" />
<ClInclude Include="VolumeGC.h" /> <ClInclude Include="VolumeGC.h" />
<ClInclude Include="VolumeVerifier.h" /> <ClInclude Include="VolumeVerifier.h" />

View File

@ -99,6 +99,7 @@
<ClCompile Include="WIACompression.cpp"> <ClCompile Include="WIACompression.cpp">
<Filter>Volume\Blob</Filter> <Filter>Volume\Blob</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="VolumeDisc.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="DiscScrubber.h"> <ClInclude Include="DiscScrubber.h">
@ -182,6 +183,7 @@
<ClInclude Include="WIACompression.h"> <ClInclude Include="WIACompression.h">
<Filter>Volume\Blob</Filter> <Filter>Volume\Blob</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="VolumeDisc.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Text Include="CMakeLists.txt" /> <Text Include="CMakeLists.txt" />

View File

@ -23,7 +23,7 @@
#include "DiscIO/DiscExtractor.h" #include "DiscIO/DiscExtractor.h"
#include "DiscIO/FileSystemGCWii.h" #include "DiscIO/FileSystemGCWii.h"
#include "DiscIO/Filesystem.h" #include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h" #include "DiscIO/VolumeDisc.h"
namespace DiscIO namespace DiscIO
{ {

View File

@ -12,7 +12,7 @@
#include "Common/Align.h" #include "Common/Align.h"
#include "DiscIO/Blob.h" #include "DiscIO/Blob.h"
#include "DiscIO/DiscScrubber.h" #include "DiscIO/DiscScrubber.h"
#include "DiscIO/Volume.h" #include "DiscIO/VolumeDisc.h"
namespace DiscIO namespace DiscIO
{ {

View File

@ -17,6 +17,7 @@
#include "DiscIO/Blob.h" #include "DiscIO/Blob.h"
#include "DiscIO/Enums.h" #include "DiscIO/Enums.h"
#include "DiscIO/VolumeDisc.h"
#include "DiscIO/VolumeGC.h" #include "DiscIO/VolumeGC.h"
#include "DiscIO/VolumeWad.h" #include "DiscIO/VolumeWad.h"
#include "DiscIO/VolumeWii.h" #include "DiscIO/VolumeWii.h"

View File

@ -23,6 +23,7 @@ namespace DiscIO
class BlobReader; class BlobReader;
enum class BlobType; enum class BlobType;
class FileSystem; class FileSystem;
class VolumeDisc;
class VolumeWAD; class VolumeWAD;
struct Partition final struct Partition final
@ -162,10 +163,6 @@ protected:
static const std::vector<u8> INVALID_CERT_CHAIN; static const std::vector<u8> INVALID_CERT_CHAIN;
}; };
class VolumeDisc : public Volume
{
};
std::unique_ptr<VolumeDisc> CreateDisc(const std::string& path); std::unique_ptr<VolumeDisc> CreateDisc(const std::string& path);
std::unique_ptr<VolumeWAD> CreateWAD(const std::string& path); std::unique_ptr<VolumeWAD> CreateWAD(const std::string& path);
std::unique_ptr<Volume> CreateVolume(const std::string& path); std::unique_ptr<Volume> CreateVolume(const std::string& path);

View File

@ -0,0 +1,87 @@
// Copyright 2020 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DiscIO/VolumeDisc.h"
#include <optional>
#include <string>
#include "Common/CommonTypes.h"
#include "DiscIO/Enums.h"
namespace DiscIO
{
std::string VolumeDisc::GetGameID(const Partition& partition) const
{
char id[6];
if (!Read(0, sizeof(id), reinterpret_cast<u8*>(id), partition))
return std::string();
return DecodeString(id);
}
Country VolumeDisc::GetCountry(const Partition& partition) const
{
// The 0 that we use as a default value is mapped to Country::Unknown and Region::Unknown
const u8 country_byte = ReadSwapped<u8>(3, partition).value_or(0);
const Region region = GetRegion();
const std::optional<u16> revision = GetRevision();
if (CountryCodeToRegion(country_byte, GetVolumeType(), region, revision) != region)
return TypicalCountryForRegion(region);
return CountryCodeToCountry(country_byte, GetVolumeType(), region, revision);
}
Region VolumeDisc::RegionCodeToRegion(std::optional<u32> region_code) const
{
if (!region_code)
return Region::Unknown;
const Region region = static_cast<Region>(*region_code);
return region <= Region::NTSC_K ? region : Region::Unknown;
}
std::string VolumeDisc::GetMakerID(const Partition& partition) const
{
char maker_id[2];
if (!Read(0x4, sizeof(maker_id), reinterpret_cast<u8*>(&maker_id), partition))
return std::string();
return DecodeString(maker_id);
}
std::optional<u16> VolumeDisc::GetRevision(const Partition& partition) const
{
std::optional<u8> revision = ReadSwapped<u8>(7, partition);
return revision ? *revision : std::optional<u16>();
}
std::string VolumeDisc::GetInternalName(const Partition& partition) const
{
char name[0x60];
if (!Read(0x20, sizeof(name), reinterpret_cast<u8*>(&name), partition))
return std::string();
return DecodeString(name);
}
std::string VolumeDisc::GetApploaderDate(const Partition& partition) const
{
char date[16];
if (!Read(0x2440, sizeof(date), reinterpret_cast<u8*>(&date), partition))
return std::string();
return DecodeString(date);
}
std::optional<u8> VolumeDisc::GetDiscNumber(const Partition& partition) const
{
return ReadSwapped<u8>(6, partition);
}
} // namespace DiscIO

View File

@ -0,0 +1,30 @@
// Copyright 2020 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <optional>
#include <string>
#include "Common/CommonTypes.h"
#include "DiscIO/Volume.h"
namespace DiscIO
{
class VolumeDisc : public Volume
{
public:
std::string GetGameID(const Partition& partition = PARTITION_NONE) const override;
Country GetCountry(const Partition& partition = PARTITION_NONE) const override;
std::string GetMakerID(const Partition& partition = PARTITION_NONE) const override;
std::optional<u16> GetRevision(const Partition& partition = PARTITION_NONE) const override;
std::string GetInternalName(const Partition& partition = PARTITION_NONE) const override;
std::string GetApploaderDate(const Partition& partition) const override;
std::optional<u8> GetDiscNumber(const Partition& partition = PARTITION_NONE) const override;
protected:
Region RegionCodeToRegion(std::optional<u32> region_code) const;
};
} // namespace DiscIO

View File

@ -57,21 +57,6 @@ const FileSystem* VolumeGC::GetFileSystem(const Partition& partition) const
return m_file_system->get(); return m_file_system->get();
} }
std::string VolumeGC::GetGameID(const Partition& partition) const
{
static const std::string NO_UID("NO_UID");
char id[6];
if (!Read(0, sizeof(id), reinterpret_cast<u8*>(id), partition))
{
PanicAlertT("Failed to read unique ID from disc image");
return NO_UID;
}
return DecodeString(id);
}
std::string VolumeGC::GetGameTDBID(const Partition& partition) const std::string VolumeGC::GetGameTDBID(const Partition& partition) const
{ {
// Don't return an ID for Datel discs // Don't return an ID for Datel discs
@ -83,48 +68,7 @@ std::string VolumeGC::GetGameTDBID(const Partition& partition) const
Region VolumeGC::GetRegion() const Region VolumeGC::GetRegion() const
{ {
const std::optional<u32> region_code = ReadSwapped<u32>(0x458, PARTITION_NONE); return RegionCodeToRegion(m_reader->ReadSwapped<u32>(0x458));
if (!region_code)
return Region::Unknown;
const Region region = static_cast<Region>(*region_code);
return region <= Region::PAL ? region : Region::Unknown;
}
Country VolumeGC::GetCountry(const Partition& partition) const
{
// The 0 that we use as a default value is mapped to Country::Unknown and Region::Unknown
const u8 country = ReadSwapped<u8>(3, partition).value_or(0);
const Region region = GetRegion();
const std::optional<u16> revision = GetRevision();
if (CountryCodeToRegion(country, Platform::GameCubeDisc, region, revision) != region)
return TypicalCountryForRegion(region);
return CountryCodeToCountry(country, Platform::GameCubeDisc, region, revision);
}
std::string VolumeGC::GetMakerID(const Partition& partition) const
{
char maker_id[2];
if (!Read(0x4, sizeof(maker_id), reinterpret_cast<u8*>(&maker_id), partition))
return std::string();
return DecodeString(maker_id);
}
std::optional<u16> VolumeGC::GetRevision(const Partition& partition) const
{
std::optional<u8> revision = ReadSwapped<u8>(7, partition);
return revision ? *revision : std::optional<u16>();
}
std::string VolumeGC::GetInternalName(const Partition& partition) const
{
char name[0x60];
if (Read(0x20, sizeof(name), reinterpret_cast<u8*>(name), partition))
return DecodeString(name);
return "";
} }
std::map<Language, std::string> VolumeGC::GetShortNames() const std::map<Language, std::string> VolumeGC::GetShortNames() const
@ -159,15 +103,6 @@ std::vector<u32> VolumeGC::GetBanner(u32* width, u32* height) const
return m_converted_banner->image_buffer; return m_converted_banner->image_buffer;
} }
std::string VolumeGC::GetApploaderDate(const Partition& partition) const
{
char date[16];
if (!Read(0x2440, sizeof(date), reinterpret_cast<u8*>(&date), partition))
return std::string();
return DecodeString(date);
}
BlobType VolumeGC::GetBlobType() const BlobType VolumeGC::GetBlobType() const
{ {
return m_reader->GetBlobType(); return m_reader->GetBlobType();
@ -193,11 +128,6 @@ const BlobReader& VolumeGC::GetBlobReader() const
return *m_reader; return *m_reader;
} }
std::optional<u8> VolumeGC::GetDiscNumber(const Partition& partition) const
{
return ReadSwapped<u8>(6, partition);
}
Platform VolumeGC::GetVolumeType() const Platform VolumeGC::GetVolumeType() const
{ {
return Platform::GameCubeDisc; return Platform::GameCubeDisc;

View File

@ -14,6 +14,7 @@
#include "Common/Lazy.h" #include "Common/Lazy.h"
#include "DiscIO/Filesystem.h" #include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"
#include "DiscIO/VolumeDisc.h"
namespace DiscIO namespace DiscIO
{ {
@ -33,28 +34,21 @@ public:
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;
const FileSystem* GetFileSystem(const Partition& partition = PARTITION_NONE) const override; const FileSystem* GetFileSystem(const Partition& partition = PARTITION_NONE) const override;
std::string GetGameID(const Partition& partition = PARTITION_NONE) const override;
std::string GetGameTDBID(const Partition& partition = PARTITION_NONE) const override; std::string GetGameTDBID(const Partition& partition = PARTITION_NONE) const override;
std::string GetMakerID(const Partition& partition = PARTITION_NONE) const override;
std::optional<u16> GetRevision(const Partition& partition = PARTITION_NONE) const override;
std::string GetInternalName(const Partition& partition = PARTITION_NONE) const override;
std::map<Language, std::string> GetShortNames() const override; std::map<Language, std::string> GetShortNames() const override;
std::map<Language, std::string> GetLongNames() const override; std::map<Language, std::string> GetLongNames() const override;
std::map<Language, std::string> GetShortMakers() const override; std::map<Language, std::string> GetShortMakers() const override;
std::map<Language, std::string> GetLongMakers() const override; std::map<Language, std::string> GetLongMakers() const override;
std::map<Language, std::string> GetDescriptions() const override; std::map<Language, std::string> GetDescriptions() const override;
std::vector<u32> GetBanner(u32* width, u32* height) const override; std::vector<u32> GetBanner(u32* width, u32* height) const override;
std::string GetApploaderDate(const Partition& partition = PARTITION_NONE) const override;
std::optional<u8> GetDiscNumber(const Partition& partition = PARTITION_NONE) const override;
Platform GetVolumeType() const override; Platform GetVolumeType() const override;
Region GetRegion() const override; Region GetRegion() const override;
Country GetCountry(const Partition& partition = PARTITION_NONE) const override;
BlobType GetBlobType() const override; BlobType GetBlobType() const override;
u64 GetSize() const override; u64 GetSize() const override;
bool IsSizeAccurate() const override; bool IsSizeAccurate() const override;
u64 GetRawSize() const override; u64 GetRawSize() const override;
const BlobReader& GetBlobReader() const; const BlobReader& GetBlobReader() const override;
private: private:
static const u32 GC_BANNER_WIDTH = 96; static const u32 GC_BANNER_WIDTH = 96;

View File

@ -66,7 +66,7 @@ public:
u64 GetSize() const override; u64 GetSize() const override;
bool IsSizeAccurate() const override; bool IsSizeAccurate() const override;
u64 GetRawSize() const override; u64 GetRawSize() const override;
const BlobReader& GetBlobReader() const; const BlobReader& GetBlobReader() const override;
private: private:
std::unique_ptr<BlobReader> m_reader; std::unique_ptr<BlobReader> m_reader;

View File

@ -299,16 +299,6 @@ u64 VolumeWii::PartitionOffsetToRawOffset(u64 offset, const Partition& partition
return EncryptedPartitionOffsetToRawOffset(offset, partition, data_offset); return EncryptedPartitionOffsetToRawOffset(offset, partition, data_offset);
} }
std::string VolumeWii::GetGameID(const Partition& partition) const
{
char id[6];
if (!Read(0, sizeof(id), reinterpret_cast<u8*>(id), partition))
return std::string();
return DecodeString(id);
}
std::string VolumeWii::GetGameTDBID(const Partition& partition) const std::string VolumeWii::GetGameTDBID(const Partition& partition) const
{ {
// Don't return an ID for Datel discs // Don't return an ID for Datel discs
@ -320,49 +310,7 @@ std::string VolumeWii::GetGameTDBID(const Partition& partition) const
Region VolumeWii::GetRegion() const Region VolumeWii::GetRegion() const
{ {
const std::optional<u32> region_code = m_reader->ReadSwapped<u32>(0x4E000); return RegionCodeToRegion(m_reader->ReadSwapped<u32>(0x4E000));
if (!region_code)
return Region::Unknown;
const Region region = static_cast<Region>(*region_code);
return region <= Region::NTSC_K ? region : Region::Unknown;
}
Country VolumeWii::GetCountry(const Partition& partition) const
{
// The 0 that we use as a default value is mapped to Country::Unknown and Region::Unknown
const u8 country_byte = ReadSwapped<u8>(3, partition).value_or(0);
const Region region = GetRegion();
const std::optional<u16> revision = GetRevision();
if (CountryCodeToRegion(country_byte, Platform::WiiDisc, region, revision) != region)
return TypicalCountryForRegion(region);
return CountryCodeToCountry(country_byte, Platform::WiiDisc, region, revision);
}
std::string VolumeWii::GetMakerID(const Partition& partition) const
{
char maker_id[2];
if (!Read(0x4, sizeof(maker_id), reinterpret_cast<u8*>(&maker_id), partition))
return std::string();
return DecodeString(maker_id);
}
std::optional<u16> VolumeWii::GetRevision(const Partition& partition) const
{
std::optional<u8> revision = ReadSwapped<u8>(7, partition);
return revision ? *revision : std::optional<u16>();
}
std::string VolumeWii::GetInternalName(const Partition& partition) const
{
char name_buffer[0x60];
if (Read(0x20, sizeof(name_buffer), reinterpret_cast<u8*>(&name_buffer), partition))
return DecodeString(name_buffer);
return "";
} }
std::map<Language, std::string> VolumeWii::GetLongNames() const std::map<Language, std::string> VolumeWii::GetLongNames() const
@ -385,26 +333,11 @@ std::vector<u32> VolumeWii::GetBanner(u32* width, u32* height) const
return WiiSaveBanner(*title_id).GetBanner(width, height); return WiiSaveBanner(*title_id).GetBanner(width, height);
} }
std::string VolumeWii::GetApploaderDate(const Partition& partition) const
{
char date[16];
if (!Read(0x2440, sizeof(date), reinterpret_cast<u8*>(&date), partition))
return std::string();
return DecodeString(date);
}
Platform VolumeWii::GetVolumeType() const Platform VolumeWii::GetVolumeType() const
{ {
return Platform::WiiDisc; return Platform::WiiDisc;
} }
std::optional<u8> VolumeWii::GetDiscNumber(const Partition& partition) const
{
return ReadSwapped<u8>(6, partition);
}
BlobType VolumeWii::GetBlobType() const BlobType VolumeWii::GetBlobType() const
{ {
return m_reader->GetBlobType(); return m_reader->GetBlobType();

View File

@ -19,6 +19,7 @@
#include "Core/IOS/ES/Formats.h" #include "Core/IOS/ES/Formats.h"
#include "DiscIO/Filesystem.h" #include "DiscIO/Filesystem.h"
#include "DiscIO/Volume.h" #include "DiscIO/Volume.h"
#include "DiscIO/VolumeDisc.h"
namespace DiscIO namespace DiscIO
{ {
@ -73,15 +74,9 @@ public:
static u64 EncryptedPartitionOffsetToRawOffset(u64 offset, const Partition& partition, static u64 EncryptedPartitionOffsetToRawOffset(u64 offset, const Partition& partition,
u64 partition_data_offset); u64 partition_data_offset);
u64 PartitionOffsetToRawOffset(u64 offset, const Partition& partition) const override; u64 PartitionOffsetToRawOffset(u64 offset, const Partition& partition) const override;
std::string GetGameID(const Partition& partition = PARTITION_NONE) const override;
std::string GetGameTDBID(const Partition& partition = PARTITION_NONE) const override; std::string GetGameTDBID(const Partition& partition = PARTITION_NONE) const override;
std::string GetMakerID(const Partition& partition = PARTITION_NONE) const override;
std::optional<u16> GetRevision(const Partition& partition = PARTITION_NONE) const override;
std::string GetInternalName(const Partition& partition = PARTITION_NONE) const override;
std::map<Language, std::string> GetLongNames() const override; std::map<Language, std::string> GetLongNames() const override;
std::vector<u32> GetBanner(u32* width, u32* height) const override; std::vector<u32> GetBanner(u32* width, u32* height) const override;
std::string GetApploaderDate(const Partition& partition) const override;
std::optional<u8> GetDiscNumber(const Partition& partition = PARTITION_NONE) const override;
Platform GetVolumeType() const override; Platform GetVolumeType() const override;
bool SupportsIntegrityCheck() const override { return m_encrypted; } bool SupportsIntegrityCheck() const override { return m_encrypted; }
@ -91,12 +86,11 @@ public:
bool CheckBlockIntegrity(u64 block_index, const Partition& partition) const override; bool CheckBlockIntegrity(u64 block_index, const Partition& partition) const override;
Region GetRegion() const override; Region GetRegion() const override;
Country GetCountry(const Partition& partition = PARTITION_NONE) const override;
BlobType GetBlobType() const override; BlobType GetBlobType() const override;
u64 GetSize() const override; u64 GetSize() const override;
bool IsSizeAccurate() const override; bool IsSizeAccurate() const override;
u64 GetRawSize() const override; u64 GetRawSize() const override;
const BlobReader& GetBlobReader() const; const BlobReader& GetBlobReader() const override;
// The in parameter can either contain all the data to begin with, // The in parameter can either contain all the data to begin with,
// or read_function can write data into the in parameter when called. // or read_function can write data into the in parameter when called.