mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-12-27 01:22:37 -06:00
core/file_sys: Make RomFSReader an abstract interface
The original RomFSReader is renamed to DirectRomFSReader that directly reads the RomFS.
This commit is contained in:
parent
821a35bd2b
commit
83e0cc45f4
2 changed files with 19 additions and 7 deletions
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
std::size_t RomFSReader::ReadFile(std::size_t offset, std::size_t length, u8* buffer) {
|
std::size_t DirectRomFSReader::ReadFile(std::size_t offset, std::size_t length, u8* buffer) {
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
return 0; // Crypto++ does not like zero size buffer
|
return 0; // Crypto++ does not like zero size buffer
|
||||||
file.Seek(file_offset + offset, SEEK_SET);
|
file.Seek(file_offset + offset, SEEK_SET);
|
||||||
|
|
|
@ -6,23 +6,35 @@
|
||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for reading RomFS data.
|
||||||
|
*/
|
||||||
class RomFSReader {
|
class RomFSReader {
|
||||||
public:
|
public:
|
||||||
RomFSReader(FileUtil::IOFile&& file, std::size_t file_offset, std::size_t data_size)
|
virtual std::size_t GetSize() const = 0;
|
||||||
|
virtual std::size_t ReadFile(std::size_t offset, std::size_t length, u8* buffer) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A RomFS reader that directly reads the RomFS file.
|
||||||
|
*/
|
||||||
|
class DirectRomFSReader : public RomFSReader {
|
||||||
|
public:
|
||||||
|
DirectRomFSReader(FileUtil::IOFile&& file, std::size_t file_offset, std::size_t data_size)
|
||||||
: is_encrypted(false), file(std::move(file)), file_offset(file_offset),
|
: is_encrypted(false), file(std::move(file)), file_offset(file_offset),
|
||||||
data_size(data_size) {}
|
data_size(data_size) {}
|
||||||
|
|
||||||
RomFSReader(FileUtil::IOFile&& file, std::size_t file_offset, std::size_t data_size,
|
DirectRomFSReader(FileUtil::IOFile&& file, std::size_t file_offset, std::size_t data_size,
|
||||||
const std::array<u8, 16>& key, const std::array<u8, 16>& ctr,
|
const std::array<u8, 16>& key, const std::array<u8, 16>& ctr,
|
||||||
std::size_t crypto_offset)
|
std::size_t crypto_offset)
|
||||||
: is_encrypted(true), file(std::move(file)), key(key), ctr(ctr), file_offset(file_offset),
|
: is_encrypted(true), file(std::move(file)), key(key), ctr(ctr), file_offset(file_offset),
|
||||||
crypto_offset(crypto_offset), data_size(data_size) {}
|
crypto_offset(crypto_offset), data_size(data_size) {}
|
||||||
|
|
||||||
std::size_t GetSize() const {
|
std::size_t GetSize() const override {
|
||||||
return data_size;
|
return data_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t ReadFile(std::size_t offset, std::size_t length, u8* buffer);
|
std::size_t ReadFile(std::size_t offset, std::size_t length, u8* buffer) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool is_encrypted;
|
bool is_encrypted;
|
||||||
|
|
Loading…
Reference in a new issue