diff --git a/include/NOD/DiscBase.hpp b/include/NOD/DiscBase.hpp index cf7ce58..77c7d83 100644 --- a/include/NOD/DiscBase.hpp +++ b/include/NOD/DiscBase.hpp @@ -55,11 +55,11 @@ public: { public: virtual ~IPartition() {} - enum Kind + enum class Kind : uint32_t { - PART_DATA, - PART_UPDATE, - PART_CHANNEL + Data, + Update, + Channel }; struct DOLHeader { @@ -77,10 +77,10 @@ public: class Node { public: - enum Kind + enum class Kind { - NODE_FILE, - NODE_DIRECTORY + File, + Directory }; private: friend class IPartition; @@ -97,7 +97,7 @@ public: public: Node(const IPartition& parent, const FSTNode& node, const char* name) : m_parent(parent), - m_kind(node.isDir() ? NODE_DIRECTORY : NODE_FILE), + m_kind(node.isDir() ? Kind::Directory : Kind::File), m_discOffset(parent.normalizeOffset(node.getOffset())), m_discLength(node.getLength()), m_name(name) {} @@ -106,7 +106,7 @@ public: inline uint64_t size() const {return m_discLength;} std::unique_ptr beginReadStream(uint64_t offset=0) const { - if (m_kind != NODE_FILE) + if (m_kind != Kind::File) { LogModule.report(LogVisor::Error, "unable to stream a non-file %s", m_name.c_str()); return std::unique_ptr(); @@ -115,7 +115,7 @@ public: } std::unique_ptr getBuf() const { - if (m_kind != NODE_FILE) + if (m_kind != Kind::File) { LogModule.report(LogVisor::Error, "unable to buffer a non-file %s", m_name.c_str()); return std::unique_ptr(); @@ -138,7 +138,7 @@ public: inline bool operator==(const DirectoryIterator& other) {return m_it == other.m_it;} inline DirectoryIterator& operator++() { - if (m_it->m_kind == NODE_DIRECTORY) + if (m_it->m_kind == Kind::Directory) m_it = m_it->rawEnd(); else ++m_it; @@ -151,7 +151,7 @@ public: inline DirectoryIterator end() const {return DirectoryIterator(m_childrenEnd);} inline DirectoryIterator find(const std::string& name) const { - if (m_kind == NODE_DIRECTORY) + if (m_kind == Kind::Directory) { DirectoryIterator it=begin(); for (; it != end() ; ++it) @@ -235,14 +235,14 @@ public: inline IPartition* getDataPartition() { for (const std::unique_ptr& part : m_partitions) - if (part->getKind() == IPartition::PART_DATA) + if (part->getKind() == IPartition::Kind::Data) return part.get(); return nullptr; } inline IPartition* getUpdatePartition() { for (const std::unique_ptr& part : m_partitions) - if (part->getKind() == IPartition::PART_UPDATE) + if (part->getKind() == IPartition::Kind::Update) return part.get(); return nullptr; } diff --git a/lib/DiscBase.cpp b/lib/DiscBase.cpp index 08502a1..f4718ee 100644 --- a/lib/DiscBase.cpp +++ b/lib/DiscBase.cpp @@ -37,7 +37,7 @@ void DiscBase::IPartition::parseFST(IPartReadStream& s) ++it) { Node& node = *it; - if (node.m_kind == Node::NODE_DIRECTORY) + if (node.m_kind == Node::Kind::Directory) { node.m_childrenBegin = it + 1; node.m_childrenEnd = m_nodes.begin() + node.m_discLength; @@ -66,7 +66,7 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath SystemStringView nameView(getName()); SystemString path = basePath + _S("/") + nameView.sys_str(); - if (m_kind == NODE_DIRECTORY) + if (m_kind == Kind::Directory) { if (ctx.verbose && ctx.progressCB && !getName().empty()) ctx.progressCB(getName()); @@ -79,7 +79,7 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath if (!subnode.extractToDirectory(path, ctx)) return false; } - else if (m_kind == NODE_FILE) + else if (m_kind == Kind::File) { Sstat theStat; if (ctx.verbose && ctx.progressCB) diff --git a/lib/DiscGCN.cpp b/lib/DiscGCN.cpp index d5432c9..26e990f 100644 --- a/lib/DiscGCN.cpp +++ b/lib/DiscGCN.cpp @@ -106,7 +106,7 @@ DiscGCN::DiscGCN(std::unique_ptr&& dio) : DiscBase(std::move(dio)) { /* One lone partition for GCN */ - m_partitions.emplace_back(new PartitionGCN(*this, IPartition::PART_DATA, 0)); + m_partitions.emplace_back(new PartitionGCN(*this, IPartition::Kind::Data, 0)); } bool DiscGCN::commit() diff --git a/lib/DiscWii.cpp b/lib/DiscWii.cpp index f2b1054..d871fda 100644 --- a/lib/DiscWii.cpp +++ b/lib/DiscWii.cpp @@ -23,17 +23,17 @@ static const uint8_t COMMON_KEYS[2][16] = class PartitionWii : public DiscBase::IPartition { - enum SigType : uint32_t + enum class SigType : uint32_t { - SRSA_4096 = 0x00010000, - SRSA_2048 = 0x00010001, - SELIPTICAL_CURVE = 0x00010002 + RSA_4096 = 0x00010000, + RSA_2048 = 0x00010001, + ELIPTICAL_CURVE = 0x00010002 }; - enum KeyType : uint32_t + enum class KeyType : uint32_t { - KRSA_4096 = 0x00000000, - KRSA_2048 = 0x00000001 + RSA_4096 = 0x00000000, + RSA_2048 = 0x00000001 }; struct Ticket @@ -124,7 +124,7 @@ class PartitionWii : public DiscBase::IPartition void read(IDiscIO::IReadStream& s) { s.read(this, 484); - sigType = (SigType)SBig(sigType); + sigType = SigType(SBig(uint32_t(sigType))); iosIdMajor = SBig(iosIdMajor); iosIdMinor = SBig(iosIdMinor); titleIdMajor = SBig(titleIdMajor); @@ -158,22 +158,22 @@ class PartitionWii : public DiscBase::IPartition void read(IDiscIO::IReadStream& s) { s.read(&sigType, 4); - sigType = (SigType)SBig(sigType); - if (sigType == SRSA_4096) + sigType = SigType(SBig(uint32_t(sigType))); + if (sigType == SigType::RSA_4096) s.read(sig, 512); - else if (sigType == SRSA_2048) + else if (sigType == SigType::RSA_2048) s.read(sig, 256); - else if (sigType == SELIPTICAL_CURVE) + else if (sigType == SigType::ELIPTICAL_CURVE) s.read(sig, 64); s.seek(60, SEEK_CUR); s.read(issuer, 64); s.read(&keyType, 4); s.read(subject, 64); - keyType = (KeyType)SBig(keyType); - if (keyType == KRSA_4096) + keyType = KeyType(SBig(uint32_t(keyType))); + if (keyType == KeyType::RSA_4096) s.read(key, 512); - else if (keyType == KRSA_2048) + else if (keyType == KeyType::RSA_2048) s.read(key, 256); s.read(&modulus, 8); @@ -345,18 +345,14 @@ DiscWii::DiscWii(std::unique_ptr&& dio) : DiscBase(std::move(dio)) { /* Read partition info */ - struct PartInfo { + struct PartInfo + { uint32_t partCount; uint32_t partInfoOff; struct Part { uint32_t partDataOff; - enum Type : uint32_t - { - PART_DATA = 0, - PART_UPDATE = 1, - PART_CHANNEL = 2 - } partType; + IPartition::Kind partType; } parts[4]; PartInfo(IDiscIO& dio) { @@ -370,7 +366,7 @@ DiscWii::DiscWii(std::unique_ptr&& dio) { s->read(&parts[p], 8); parts[p].partDataOff = SBig(parts[p].partDataOff); - parts[p].partType = (Part::Type)SBig(parts[p].partType); + parts[p].partType = IPartition::Kind(SBig(uint32_t(parts[p].partType))); } } } partInfo(*m_discIO); @@ -380,15 +376,17 @@ DiscWii::DiscWii(std::unique_ptr&& dio) for (uint32_t p=0 ; p