DiscIO: Replace IsDataSizeAccurate with GetDataSizeType

Previously, we had WBFS and CISO which both returned an upper bound
of the size, and other formats which returned an accurate size. But
now we also have NFS, which returns a lower bound of the size. To
allow VolumeVerifier to make better informed decisions for NFS, let's
use an enum instead of a bool for the type of data size a blob has.
This commit is contained in:
JosJuice 2022-08-01 11:53:30 +02:00
parent 3a6df63e9b
commit a87dffe52d
29 changed files with 62 additions and 54 deletions

View File

@ -430,9 +430,9 @@ void Shutdown()
static u64 GetDiscEndOffset(const DiscIO::VolumeDisc& disc)
{
u64 size = disc.GetSize();
u64 size = disc.GetDataSize();
if (disc.IsSizeAccurate())
if (disc.GetDataSizeType() == DiscIO::DataSizeType::Accurate)
{
if (size == DiscIO::MINI_DVD_SIZE)
return DiscIO::MINI_DVD_SIZE;
@ -464,7 +464,7 @@ void SetDisc(std::unique_ptr<DiscIO::VolumeDisc> disc,
if (has_disc)
{
s_disc_end_offset = GetDiscEndOffset(*disc);
if (!disc->IsSizeAccurate())
if (disc->GetDataSizeType() != DiscIO::DataSizeType::Accurate)
WARN_LOG_FMT(DVDINTERFACE, "Unknown disc size, guessing {0} bytes", s_disc_end_offset);
const DiscIO::BlobReader& blob = disc->GetBlobReader();

View File

@ -43,6 +43,18 @@ enum class BlobType
NFS,
};
// If you convert an ISO file to another format and then call GetDataSize on it, what is the result?
enum class DataSizeType
{
// The result is the same as for the ISO.
Accurate,
// The result is not larger than for the ISO. (It's usually a little smaller than for the ISO.)
// Reads to offsets that are larger than the result will return some kind of "blank" data.
LowerBound,
// The result is not smaller than for the ISO. (It's usually much larger than for the ISO.)
UpperBound,
};
std::string GetName(BlobType blob_type, bool translate);
class BlobReader
@ -54,7 +66,7 @@ public:
virtual u64 GetRawSize() const = 0;
virtual u64 GetDataSize() const = 0;
virtual bool IsDataSizeAccurate() const = 0;
virtual DataSizeType GetDataSizeType() const = 0;
// Returns 0 if the format does not use blocks
virtual u64 GetBlockSize() const = 0;

View File

@ -38,10 +38,8 @@ public:
BlobType GetBlobType() const override { return BlobType::CISO; }
u64 GetRawSize() const override;
// 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; }
DataSizeType GetDataSizeType() const override { return DataSizeType::UpperBound; }
u64 GetBlockSize() const override { return m_block_size; }
bool HasFastRandomAccessInBlock() const override { return true; }

View File

@ -273,7 +273,7 @@ bool ConvertToGCZ(BlobReader* infile, const std::string& infile_path,
const std::string& outfile_path, u32 sub_type, int block_size,
CompressCB callback)
{
ASSERT(infile->IsDataSizeAccurate());
ASSERT(infile->GetDataSizeType() == DataSizeType::Accurate);
File::IOFile outfile(outfile_path, "wb");
if (!outfile)

View File

@ -53,7 +53,7 @@ public:
u64 GetRawSize() const override { return m_file_size; }
u64 GetDataSize() const override { return m_header.data_size; }
bool IsDataSizeAccurate() const override { return true; }
DataSizeType GetDataSizeType() const override { return DataSizeType::Accurate; }
u64 GetBlockSize() const override { return m_header.block_size; }
bool HasFastRandomAccessInBlock() const override { return false; }

View File

@ -284,7 +284,7 @@ public:
u64 GetRawSize() const override;
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return true; }
DataSizeType GetDataSizeType() const override { return DataSizeType::Accurate; }
u64 GetBlockSize() const override { return 0; }
bool HasFastRandomAccessInBlock() const override { return true; }

View File

@ -30,7 +30,7 @@ bool DiscScrubber::SetupScrub(const Volume* disc)
return false;
m_disc = disc;
m_file_size = m_disc->GetSize();
m_file_size = m_disc->GetDataSize();
// Round up when diving by CLUSTER_SIZE, otherwise MarkAsUsed might write out of bounds
const size_t num_clusters = static_cast<size_t>((m_file_size + CLUSTER_SIZE - 1) / CLUSTER_SIZE);

View File

@ -27,7 +27,7 @@ public:
u64 GetRawSize() const override { return m_size; }
u64 GetDataSize() const override { return m_size; }
bool IsDataSizeAccurate() const override { return true; }
DataSizeType GetDataSizeType() const override { return DataSizeType::Accurate; }
u64 GetBlockSize() const override { return ECC_BLOCK_SIZE; }
bool HasFastRandomAccessInBlock() const override { return false; }

View File

@ -44,7 +44,7 @@ bool PlainFileReader::Read(u64 offset, u64 nbytes, u8* out_ptr)
bool ConvertToPlain(BlobReader* infile, const std::string& infile_path,
const std::string& outfile_path, CompressCB callback)
{
ASSERT(infile->IsDataSizeAccurate());
ASSERT(infile->GetDataSizeType() == DataSizeType::Accurate);
File::IOFile outfile(outfile_path, "wb");
if (!outfile)

View File

@ -22,7 +22,7 @@ public:
u64 GetRawSize() const override { return m_size; }
u64 GetDataSize() const override { return m_size; }
bool IsDataSizeAccurate() const override { return true; }
DataSizeType GetDataSizeType() const override { return DataSizeType::Accurate; }
u64 GetBlockSize() const override { return 0; }
bool HasFastRandomAccessInBlock() const override { return true; }

View File

@ -48,7 +48,7 @@ public:
u64 GetRawSize() const override;
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return false; }
DataSizeType GetDataSizeType() const override { return DataSizeType::LowerBound; }
u64 GetBlockSize() const override { return BLOCK_SIZE; }
bool HasFastRandomAccessInBlock() const override { return false; }

View File

@ -22,7 +22,7 @@ public:
u64 GetRawSize() const override { return m_blob_reader->GetRawSize(); }
u64 GetDataSize() const override { return m_blob_reader->GetDataSize(); }
bool IsDataSizeAccurate() const override { return m_blob_reader->IsDataSizeAccurate(); }
DataSizeType GetDataSizeType() const override { return m_blob_reader->GetDataSizeType(); }
u64 GetBlockSize() const override { return m_blob_reader->GetBlockSize(); }
bool HasFastRandomAccessInBlock() const override

View File

@ -45,7 +45,7 @@ public:
u64 GetRawSize() const override { return m_size; }
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return true; }
DataSizeType GetDataSizeType() const override { return DataSizeType::Accurate; }
u64 GetBlockSize() const override { return 0; }
bool HasFastRandomAccessInBlock() const override { return true; }

View File

@ -22,6 +22,7 @@ namespace DiscIO
{
class BlobReader;
enum class BlobType;
enum class DataSizeType;
class FileSystem;
class VolumeDisc;
class VolumeWAD;
@ -137,8 +138,8 @@ public:
virtual Country GetCountry(const Partition& partition = PARTITION_NONE) const = 0;
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;
virtual u64 GetDataSize() const = 0;
virtual DataSizeType GetDataSizeType() const = 0;
// Size on disc (compressed size)
virtual u64 GetRawSize() const = 0;
virtual const BlobReader& GetBlobReader() const = 0;

View File

@ -25,7 +25,7 @@ public:
u64 GetRawSize() const override;
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return true; }
DataSizeType GetDataSizeType() const override { return DataSizeType::Accurate; }
u64 GetBlockSize() const override;
bool HasFastRandomAccessInBlock() const override;

View File

@ -119,14 +119,14 @@ BlobType VolumeGC::GetBlobType() const
return m_reader->GetBlobType();
}
u64 VolumeGC::GetSize() const
u64 VolumeGC::GetDataSize() const
{
return m_reader->GetDataSize();
}
bool VolumeGC::IsSizeAccurate() const
DataSizeType VolumeGC::GetDataSizeType() const
{
return m_reader->IsDataSizeAccurate();
return m_reader->GetDataSizeType();
}
u64 VolumeGC::GetRawSize() const

View File

@ -45,8 +45,8 @@ public:
bool IsDatelDisc() const override;
Region GetRegion() const override;
BlobType GetBlobType() const override;
u64 GetSize() const override;
bool IsSizeAccurate() const override;
u64 GetDataSize() const override;
DataSizeType GetDataSizeType() const override;
u64 GetRawSize() const override;
const BlobReader& GetBlobReader() const override;

View File

@ -62,7 +62,7 @@ void RedumpVerifier::Start(const Volume& volume)
m_revision = volume.GetRevision().value_or(0);
m_disc_number = volume.GetDiscNumber().value_or(0);
m_size = volume.GetSize();
m_size = volume.GetDataSize();
const DiscIO::Platform platform = volume.GetVolumeType();
@ -364,7 +364,7 @@ VolumeVerifier::VolumeVerifier(const Volume& volume, bool redump_verification,
m_hashes_to_calculate(hashes_to_calculate),
m_calculating_any_hash(hashes_to_calculate.crc32 || hashes_to_calculate.md5 ||
hashes_to_calculate.sha1),
m_max_progress(volume.GetSize())
m_max_progress(volume.GetDataSize())
{
if (!m_calculating_any_hash)
m_redump_verification = false;
@ -758,10 +758,10 @@ bool VolumeVerifier::ShouldBeDualLayer() const
void VolumeVerifier::CheckVolumeSize()
{
u64 volume_size = m_volume.GetSize();
u64 volume_size = m_volume.GetDataSize();
const bool is_disc = IsDisc(m_volume.GetVolumeType());
const bool should_be_dual_layer = is_disc && ShouldBeDualLayer();
const bool is_size_accurate = m_volume.IsSizeAccurate();
const bool is_size_accurate = m_volume.GetDataSizeType() != DiscIO::DataSizeType::Accurate;
bool volume_size_roughly_known = is_size_accurate;
if (should_be_dual_layer && m_biggest_referenced_offset <= SL_DVD_R_SIZE)

View File

@ -318,14 +318,14 @@ BlobType VolumeWAD::GetBlobType() const
return m_reader->GetBlobType();
}
u64 VolumeWAD::GetSize() const
u64 VolumeWAD::GetDataSize() const
{
return m_reader->GetDataSize();
}
bool VolumeWAD::IsSizeAccurate() const
DataSizeType VolumeWAD::GetDataSizeType() const
{
return m_reader->IsDataSizeAccurate();
return m_reader->GetDataSizeType();
}
u64 VolumeWAD::GetRawSize() const

View File

@ -64,8 +64,8 @@ public:
Country GetCountry(const Partition& partition = PARTITION_NONE) const override;
BlobType GetBlobType() const override;
u64 GetSize() const override;
bool IsSizeAccurate() const override;
u64 GetDataSize() const override;
DataSizeType GetDataSizeType() const override;
u64 GetRawSize() const override;
const BlobReader& GetBlobReader() const override;

View File

@ -369,14 +369,14 @@ BlobType VolumeWii::GetBlobType() const
return m_reader->GetBlobType();
}
u64 VolumeWii::GetSize() const
u64 VolumeWii::GetDataSize() const
{
return m_reader->GetDataSize();
}
bool VolumeWii::IsSizeAccurate() const
DataSizeType VolumeWii::GetDataSizeType() const
{
return m_reader->IsDataSizeAccurate();
return m_reader->GetDataSizeType();
}
u64 VolumeWii::GetRawSize() const

View File

@ -86,8 +86,8 @@ public:
Region GetRegion() const override;
BlobType GetBlobType() const override;
u64 GetSize() const override;
bool IsSizeAccurate() const override;
u64 GetDataSize() const override;
DataSizeType GetDataSizeType() const override;
u64 GetRawSize() const override;
const BlobReader& GetBlobReader() const override;
std::array<u8, 20> GetSyncHash() const override;

View File

@ -1731,7 +1731,7 @@ WIARVZFileReader<RVZ>::Convert(BlobReader* infile, const VolumeDisc* infile_volu
File::IOFile* outfile, WIARVZCompressionType compression_type,
int compression_level, int chunk_size, CompressCB callback)
{
ASSERT(infile->IsDataSizeAccurate());
ASSERT(infile->GetDataSizeType() == DataSizeType::Accurate);
ASSERT(chunk_size > 0);
const u64 iso_size = infile->GetDataSize();

View File

@ -52,7 +52,7 @@ public:
u64 GetRawSize() const override { return Common::swap64(m_header_1.wia_file_size); }
u64 GetDataSize() const override { return Common::swap64(m_header_1.iso_file_size); }
bool IsDataSizeAccurate() const override { return true; }
DataSizeType GetDataSizeType() const override { return DataSizeType::Accurate; }
u64 GetBlockSize() const override { return Common::swap32(m_header_2.chunk_size); }
bool HasFastRandomAccessInBlock() const override { return false; }

View File

@ -25,11 +25,8 @@ public:
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; }
DataSizeType GetDataSizeType() const override { return DataSizeType::UpperBound; }
u64 GetBlockSize() const override { return m_wbfs_sector_size; }
bool HasFastRandomAccessInBlock() const override { return true; }

View File

@ -212,7 +212,7 @@ int ConvertCommand::Main(const std::vector<std::string>& args)
}
if (format == DiscIO::BlobType::GCZ && volume &&
!DiscIO::IsGCZBlockSizeLegacyCompatible(block_size_o.value(), volume->GetSize()))
!DiscIO::IsGCZBlockSizeLegacyCompatible(block_size_o.value(), volume->GetDataSize()))
{
std::cerr << "Warning: For GCZs to be compatible with Dolphin < 5.0-11893, "
"the file size must be an integer multiple of the block size "

View File

@ -133,8 +133,8 @@ GameFile::GameFile(std::string path) : m_file_path(std::move(path))
m_block_size = volume->GetBlobReader().GetBlockSize();
m_compression_method = volume->GetBlobReader().GetCompressionMethod();
m_file_size = volume->GetRawSize();
m_volume_size = volume->GetSize();
m_volume_size_is_accurate = volume->IsSizeAccurate();
m_volume_size = volume->GetDataSize();
m_volume_size_type = volume->GetDataSizeType();
m_is_datel_disc = volume->IsDatelDisc();
m_is_nkit = volume->IsNKit();
@ -158,7 +158,7 @@ GameFile::GameFile(std::string path) : m_file_path(std::move(path))
m_valid = true;
m_file_size = m_volume_size = File::GetSize(m_file_path);
m_game_id = SConfig::MakeGameID(m_file_name);
m_volume_size_is_accurate = true;
m_volume_size_type = DiscIO::DataSizeType::Accurate;
m_is_datel_disc = false;
m_is_nkit = false;
m_platform = DiscIO::Platform::ELFOrDOL;
@ -349,7 +349,7 @@ void GameFile::DoState(PointerWrap& p)
p.Do(m_file_size);
p.Do(m_volume_size);
p.Do(m_volume_size_is_accurate);
p.Do(m_volume_size_type);
p.Do(m_is_datel_disc);
p.Do(m_is_nkit);
@ -827,7 +827,7 @@ std::string GameFile::GetFileFormatName() const
bool GameFile::ShouldAllowConversion() const
{
return DiscIO::IsDisc(m_platform) && m_volume_size_is_accurate;
return DiscIO::IsDisc(m_platform) && m_volume_size_type == DiscIO::DataSizeType::Accurate;
}
bool GameFile::IsModDescriptor() const

View File

@ -104,7 +104,7 @@ public:
const std::string& GetApploaderDate() const { return m_apploader_date; }
u64 GetFileSize() const { return m_file_size; }
u64 GetVolumeSize() const { return m_volume_size; }
bool IsVolumeSizeAccurate() const { return m_volume_size_is_accurate; }
DiscIO::DataSizeType GetVolumeSizeType() const { return m_volume_size_type; }
bool IsDatelDisc() const { return m_is_datel_disc; }
bool IsNKit() const { return m_is_nkit; }
bool IsModDescriptor() const;
@ -145,7 +145,7 @@ private:
u64 m_file_size{};
u64 m_volume_size{};
bool m_volume_size_is_accurate{};
DiscIO::DataSizeType m_volume_size_type{};
bool m_is_datel_disc{};
bool m_is_nkit{};

View File

@ -27,7 +27,7 @@
namespace UICommon
{
static constexpr u32 CACHE_REVISION = 22; // Last changed in PR 10932
static constexpr u32 CACHE_REVISION = 23; // Last changed in PR 10932
std::vector<std::string> FindAllGamePaths(const std::vector<std::string>& directories_to_scan,
bool recursive_scan)