Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12036 from LillyJadeKatrin/deep-copy-volume
Added CopyReader to BlobReader and all subclasses
  • Loading branch information
JMC47 committed Oct 1, 2023
2 parents d55d878 + 335cf4f commit cd366c4
Show file tree
Hide file tree
Showing 28 changed files with 305 additions and 215 deletions.
9 changes: 9 additions & 0 deletions Source/Core/Common/IOFile.cpp
Expand Up @@ -101,6 +101,15 @@ bool IOFile::Close()
return m_good;
}

IOFile IOFile::Duplicate(const char openmode[]) const
{
#ifdef _WIN32
return IOFile(_fdopen(_dup(_fileno(m_file)), openmode));
#else // _WIN32
return IOFile(fdopen(dup(fileno(m_file)), openmode));
#endif // _WIN32
}

void IOFile::SetHandle(std::FILE* file)
{
Close();
Expand Down
2 changes: 2 additions & 0 deletions Source/Core/Common/IOFile.h
Expand Up @@ -51,6 +51,8 @@ class IOFile
SharedAccess sh = SharedAccess::Default);
bool Close();

IOFile Duplicate(const char openmode[]) const;

template <typename T>
bool ReadArray(T* elements, size_t count, size_t* num_read = nullptr)
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DiscIO/Blob.h
Expand Up @@ -64,6 +64,7 @@ class BlobReader
virtual ~BlobReader() {}

virtual BlobType GetBlobType() const = 0;
virtual std::unique_ptr<BlobReader> CopyReader() const = 0;

virtual u64 GetRawSize() const = 0;
virtual u64 GetDataSize() const = 0;
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DiscIO/CISOBlob.cpp
Expand Up @@ -40,6 +40,11 @@ std::unique_ptr<CISOFileReader> CISOFileReader::Create(File::IOFile file)
return nullptr;
}

std::unique_ptr<BlobReader> CISOFileReader::CopyReader() const
{
return Create(m_file.Duplicate("rb"));
}

u64 CISOFileReader::GetDataSize() const
{
return static_cast<u64>(CISO_MAP_SIZE) * m_block_size;
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DiscIO/CISOBlob.h
Expand Up @@ -36,6 +36,7 @@ class CISOFileReader : public BlobReader
static std::unique_ptr<CISOFileReader> Create(File::IOFile file);

BlobType GetBlobType() const override { return BlobType::CISO; }
std::unique_ptr<BlobReader> CopyReader() const override;

u64 GetRawSize() const override;
u64 GetDataSize() const override;
Expand Down
5 changes: 5 additions & 0 deletions Source/Core/DiscIO/CompressedBlob.cpp
Expand Up @@ -74,6 +74,11 @@ CompressedBlobReader::~CompressedBlobReader()
{
}

std::unique_ptr<BlobReader> CompressedBlobReader::CopyReader() const
{
return Create(m_file.Duplicate("rb"), m_file_name);
}

// IMPORTANT: Calling this function invalidates all earlier pointers gotten from this function.
u64 CompressedBlobReader::GetBlockCompressedSize(u64 block_num) const
{
Expand Down
1 change: 1 addition & 0 deletions Source/Core/DiscIO/CompressedBlob.h
Expand Up @@ -50,6 +50,7 @@ class CompressedBlobReader : public SectorReader
const CompressedBlobHeader& GetHeader() const { return m_header; }

BlobType GetBlobType() const override { return BlobType::GCZ; }
std::unique_ptr<BlobReader> CopyReader() const override;

u64 GetRawSize() const override { return m_file_size; }
u64 GetDataSize() const override { return m_header.data_size; }
Expand Down

0 comments on commit cd366c4

Please sign in to comment.