General: Make use of override where applicable

Makes it explicit where functions are being overridden in derived
classes/structs.
This commit is contained in:
Lioncash 2019-08-10 01:41:41 -04:00
parent ac6f2a1ed2
commit 2171388b9d
10 changed files with 73 additions and 71 deletions

View File

@ -11,7 +11,7 @@ class DiscGCN : public DiscBase {
public:
DiscGCN(std::unique_ptr<IDiscIO>&& dio, bool& err);
bool extractDiscHeaderFiles(SystemStringView path, const ExtractionContext& ctx) const;
bool extractDiscHeaderFiles(SystemStringView path, const ExtractionContext& ctx) const override;
};
class DiscBuilderGCN : public DiscBuilderBase {

View File

@ -9,7 +9,7 @@ class DiscWii : public DiscBase {
public:
DiscWii(std::unique_ptr<IDiscIO>&& dio, bool& err);
DiscBuilderWii makeMergeBuilder(SystemStringView outPath, bool dualLayer, FProgress progressCB);
bool extractDiscHeaderFiles(SystemStringView path, const ExtractionContext& ctx) const;
bool extractDiscHeaderFiles(SystemStringView path, const ExtractionContext& ctx) const override;
};
class DiscBuilderWii : public DiscBuilderBase {

View File

@ -32,11 +32,11 @@ public:
};
struct IPartReadStream : IReadStream {
virtual ~IPartReadStream() = default;
~IPartReadStream() override = default;
};
struct IPartWriteStream : IWriteStream {
virtual ~IPartWriteStream() = default;
~IPartWriteStream() override = default;
virtual void close() = 0;
virtual uint64_t position() const = 0;
};
@ -49,15 +49,15 @@ class AthenaPartReadStream : public athena::io::IStreamReader {
public:
AthenaPartReadStream(std::unique_ptr<IPartReadStream>&& rs) : m_rs(std::move(rs)) {}
inline void seek(atInt64 off, athena::SeekOrigin origin) {
void seek(atInt64 off, athena::SeekOrigin origin) override {
if (origin == athena::Begin)
m_rs->seek(off, SEEK_SET);
else if (origin == athena::Current)
m_rs->seek(off, SEEK_CUR);
}
inline atUint64 position() const { return m_rs->position(); }
inline atUint64 length() const { return 0; }
inline atUint64 readUBytesToBuf(void* buf, atUint64 sz) {
atUint64 position() const override { return m_rs->position(); }
atUint64 length() const override { return 0; }
atUint64 readUBytesToBuf(void* buf, atUint64 sz) override {
m_rs->read(buf, sz);
return sz;
}

View File

@ -52,7 +52,7 @@ public:
m_dio->read(m_buf, BUFFER_SZ);
m_curBlock = block;
}
void seek(int64_t offset, int whence) {
void seek(int64_t offset, int whence) override {
if (whence == SEEK_SET)
m_offset = offset;
else if (whence == SEEK_CUR)
@ -66,8 +66,8 @@ public:
m_curBlock = block;
}
}
uint64_t position() const { return m_offset; }
uint64_t read(void* buf, uint64_t length) {
uint64_t position() const override { return m_offset; }
uint64_t read(void* buf, uint64_t length) override {
size_t block = m_offset / BUFFER_SZ;
size_t cacheOffset = m_offset % BUFFER_SZ;
uint64_t cacheSize;
@ -96,7 +96,7 @@ public:
}
};
std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset) const {
std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset) const override {
bool Err = false;
auto ret = std::unique_ptr<IPartReadStream>(new PartReadStream(*this, offset, Err));
if (Err)
@ -135,9 +135,9 @@ public:
if (!m_fio)
err = true;
}
void close() { m_fio.reset(); }
uint64_t position() const { return m_offset; }
uint64_t write(const void* buf, uint64_t length) {
void close() override { m_fio.reset(); }
uint64_t position() const override { return m_offset; }
uint64_t write(const void* buf, uint64_t length) override {
uint64_t len = m_fio->write(buf, length);
m_offset += len;
return len;
@ -151,7 +151,7 @@ public:
PartitionBuilderGCN(DiscBuilderBase& parent)
: DiscBuilderBase::PartitionBuilderBase(parent, PartitionKind::Data, false) {}
uint64_t userAllocate(uint64_t reqSz, IPartWriteStream& ws) {
uint64_t userAllocate(uint64_t reqSz, IPartWriteStream& ws) override {
m_curUser -= reqSz;
m_curUser &= 0xfffffffffffffff0;
if (m_curUser < 0x30000) {
@ -162,9 +162,9 @@ public:
return m_curUser;
}
uint32_t packOffset(uint64_t offset) const { return offset; }
uint32_t packOffset(uint64_t offset) const override { return offset; }
std::unique_ptr<IPartWriteStream> beginWriteStream(uint64_t offset) {
std::unique_ptr<IPartWriteStream> beginWriteStream(uint64_t offset) override {
bool Err = false;
std::unique_ptr<IPartWriteStream> ret = std::make_unique<PartWriteStream>(*this, offset, Err);
if (Err)

View File

@ -20,12 +20,12 @@ public:
}
public:
uint64_t read(void* buf, uint64_t length) { return fp->read(buf, length); }
uint64_t position() const { return fp->position(); }
void seek(int64_t offset, int whence) { fp->seek(offset, whence); }
uint64_t read(void* buf, uint64_t length) override { return fp->read(buf, length); }
uint64_t position() const override { return fp->position(); }
void seek(int64_t offset, int whence) override { fp->seek(offset, whence); }
};
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const {
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const override {
bool Err = false;
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_fio->beginReadStream(offset), Err));
if (Err)
@ -42,10 +42,10 @@ public:
}
public:
uint64_t write(const void* buf, uint64_t length) { return fp->write(buf, length); }
uint64_t write(const void* buf, uint64_t length) override { return fp->write(buf, length); }
};
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const {
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const override {
bool Err = false;
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_fio->beginWriteStream(offset), Err));
if (Err)

View File

@ -232,7 +232,7 @@ public:
}
public:
uint64_t read(void* buf, uint64_t length) {
uint64_t read(void* buf, uint64_t length) override {
uint8_t extra[4];
uint64_t rem_offset = m_offset % 4;
if (rem_offset) {
@ -249,8 +249,8 @@ public:
m_offset += length;
return length;
}
uint64_t position() const { return m_offset; }
void seek(int64_t offset, int whence) {
uint64_t position() const override { return m_offset; }
void seek(int64_t offset, int whence) override {
if (whence == SEEK_SET)
m_offset = offset;
else if (whence == SEEK_CUR)
@ -258,7 +258,7 @@ public:
}
};
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const {
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const override {
bool Err = false;
auto ret = std::unique_ptr<IReadStream>(new ReadStream(*this, NewFileIO(filepath)->beginReadStream(), offset, Err));
if (Err)
@ -266,7 +266,9 @@ public:
return ret;
}
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const { return std::unique_ptr<IWriteStream>(); }
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const override {
return std::unique_ptr<IWriteStream>();
}
};
std::unique_ptr<IDiscIO> NewDiscIOWBFS(SystemStringView path) { return std::unique_ptr<IDiscIO>(new DiscIOWBFS(path)); }

View File

@ -345,7 +345,7 @@ public:
decryptBlock();
m_curBlock = block;
}
void seek(int64_t offset, int whence) {
void seek(int64_t offset, int whence) override {
if (whence == SEEK_SET)
m_offset = offset;
else if (whence == SEEK_CUR)
@ -359,8 +359,8 @@ public:
m_curBlock = block;
}
}
uint64_t position() const { return m_offset; }
uint64_t read(void* buf, uint64_t length) {
uint64_t position() const override { return m_offset; }
uint64_t read(void* buf, uint64_t length) override {
size_t block = m_offset / 0x7c00;
size_t cacheOffset = m_offset % 0x7c00;
uint64_t cacheSize;
@ -389,7 +389,7 @@ public:
}
};
std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset) const {
std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset) const override {
bool Err = false;
auto ret = std::unique_ptr<IPartReadStream>(new PartReadStream(*this, m_dataOff, offset, Err));
if (Err)
@ -397,7 +397,7 @@ public:
return ret;
}
uint64_t normalizeOffset(uint64_t anOffset) const { return anOffset << 2; }
uint64_t normalizeOffset(uint64_t anOffset) const override { return anOffset << 2; }
std::unique_ptr<uint8_t[]> readPartitionHeaderBuf(size_t& szOut) const {
{
@ -424,7 +424,7 @@ public:
return buf;
}
bool extractCryptoFiles(SystemStringView basePath, const ExtractionContext& ctx) const {
bool extractCryptoFiles(SystemStringView basePath, const ExtractionContext& ctx) const override {
Sstat theStat;
SystemString basePathStr(basePath);
@ -679,8 +679,8 @@ public:
err = true;
m_curGroup = group;
}
~PartWriteStream() { close(); }
void close() {
~PartWriteStream() override { PartWriteStream::close(); }
void close() override {
if (m_closed)
return;
m_closed = true;
@ -692,8 +692,8 @@ public:
encryptGroup(m_parent.m_h3[m_curGroup]);
m_fio.reset();
}
uint64_t position() const { return m_offset; }
uint64_t write(const void* buf, uint64_t length) {
uint64_t position() const override { return m_offset; }
uint64_t write(const void* buf, uint64_t length) override {
size_t group = m_offset / 0x1F0000;
size_t block = (m_offset - group * 0x1F0000) / 0x7c00;
size_t cacheOffset = m_offset % 0x7c00;
@ -736,7 +736,7 @@ public:
uint64_t getCurUserEnd() const { return m_curUser; }
uint64_t userAllocate(uint64_t reqSz, IPartWriteStream& ws) {
uint64_t userAllocate(uint64_t reqSz, IPartWriteStream& ws) override {
reqSz = ROUND_UP_32(reqSz);
if (m_curUser + reqSz >= 0x1FB450000) {
LogModule.report(logvisor::Error, fmt("partition exceeds maximum single-partition capacity"));
@ -754,9 +754,9 @@ public:
return ret;
}
uint32_t packOffset(uint64_t offset) const { return uint32_t(offset >> uint64_t(2)); }
uint32_t packOffset(uint64_t offset) const override { return uint32_t(offset >> uint64_t(2)); }
std::unique_ptr<IPartWriteStream> beginWriteStream(uint64_t offset) {
std::unique_ptr<IPartWriteStream> beginWriteStream(uint64_t offset) override {
bool Err = false;
std::unique_ptr<IPartWriteStream> ret =
std::make_unique<PartWriteStream>(*this, m_baseOffset + m_userOffset, offset, Err);

View File

@ -13,7 +13,7 @@ class FileIOFILE : public IFileIO {
public:
FileIOFILE(SystemStringView path, int64_t maxWriteSize) : m_path(path), m_maxWriteSize(maxWriteSize) {}
bool exists() {
bool exists() override {
FILE* fp = Fopen(m_path.c_str(), _SYS_STR("rb"));
if (!fp)
return false;
@ -21,7 +21,7 @@ public:
return true;
}
uint64_t size() {
uint64_t size() override {
FILE* fp = Fopen(m_path.c_str(), _SYS_STR("rb"));
if (!fp)
return 0;
@ -56,8 +56,8 @@ public:
LogModule.report(logvisor::Error, fmt(_SYS_STR("unable to open '{}' for writing")), path);
err = true;
}
~WriteStream() { fclose(fp); }
uint64_t write(const void* buf, uint64_t length) {
~WriteStream() override { fclose(fp); }
uint64_t write(const void* buf, uint64_t length) override {
if (m_maxWriteSize >= 0) {
if (FTell(fp) + length > m_maxWriteSize) {
LogModule.report(logvisor::Error, fmt(_SYS_STR("write operation exceeds file's {}-byte limit")),
@ -68,14 +68,14 @@ public:
return fwrite(buf, 1, length, fp);
}
};
std::unique_ptr<IWriteStream> beginWriteStream() const {
std::unique_ptr<IWriteStream> beginWriteStream() const override {
bool Err = false;
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_path, m_maxWriteSize, Err));
if (Err)
return {};
return ret;
}
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const {
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const override {
bool Err = false;
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_path, offset, m_maxWriteSize, Err));
if (Err)
@ -97,11 +97,11 @@ public:
return;
FSeek(fp, offset, SEEK_SET);
}
~ReadStream() { fclose(fp); }
void seek(int64_t offset, int whence) { FSeek(fp, offset, whence); }
uint64_t position() const { return FTell(fp); }
uint64_t read(void* buf, uint64_t length) { return fread(buf, 1, length, fp); }
uint64_t copyToDisc(IPartWriteStream& discio, uint64_t length) {
~ReadStream() override { fclose(fp); }
void seek(int64_t offset, int whence) override { FSeek(fp, offset, whence); }
uint64_t position() const override { return FTell(fp); }
uint64_t read(void* buf, uint64_t length) override { return fread(buf, 1, length, fp); }
uint64_t copyToDisc(IPartWriteStream& discio, uint64_t length) override {
uint64_t written = 0;
uint8_t buf[0x7c00];
while (length) {
@ -120,14 +120,14 @@ public:
return written;
}
};
std::unique_ptr<IReadStream> beginReadStream() const {
std::unique_ptr<IReadStream> beginReadStream() const override {
bool Err = false;
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_path, Err));
if (Err)
return {};
return ret;
}
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const {
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const override {
bool Err = false;
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_path, offset, Err));
if (Err)

View File

@ -13,7 +13,7 @@ class FileIOWin32 : public IFileIO {
public:
FileIOWin32(SystemStringView path, int64_t maxWriteSize) : m_path(path), m_maxWriteSize(maxWriteSize) {}
bool exists() {
bool exists() override {
#if !WINDOWS_STORE
HANDLE fp = CreateFileW(m_path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, nullptr);
@ -26,7 +26,7 @@ public:
return true;
}
uint64_t size() {
uint64_t size() override {
#if !WINDOWS_STORE
HANDLE fp = CreateFileW(m_path.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, nullptr);
@ -76,8 +76,8 @@ public:
lioffset.QuadPart = offset;
SetFilePointerEx(fp, lioffset, nullptr, FILE_BEGIN);
}
~WriteStream() { CloseHandle(fp); }
uint64_t write(const void* buf, uint64_t length) {
~WriteStream() override { CloseHandle(fp); }
uint64_t write(const void* buf, uint64_t length) override {
if (m_maxWriteSize >= 0) {
LARGE_INTEGER li = {};
LARGE_INTEGER res;
@ -94,14 +94,14 @@ public:
return ret;
}
};
std::unique_ptr<IWriteStream> beginWriteStream() const {
std::unique_ptr<IWriteStream> beginWriteStream() const override {
bool Err = false;
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_path, m_maxWriteSize, Err));
if (Err)
return {};
return ret;
}
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const {
std::unique_ptr<IWriteStream> beginWriteStream(uint64_t offset) const override {
bool Err = false;
auto ret = std::unique_ptr<IWriteStream>(new WriteStream(m_path, offset, m_maxWriteSize, Err));
if (Err)
@ -130,24 +130,24 @@ public:
lioffset.QuadPart = offset;
SetFilePointerEx(fp, lioffset, nullptr, FILE_BEGIN);
}
~ReadStream() { CloseHandle(fp); }
void seek(int64_t offset, int whence) {
~ReadStream() override { CloseHandle(fp); }
void seek(int64_t offset, int whence) override {
LARGE_INTEGER li;
li.QuadPart = offset;
SetFilePointerEx(fp, li, nullptr, whence);
}
uint64_t position() const {
uint64_t position() const override {
LARGE_INTEGER li = {};
LARGE_INTEGER res;
SetFilePointerEx(fp, li, &res, FILE_CURRENT);
return res.QuadPart;
}
uint64_t read(void* buf, uint64_t length) {
uint64_t read(void* buf, uint64_t length) override {
DWORD ret = 0;
ReadFile(fp, buf, length, &ret, nullptr);
return ret;
}
uint64_t copyToDisc(IPartWriteStream& discio, uint64_t length) {
uint64_t copyToDisc(IPartWriteStream& discio, uint64_t length) override {
uint64_t written = 0;
uint8_t buf[0x7c00];
while (length) {
@ -166,14 +166,14 @@ public:
return written;
}
};
std::unique_ptr<IReadStream> beginReadStream() const {
std::unique_ptr<IReadStream> beginReadStream() const override {
bool Err = false;
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_path, Err));
if (Err)
return {};
return ret;
}
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const {
std::unique_ptr<IReadStream> beginReadStream(uint64_t offset) const override {
bool Err = false;
auto ret = std::unique_ptr<IReadStream>(new ReadStream(m_path, offset, Err));
if (Err)

View File

@ -173,9 +173,9 @@ protected:
void _decrypt(uint8_t* buff);
public:
void encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, size_t len);
void decrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, size_t len);
void setKey(const uint8_t* key);
void encrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, size_t len) override;
void decrypt(const uint8_t* iv, const uint8_t* inbuf, uint8_t* outbuf, size_t len) override;
void setKey(const uint8_t* key) override;
};
void SoftwareAES::gkey(int nb, int nk, const uint8_t* key) {