From 335cf4f2db4160ebbf387aeb19dc637182c91c5a Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Fri, 7 Jul 2023 08:31:26 -0400 Subject: Added CopyReader to BlobReader and all subclasses A deep-copy method CopyReader has been added to BlobReader (virtual) and all of its subclasses (override). This should create a second BlobReader to open the same set of data but with an independent read pointer so that it doesn't interfere with any reads done on the original Reader. As part of this, IOFile has added code to create a deep copy IOFile pointer onto the same file, with code based on the platform in question to find the file ID from the file pointer and open a new one. There has also been a small piece added to FileInfo to enable a deep copy, but its only subclass at this time already had a copy constructor so this was relatively minor. --- Source/Core/DiscIO/NFSBlob.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'Source/Core/DiscIO/NFSBlob.cpp') diff --git a/Source/Core/DiscIO/NFSBlob.cpp b/Source/Core/DiscIO/NFSBlob.cpp index 3960fff75e..4b33596802 100644 --- a/Source/Core/DiscIO/NFSBlob.cpp +++ b/Source/Core/DiscIO/NFSBlob.cpp @@ -160,11 +160,20 @@ std::unique_ptr NFSFileReader::Create(File::IOFile first_file, NFSFileReader::NFSFileReader(std::vector lba_ranges, std::vector files, Key key, u64 raw_size) : m_lba_ranges(std::move(lba_ranges)), m_files(std::move(files)), - m_aes_context(Common::AES::CreateContextDecrypt(key.data())), m_raw_size(raw_size) + m_aes_context(Common::AES::CreateContextDecrypt(key.data())), m_raw_size(raw_size), m_key(key) { m_data_size = CalculateExpectedDataSize(m_lba_ranges); } +std::unique_ptr NFSFileReader::CopyReader() const +{ + std::vector new_files{}; + for (const File::IOFile& file : m_files) + new_files.push_back(file.Duplicate("rb")); + return std::unique_ptr( + new NFSFileReader(m_lba_ranges, std::move(new_files), m_key, m_raw_size)); +} + u64 NFSFileReader::GetDataSize() const { return m_data_size; -- cgit v1.2.3