From 2171388b9d112797311f97fceec6101b1db6d3f4 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 10 Aug 2019 01:41:41 -0400 Subject: [PATCH] General: Make use of override where applicable Makes it explicit where functions are being overridden in derived classes/structs. --- include/nod/DiscGCN.hpp | 2 +- include/nod/DiscWii.hpp | 2 +- include/nod/IDiscIO.hpp | 12 ++++++------ lib/DiscGCN.cpp | 20 ++++++++++---------- lib/DiscIOISO.cpp | 12 ++++++------ lib/DiscIOWBFS.cpp | 12 +++++++----- lib/DiscWii.cpp | 26 +++++++++++++------------- lib/FileIOFILE.cpp | 26 +++++++++++++------------- lib/FileIOWin32.cpp | 26 +++++++++++++------------- lib/aes.cpp | 6 +++--- 10 files changed, 73 insertions(+), 71 deletions(-) diff --git a/include/nod/DiscGCN.hpp b/include/nod/DiscGCN.hpp index 880afa6..21c6a63 100644 --- a/include/nod/DiscGCN.hpp +++ b/include/nod/DiscGCN.hpp @@ -11,7 +11,7 @@ class DiscGCN : public DiscBase { public: DiscGCN(std::unique_ptr&& dio, bool& err); - bool extractDiscHeaderFiles(SystemStringView path, const ExtractionContext& ctx) const; + bool extractDiscHeaderFiles(SystemStringView path, const ExtractionContext& ctx) const override; }; class DiscBuilderGCN : public DiscBuilderBase { diff --git a/include/nod/DiscWii.hpp b/include/nod/DiscWii.hpp index 783012d..bc39bad 100644 --- a/include/nod/DiscWii.hpp +++ b/include/nod/DiscWii.hpp @@ -9,7 +9,7 @@ class DiscWii : public DiscBase { public: DiscWii(std::unique_ptr&& 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 { diff --git a/include/nod/IDiscIO.hpp b/include/nod/IDiscIO.hpp index 64f3ec0..3383fa8 100644 --- a/include/nod/IDiscIO.hpp +++ b/include/nod/IDiscIO.hpp @@ -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&& 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; } diff --git a/lib/DiscGCN.cpp b/lib/DiscGCN.cpp index 2b1c0f9..81e41f0 100644 --- a/lib/DiscGCN.cpp +++ b/lib/DiscGCN.cpp @@ -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 beginReadStream(uint64_t offset) const { + std::unique_ptr beginReadStream(uint64_t offset) const override { bool Err = false; auto ret = std::unique_ptr(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 beginWriteStream(uint64_t offset) { + std::unique_ptr beginWriteStream(uint64_t offset) override { bool Err = false; std::unique_ptr ret = std::make_unique(*this, offset, Err); if (Err) diff --git a/lib/DiscIOISO.cpp b/lib/DiscIOISO.cpp index 1107213..678cf38 100644 --- a/lib/DiscIOISO.cpp +++ b/lib/DiscIOISO.cpp @@ -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 beginReadStream(uint64_t offset) const { + std::unique_ptr beginReadStream(uint64_t offset) const override { bool Err = false; auto ret = std::unique_ptr(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 beginWriteStream(uint64_t offset) const { + std::unique_ptr beginWriteStream(uint64_t offset) const override { bool Err = false; auto ret = std::unique_ptr(new WriteStream(m_fio->beginWriteStream(offset), Err)); if (Err) diff --git a/lib/DiscIOWBFS.cpp b/lib/DiscIOWBFS.cpp index 0e52403..cdd3517 100644 --- a/lib/DiscIOWBFS.cpp +++ b/lib/DiscIOWBFS.cpp @@ -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 beginReadStream(uint64_t offset) const { + std::unique_ptr beginReadStream(uint64_t offset) const override { bool Err = false; auto ret = std::unique_ptr(new ReadStream(*this, NewFileIO(filepath)->beginReadStream(), offset, Err)); if (Err) @@ -266,7 +266,9 @@ public: return ret; } - std::unique_ptr beginWriteStream(uint64_t offset) const { return std::unique_ptr(); } + std::unique_ptr beginWriteStream(uint64_t offset) const override { + return std::unique_ptr(); + } }; std::unique_ptr NewDiscIOWBFS(SystemStringView path) { return std::unique_ptr(new DiscIOWBFS(path)); } diff --git a/lib/DiscWii.cpp b/lib/DiscWii.cpp index 376111a..c81bd34 100644 --- a/lib/DiscWii.cpp +++ b/lib/DiscWii.cpp @@ -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 beginReadStream(uint64_t offset) const { + std::unique_ptr beginReadStream(uint64_t offset) const override { bool Err = false; auto ret = std::unique_ptr(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 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 beginWriteStream(uint64_t offset) { + std::unique_ptr beginWriteStream(uint64_t offset) override { bool Err = false; std::unique_ptr ret = std::make_unique(*this, m_baseOffset + m_userOffset, offset, Err); diff --git a/lib/FileIOFILE.cpp b/lib/FileIOFILE.cpp index 428e966..e2d08bb 100644 --- a/lib/FileIOFILE.cpp +++ b/lib/FileIOFILE.cpp @@ -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 beginWriteStream() const { + std::unique_ptr beginWriteStream() const override { bool Err = false; auto ret = std::unique_ptr(new WriteStream(m_path, m_maxWriteSize, Err)); if (Err) return {}; return ret; } - std::unique_ptr beginWriteStream(uint64_t offset) const { + std::unique_ptr beginWriteStream(uint64_t offset) const override { bool Err = false; auto ret = std::unique_ptr(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 beginReadStream() const { + std::unique_ptr beginReadStream() const override { bool Err = false; auto ret = std::unique_ptr(new ReadStream(m_path, Err)); if (Err) return {}; return ret; } - std::unique_ptr beginReadStream(uint64_t offset) const { + std::unique_ptr beginReadStream(uint64_t offset) const override { bool Err = false; auto ret = std::unique_ptr(new ReadStream(m_path, offset, Err)); if (Err) diff --git a/lib/FileIOWin32.cpp b/lib/FileIOWin32.cpp index 4b02187..a6d799d 100644 --- a/lib/FileIOWin32.cpp +++ b/lib/FileIOWin32.cpp @@ -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 beginWriteStream() const { + std::unique_ptr beginWriteStream() const override { bool Err = false; auto ret = std::unique_ptr(new WriteStream(m_path, m_maxWriteSize, Err)); if (Err) return {}; return ret; } - std::unique_ptr beginWriteStream(uint64_t offset) const { + std::unique_ptr beginWriteStream(uint64_t offset) const override { bool Err = false; auto ret = std::unique_ptr(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 beginReadStream() const { + std::unique_ptr beginReadStream() const override { bool Err = false; auto ret = std::unique_ptr(new ReadStream(m_path, Err)); if (Err) return {}; return ret; } - std::unique_ptr beginReadStream(uint64_t offset) const { + std::unique_ptr beginReadStream(uint64_t offset) const override { bool Err = false; auto ret = std::unique_ptr(new ReadStream(m_path, offset, Err)); if (Err) diff --git a/lib/aes.cpp b/lib/aes.cpp index 114de0d..5df85f8 100644 --- a/lib/aes.cpp +++ b/lib/aes.cpp @@ -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) {