Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8850 from JosJuice/block-size-warning
Show an OSD message when running a disc image with a large block size
  • Loading branch information
Tilka committed Jun 14, 2020
2 parents ad85012 + 162e3be commit f9f4734
Show file tree
Hide file tree
Showing 19 changed files with 78 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Source/Core/Core/HW/DVD/DVDInterface.cpp
Expand Up @@ -36,6 +36,7 @@
#include "Core/IOS/IOS.h"
#include "Core/Movie.h"

#include "DiscIO/Blob.h"
#include "DiscIO/Enums.h"
#include "DiscIO/Volume.h"
#include "DiscIO/VolumeWii.h"
Expand Down Expand Up @@ -426,6 +427,17 @@ void SetDisc(std::unique_ptr<DiscIO::VolumeDisc> disc,
bool had_disc = IsDiscInside();
bool has_disc = static_cast<bool>(disc);

if (has_disc)
{
const DiscIO::BlobReader& blob = disc->GetBlobReader();
if (!blob.HasFastRandomAccessInBlock() && blob.GetBlockSize() > 0x200000)
{
OSD::AddMessage("You are running a disc image with a very large block size.", 60000);
OSD::AddMessage("This will likely lead to performance problems.", 60000);
OSD::AddMessage("You can use Dolphin's convert feature to reduce the block size.", 60000);
}
}

if (auto_disc_change_paths)
{
ASSERT_MSG(DISCIO, (*auto_disc_change_paths).size() != 1,
Expand Down
3 changes: 2 additions & 1 deletion Source/Core/DiscIO/Blob.h
Expand Up @@ -49,7 +49,8 @@ class BlobReader
virtual bool IsDataSizeAccurate() const = 0;

// Returns 0 if the format does not use blocks
virtual u64 GetBlockSize() const { return 0; }
virtual u64 GetBlockSize() const = 0;
virtual bool HasFastRandomAccessInBlock() const = 0;

// NOT thread-safe - can't call this from multiple threads.
virtual bool Read(u64 offset, u64 size, u8* out_ptr) = 0;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DiscIO/CISOBlob.h
Expand Up @@ -45,6 +45,7 @@ class CISOFileReader : public BlobReader
bool IsDataSizeAccurate() const override { return false; }

u64 GetBlockSize() const override { return m_block_size; }
bool HasFastRandomAccessInBlock() const override { return true; }

bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;

Expand Down
6 changes: 6 additions & 0 deletions Source/Core/DiscIO/CompressedBlob.h
Expand Up @@ -47,12 +47,18 @@ class CompressedBlobReader : public SectorReader
static std::unique_ptr<CompressedBlobReader> Create(File::IOFile file,
const std::string& filename);
~CompressedBlobReader();

const CompressedBlobHeader& GetHeader() const { return m_header; }

BlobType GetBlobType() const override { return BlobType::GCZ; }

u64 GetRawSize() const override { return m_file_size; }
u64 GetDataSize() const override { return m_header.data_size; }
bool IsDataSizeAccurate() const override { return true; }

u64 GetBlockSize() const override { return m_header.block_size; }
bool HasFastRandomAccessInBlock() const override { return false; }

u64 GetBlockCompressedSize(u64 block_num) const;
bool GetBlock(u64 block_num, u8* out_ptr) override;

Expand Down
4 changes: 4 additions & 0 deletions Source/Core/DiscIO/DirectoryBlob.h
Expand Up @@ -161,10 +161,14 @@ class DirectoryBlobReader : public BlobReader
bool ReadWiiDecrypted(u64 offset, u64 size, u8* buffer, u64 partition_data_offset) override;

BlobType GetBlobType() const override;

u64 GetRawSize() const override;
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return true; }

u64 GetBlockSize() const override { return 0; }
bool HasFastRandomAccessInBlock() const override { return true; }

private:
struct PartitionWithType
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DiscIO/DriveBlob.h
Expand Up @@ -31,6 +31,7 @@ class DriveReader : public SectorReader
bool IsDataSizeAccurate() const override { return true; }

u64 GetBlockSize() const override { return ECC_BLOCK_SIZE; }
bool HasFastRandomAccessInBlock() const override { return false; }

private:
DriveReader(const std::string& drive);
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DiscIO/FileBlob.h
Expand Up @@ -20,9 +20,14 @@ class PlainFileReader : public BlobReader
static std::unique_ptr<PlainFileReader> Create(File::IOFile file);

BlobType GetBlobType() const override { return BlobType::PLAIN; }

u64 GetRawSize() const override { return m_size; }
u64 GetDataSize() const override { return m_size; }
bool IsDataSizeAccurate() const override { return true; }

u64 GetBlockSize() const override { return 0; }
bool HasFastRandomAccessInBlock() const override { return true; }

bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;

private:
Expand Down
6 changes: 6 additions & 0 deletions Source/Core/DiscIO/ScrubbedBlob.h
Expand Up @@ -20,10 +20,16 @@ class ScrubbedBlob : public BlobReader
static std::unique_ptr<ScrubbedBlob> Create(const std::string& path);

BlobType GetBlobType() const override { return m_blob_reader->GetBlobType(); }

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(); }

u64 GetBlockSize() const override { return m_blob_reader->GetBlockSize(); }
bool HasFastRandomAccessInBlock() const override
{
return m_blob_reader->HasFastRandomAccessInBlock();
}

bool Read(u64 offset, u64 size, u8* out_ptr) override;

Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DiscIO/TGCBlob.h
Expand Up @@ -43,9 +43,14 @@ class TGCFileReader final : public BlobReader
static std::unique_ptr<TGCFileReader> Create(File::IOFile file);

BlobType GetBlobType() const override { return BlobType::TGC; }

u64 GetRawSize() const override { return m_size; }
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return true; }

u64 GetBlockSize() const override { return 0; }
bool HasFastRandomAccessInBlock() const override { return true; }

bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;

private:
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/DiscIO/Volume.h
Expand Up @@ -20,6 +20,7 @@

namespace DiscIO
{
class BlobReader;
enum class BlobType;
class FileSystem;
class VolumeWAD;
Expand Down Expand Up @@ -132,6 +133,7 @@ class Volume
virtual bool IsSizeAccurate() const = 0;
// Size on disc (compressed size)
virtual u64 GetRawSize() const = 0;
virtual const BlobReader& GetBlobReader() const = 0;

protected:
template <u32 N>
Expand Down
10 changes: 10 additions & 0 deletions Source/Core/DiscIO/VolumeFileBlobReader.cpp
Expand Up @@ -44,6 +44,16 @@ u64 VolumeFileBlobReader::GetRawSize() const
return GetDataSize();
}

u64 VolumeFileBlobReader::GetBlockSize() const
{
return m_volume.GetBlobReader().GetBlockSize();
}

bool VolumeFileBlobReader::HasFastRandomAccessInBlock() const
{
return m_volume.GetBlobReader().HasFastRandomAccessInBlock();
}

bool VolumeFileBlobReader::Read(u64 offset, u64 length, u8* out_ptr)
{
if (offset + length > m_file_info->GetSize())
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DiscIO/VolumeFileBlobReader.h
Expand Up @@ -23,9 +23,14 @@ class VolumeFileBlobReader final : public BlobReader
Create(const Volume& volume, const Partition& partition, std::string_view file_path);

BlobType GetBlobType() const override { return BlobType::PLAIN; }

u64 GetRawSize() const override;
u64 GetDataSize() const override;
bool IsDataSizeAccurate() const override { return true; }

u64 GetBlockSize() const override;
bool HasFastRandomAccessInBlock() const override;

bool Read(u64 offset, u64 length, u8* out_ptr) override;

private:
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DiscIO/VolumeGC.cpp
Expand Up @@ -188,6 +188,11 @@ u64 VolumeGC::GetRawSize() const
return m_reader->GetRawSize();
}

const BlobReader& VolumeGC::GetBlobReader() const
{
return *m_reader;
}

std::optional<u8> VolumeGC::GetDiscNumber(const Partition& partition) const
{
return ReadSwapped<u8>(6, partition);
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DiscIO/VolumeGC.h
Expand Up @@ -54,6 +54,7 @@ class VolumeGC : public VolumeDisc
u64 GetSize() const override;
bool IsSizeAccurate() const override;
u64 GetRawSize() const override;
const BlobReader& GetBlobReader() const;

private:
static const u32 GC_BANNER_WIDTH = 96;
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DiscIO/VolumeWad.cpp
Expand Up @@ -327,4 +327,9 @@ u64 VolumeWAD::GetRawSize() const
return m_reader->GetRawSize();
}

const BlobReader& VolumeWAD::GetBlobReader() const
{
return *m_reader;
}

} // namespace DiscIO
1 change: 1 addition & 0 deletions Source/Core/DiscIO/VolumeWad.h
Expand Up @@ -66,6 +66,7 @@ class VolumeWAD : public Volume
u64 GetSize() const override;
bool IsSizeAccurate() const override;
u64 GetRawSize() const override;
const BlobReader& GetBlobReader() const;

private:
std::unique_ptr<BlobReader> m_reader;
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DiscIO/VolumeWii.cpp
Expand Up @@ -434,6 +434,11 @@ u64 VolumeWii::GetRawSize() const
return m_reader->GetRawSize();
}

const BlobReader& VolumeWii::GetBlobReader() const
{
return *m_reader;
}

bool VolumeWii::CheckH3TableIntegrity(const Partition& partition) const
{
auto it = m_partitions.find(partition);
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DiscIO/VolumeWii.h
Expand Up @@ -95,6 +95,7 @@ class VolumeWii : public VolumeDisc
u64 GetSize() const override;
bool IsSizeAccurate() const override;
u64 GetRawSize() const override;
const BlobReader& GetBlobReader() const;

static bool EncryptGroup(u64 offset, u64 partition_data_offset, u64 partition_data_decrypted_size,
const std::array<u8, AES_KEY_SIZE>& key, BlobReader* blob,
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DiscIO/WbfsBlob.h
Expand Up @@ -33,6 +33,7 @@ class WbfsFileReader : public BlobReader
bool IsDataSizeAccurate() const override { return false; }

u64 GetBlockSize() const override { return m_wbfs_sector_size; }
bool HasFastRandomAccessInBlock() const override { return true; }

bool Read(u64 offset, u64 nbytes, u8* out_ptr) override;

Expand Down

0 comments on commit f9f4734

Please sign in to comment.