VolumeWiiCrypted: Replace ChangePartition with a partition parameter

By removing mutable state in VolumeWiiCrypted, this change makes
partition-related code simpler. It also gets rid of other ugly things,
like ISOProperties's "over 9000" loop that creates a list of
partitions by trying possible combinations, and DiscScrubber's
volume swapping that recreates the entire volume when it needs to
change partition.
This commit is contained in:
JosJuice
2015-06-13 12:51:24 +02:00
parent 74d84c5af2
commit 19b8f1c10a
35 changed files with 622 additions and 639 deletions

View File

@ -5,6 +5,7 @@
#pragma once
#include <cstring>
#include <limits>
#include <map>
#include <string>
#include <vector>
@ -19,49 +20,71 @@ namespace DiscIO
{
enum class BlobType;
struct Partition final
{
Partition() : offset(std::numeric_limits<u64>::max()) {}
explicit Partition(u64 offset_) : offset(offset_) {}
bool operator==(const Partition& other) const { return offset == other.offset; }
bool operator!=(const Partition& other) const { return !(*this == other); }
bool operator<(const Partition& other) const { return offset < other.offset; }
bool operator>(const Partition& other) const { return other < *this; }
bool operator<=(const Partition& other) const { return !(*this < other); }
bool operator>=(const Partition& other) const { return !(*this > other); }
u64 offset;
};
const Partition PARTITION_NONE(std::numeric_limits<u64>::max() - 1);
class IVolume
{
public:
IVolume() {}
virtual ~IVolume() {}
// decrypt parameter must be false if not reading a Wii disc
virtual bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, bool decrypt) const = 0;
virtual bool Read(u64 _Offset, u64 _Length, u8* _pBuffer, const Partition& partition) const = 0;
template <typename T>
bool ReadSwapped(u64 offset, T* buffer, bool decrypt) const
bool ReadSwapped(u64 offset, T* buffer, const Partition& partition) const
{
T temp;
if (!Read(offset, sizeof(T), reinterpret_cast<u8*>(&temp), decrypt))
if (!Read(offset, sizeof(T), reinterpret_cast<u8*>(&temp), partition))
return false;
*buffer = Common::FromBigEndian(temp);
return true;
}
virtual bool GetTitleID(u64*) const { return false; }
virtual IOS::ES::TicketReader GetTicket() const { return {}; }
virtual IOS::ES::TMDReader GetTMD() const { return {}; }
virtual u64 PartitionOffsetToRawOffset(u64 offset) const { return offset; }
virtual std::string GetGameID() const = 0;
virtual std::string GetMakerID() const = 0;
virtual u16 GetRevision() const = 0;
virtual std::string GetInternalName() const = 0;
virtual std::vector<Partition> GetPartitions() const { return {{}}; }
virtual Partition GetGamePartition() const { return PARTITION_NONE; }
bool GetTitleID(u64* buffer) const { return GetTitleID(buffer, GetGamePartition()); }
virtual bool GetTitleID(u64* buffer, const Partition& partition) const { return false; }
virtual IOS::ES::TicketReader GetTicket(const Partition& partition) const { return {}; }
virtual IOS::ES::TMDReader GetTMD(const Partition& partition) const { return {}; }
std::string GetGameID() const { return GetGameID(GetGamePartition()); }
virtual std::string GetGameID(const Partition& partition) const = 0;
std::string GetMakerID() const { return GetMakerID(GetGamePartition()); }
virtual std::string GetMakerID(const Partition& partition) const = 0;
u16 GetRevision() const { return GetRevision(GetGamePartition()); }
virtual u16 GetRevision(const Partition& partition) const = 0;
std::string GetInternalName() const { return GetInternalName(GetGamePartition()); }
virtual std::string GetInternalName(const Partition& partition) const = 0;
virtual std::map<Language, std::string> GetShortNames() const { return {{}}; }
virtual std::map<Language, std::string> GetLongNames() const { return {{}}; }
virtual std::map<Language, std::string> GetShortMakers() const { return {{}}; }
virtual std::map<Language, std::string> GetLongMakers() const { return {{}}; }
virtual std::map<Language, std::string> GetDescriptions() const { return {{}}; }
virtual std::vector<u32> GetBanner(int* width, int* height) const = 0;
virtual u64 GetFSTSize() const = 0;
virtual std::string GetApploaderDate() const = 0;
u64 GetFSTSize() const { return GetFSTSize(GetGamePartition()); }
virtual u64 GetFSTSize(const Partition& partition) const = 0;
std::string GetApploaderDate() const { return GetApploaderDate(GetGamePartition()); }
virtual std::string GetApploaderDate(const Partition& partition) const = 0;
// 0 is the first disc, 1 is the second disc
virtual u8 GetDiscNumber() const { return 0; }
u8 GetDiscNumber() const { return GetDiscNumber(GetGamePartition()); }
virtual u8 GetDiscNumber(const Partition& partition) const { return 0; }
virtual Platform GetVolumeType() const = 0;
virtual bool SupportsIntegrityCheck() const { return false; }
virtual bool CheckIntegrity() const { return false; }
virtual bool ChangePartition(u64 offset) { return false; }
virtual bool CheckIntegrity(const Partition& partition) const { return false; }
virtual Region GetRegion() const = 0;
virtual Country GetCountry() const = 0;
Country GetCountry() const { return GetCountry(GetGamePartition()); }
virtual Country GetCountry(const Partition& partition) const = 0;
virtual BlobType GetBlobType() const = 0;
// Size of virtual disc (not always accurate)
// Size of virtual disc (may be inaccurate depending on the blob type)
virtual u64 GetSize() const = 0;
// Size on disc (compressed size)
virtual u64 GetRawSize() const = 0;