Skip to content
Permalink
Browse files

DiscIO: Add way of checking whether blob data size is accurate

  • Loading branch information...
JosJuice committed Mar 21, 2019
1 parent 0bce1c5 commit 3014dadfa8c2065f81009895ecf81396de5120bc
@@ -44,6 +44,7 @@ class BlobReader
virtual BlobType GetBlobType() const = 0;
virtual u64 GetRawSize() const = 0;
virtual u64 GetDataSize() const = 0;
virtual bool IsDataSizeAccurate() const = 0;

// NOT thread-safe - can't call this from multiple threads.
virtual bool Read(u64 offset, u64 size, u8* out_ptr) = 0;
@@ -40,6 +40,7 @@ class CISOFileReader : public BlobReader
// The CISO format does not save the original file size.
// This function returns an upper bound.
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return false; }

u64 GetRawSize() const override;
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;
@@ -49,8 +49,9 @@ class CompressedBlobReader : public SectorReader
~CompressedBlobReader();
const CompressedBlobHeader& GetHeader() const { return m_header; }
BlobType GetBlobType() const override { return BlobType::GCZ; }
u64 GetDataSize() const override { return m_header.data_size; }
u64 GetRawSize() const override { return m_file_size; }
u64 GetDataSize() const override { return m_header.data_size; }
bool IsDataSizeAccurate() const override { return true; }
u64 GetBlockCompressedSize(u64 block_num) const;
bool GetBlock(u64 block_num, u8* out_ptr) override;

@@ -146,6 +146,7 @@ class DirectoryBlobReader : public BlobReader
BlobType GetBlobType() const override;
u64 GetRawSize() const override;
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return true; }

private:
struct PartitionWithType
@@ -24,8 +24,9 @@ class DriveReader : public SectorReader
static std::unique_ptr<DriveReader> Create(const std::string& drive);
~DriveReader();
BlobType GetBlobType() const override { return BlobType::DRIVE; }
u64 GetDataSize() const override { return m_size; }
u64 GetRawSize() const override { return m_size; }
u64 GetDataSize() const override { return m_size; }
bool IsDataSizeAccurate() const override { return true; }

private:
DriveReader(const std::string& drive);
@@ -20,8 +20,9 @@ class PlainFileReader : public BlobReader
static std::unique_ptr<PlainFileReader> Create(File::IOFile file);

BlobType GetBlobType() const override { return BlobType::PLAIN; }
u64 GetDataSize() const override { return m_size; }
u64 GetRawSize() const override { return m_size; }
u64 GetDataSize() const override { return m_size; }
bool IsDataSizeAccurate() const override { return true; }
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;

private:
@@ -43,8 +43,9 @@ class TGCFileReader final : public BlobReader
static std::unique_ptr<TGCFileReader> Create(File::IOFile file);

BlobType GetBlobType() const override { return BlobType::TGC; }
u64 GetDataSize() const override;
u64 GetRawSize() const override { return m_size; }
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return true; }
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;

private:
@@ -101,6 +101,7 @@ class Volume
virtual BlobType GetBlobType() const = 0;
// Size of virtual disc (may be inaccurate depending on the blob type)
virtual u64 GetSize() const = 0;
virtual bool IsSizeAccurate() const = 0;
// Size on disc (compressed size)
virtual u64 GetRawSize() const = 0;

@@ -23,8 +23,9 @@ class VolumeFileBlobReader final : public BlobReader
Create(const Volume& volume, const Partition& partition, const std::string& file_path);

BlobType GetBlobType() const override { return BlobType::PLAIN; }
u64 GetDataSize() const override;
u64 GetRawSize() const override;
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return true; }
bool Read(u64 offset, u64 length, u8* out_ptr) override;

private:
@@ -179,6 +179,11 @@ u64 VolumeGC::GetSize() const
return m_reader->GetDataSize();
}

bool VolumeGC::IsSizeAccurate() const
{
return m_reader->IsDataSizeAccurate();
}

u64 VolumeGC::GetRawSize() const
{
return m_reader->GetRawSize();
@@ -52,6 +52,7 @@ class VolumeGC : public Volume
Country GetCountry(const Partition& partition = PARTITION_NONE) const override;
BlobType GetBlobType() const override;
u64 GetSize() const override;
bool IsSizeAccurate() const override;
u64 GetRawSize() const override;

private:
@@ -175,6 +175,11 @@ u64 VolumeWAD::GetSize() const
return m_reader->GetDataSize();
}

bool VolumeWAD::IsSizeAccurate() const
{
return m_reader->IsDataSizeAccurate();
}

u64 VolumeWAD::GetRawSize() const
{
return m_reader->GetRawSize();
@@ -54,6 +54,7 @@ class VolumeWAD : public Volume

BlobType GetBlobType() const override;
u64 GetSize() const override;
bool IsSizeAccurate() const override;
u64 GetRawSize() const override;

private:
@@ -379,6 +379,11 @@ u64 VolumeWii::GetSize() const
return m_reader->GetDataSize();
}

bool VolumeWii::IsSizeAccurate() const
{
return m_reader->IsDataSizeAccurate();
}

u64 VolumeWii::GetRawSize() const
{
return m_reader->GetRawSize();
@@ -62,6 +62,7 @@ class VolumeWii : public Volume
Country GetCountry(const Partition& partition) const override;
BlobType GetBlobType() const override;
u64 GetSize() const override;
bool IsSizeAccurate() const override;
u64 GetRawSize() const override;

static constexpr unsigned int BLOCK_HEADER_SIZE = 0x0400;
@@ -24,12 +24,13 @@ class WbfsFileReader : public BlobReader
static std::unique_ptr<WbfsFileReader> Create(File::IOFile file, const std::string& path);

BlobType GetBlobType() const override { return BlobType::WBFS; }
u64 GetRawSize() const override { return m_size; }
// The WBFS format does not save the original file size.
// This function returns a constant upper bound
// (the size of a double-layer Wii disc).
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return false; }

u64 GetRawSize() const override { return m_size; }
bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;

private:

0 comments on commit 3014dad

Please sign in to comment.
You can’t perform that action at this time.