Major scoped-enum refactor

This commit is contained in:
Jack Andersen 2015-11-20 15:15:33 -10:00
parent 3bbfad76f9
commit 168ff506a3
4 changed files with 48 additions and 50 deletions

View File

@ -55,11 +55,11 @@ public:
{ {
public: public:
virtual ~IPartition() {} virtual ~IPartition() {}
enum Kind enum class Kind : uint32_t
{ {
PART_DATA, Data,
PART_UPDATE, Update,
PART_CHANNEL Channel
}; };
struct DOLHeader struct DOLHeader
{ {
@ -77,10 +77,10 @@ public:
class Node class Node
{ {
public: public:
enum Kind enum class Kind
{ {
NODE_FILE, File,
NODE_DIRECTORY Directory
}; };
private: private:
friend class IPartition; friend class IPartition;
@ -97,7 +97,7 @@ public:
public: public:
Node(const IPartition& parent, const FSTNode& node, const char* name) Node(const IPartition& parent, const FSTNode& node, const char* name)
: m_parent(parent), : 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_discOffset(parent.normalizeOffset(node.getOffset())),
m_discLength(node.getLength()), m_discLength(node.getLength()),
m_name(name) {} m_name(name) {}
@ -106,7 +106,7 @@ public:
inline uint64_t size() const {return m_discLength;} inline uint64_t size() const {return m_discLength;}
std::unique_ptr<IPartReadStream> beginReadStream(uint64_t offset=0) const std::unique_ptr<IPartReadStream> 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()); LogModule.report(LogVisor::Error, "unable to stream a non-file %s", m_name.c_str());
return std::unique_ptr<IPartReadStream>(); return std::unique_ptr<IPartReadStream>();
@ -115,7 +115,7 @@ public:
} }
std::unique_ptr<uint8_t[]> getBuf() const std::unique_ptr<uint8_t[]> 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()); LogModule.report(LogVisor::Error, "unable to buffer a non-file %s", m_name.c_str());
return std::unique_ptr<uint8_t[]>(); return std::unique_ptr<uint8_t[]>();
@ -138,7 +138,7 @@ public:
inline bool operator==(const DirectoryIterator& other) {return m_it == other.m_it;} inline bool operator==(const DirectoryIterator& other) {return m_it == other.m_it;}
inline DirectoryIterator& operator++() inline DirectoryIterator& operator++()
{ {
if (m_it->m_kind == NODE_DIRECTORY) if (m_it->m_kind == Kind::Directory)
m_it = m_it->rawEnd(); m_it = m_it->rawEnd();
else else
++m_it; ++m_it;
@ -151,7 +151,7 @@ public:
inline DirectoryIterator end() const {return DirectoryIterator(m_childrenEnd);} inline DirectoryIterator end() const {return DirectoryIterator(m_childrenEnd);}
inline DirectoryIterator find(const std::string& name) const inline DirectoryIterator find(const std::string& name) const
{ {
if (m_kind == NODE_DIRECTORY) if (m_kind == Kind::Directory)
{ {
DirectoryIterator it=begin(); DirectoryIterator it=begin();
for (; it != end() ; ++it) for (; it != end() ; ++it)
@ -235,14 +235,14 @@ public:
inline IPartition* getDataPartition() inline IPartition* getDataPartition()
{ {
for (const std::unique_ptr<IPartition>& part : m_partitions) for (const std::unique_ptr<IPartition>& part : m_partitions)
if (part->getKind() == IPartition::PART_DATA) if (part->getKind() == IPartition::Kind::Data)
return part.get(); return part.get();
return nullptr; return nullptr;
} }
inline IPartition* getUpdatePartition() inline IPartition* getUpdatePartition()
{ {
for (const std::unique_ptr<IPartition>& part : m_partitions) for (const std::unique_ptr<IPartition>& part : m_partitions)
if (part->getKind() == IPartition::PART_UPDATE) if (part->getKind() == IPartition::Kind::Update)
return part.get(); return part.get();
return nullptr; return nullptr;
} }

View File

@ -37,7 +37,7 @@ void DiscBase::IPartition::parseFST(IPartReadStream& s)
++it) ++it)
{ {
Node& node = *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_childrenBegin = it + 1;
node.m_childrenEnd = m_nodes.begin() + node.m_discLength; node.m_childrenEnd = m_nodes.begin() + node.m_discLength;
@ -66,7 +66,7 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
SystemStringView nameView(getName()); SystemStringView nameView(getName());
SystemString path = basePath + _S("/") + nameView.sys_str(); SystemString path = basePath + _S("/") + nameView.sys_str();
if (m_kind == NODE_DIRECTORY) if (m_kind == Kind::Directory)
{ {
if (ctx.verbose && ctx.progressCB && !getName().empty()) if (ctx.verbose && ctx.progressCB && !getName().empty())
ctx.progressCB(getName()); ctx.progressCB(getName());
@ -79,7 +79,7 @@ bool DiscBase::IPartition::Node::extractToDirectory(const SystemString& basePath
if (!subnode.extractToDirectory(path, ctx)) if (!subnode.extractToDirectory(path, ctx))
return false; return false;
} }
else if (m_kind == NODE_FILE) else if (m_kind == Kind::File)
{ {
Sstat theStat; Sstat theStat;
if (ctx.verbose && ctx.progressCB) if (ctx.verbose && ctx.progressCB)

View File

@ -106,7 +106,7 @@ DiscGCN::DiscGCN(std::unique_ptr<IDiscIO>&& dio)
: DiscBase(std::move(dio)) : DiscBase(std::move(dio))
{ {
/* One lone partition for GCN */ /* 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() bool DiscGCN::commit()

View File

@ -23,17 +23,17 @@ static const uint8_t COMMON_KEYS[2][16] =
class PartitionWii : public DiscBase::IPartition class PartitionWii : public DiscBase::IPartition
{ {
enum SigType : uint32_t enum class SigType : uint32_t
{ {
SRSA_4096 = 0x00010000, RSA_4096 = 0x00010000,
SRSA_2048 = 0x00010001, RSA_2048 = 0x00010001,
SELIPTICAL_CURVE = 0x00010002 ELIPTICAL_CURVE = 0x00010002
}; };
enum KeyType : uint32_t enum class KeyType : uint32_t
{ {
KRSA_4096 = 0x00000000, RSA_4096 = 0x00000000,
KRSA_2048 = 0x00000001 RSA_2048 = 0x00000001
}; };
struct Ticket struct Ticket
@ -124,7 +124,7 @@ class PartitionWii : public DiscBase::IPartition
void read(IDiscIO::IReadStream& s) void read(IDiscIO::IReadStream& s)
{ {
s.read(this, 484); s.read(this, 484);
sigType = (SigType)SBig(sigType); sigType = SigType(SBig(uint32_t(sigType)));
iosIdMajor = SBig(iosIdMajor); iosIdMajor = SBig(iosIdMajor);
iosIdMinor = SBig(iosIdMinor); iosIdMinor = SBig(iosIdMinor);
titleIdMajor = SBig(titleIdMajor); titleIdMajor = SBig(titleIdMajor);
@ -158,22 +158,22 @@ class PartitionWii : public DiscBase::IPartition
void read(IDiscIO::IReadStream& s) void read(IDiscIO::IReadStream& s)
{ {
s.read(&sigType, 4); s.read(&sigType, 4);
sigType = (SigType)SBig(sigType); sigType = SigType(SBig(uint32_t(sigType)));
if (sigType == SRSA_4096) if (sigType == SigType::RSA_4096)
s.read(sig, 512); s.read(sig, 512);
else if (sigType == SRSA_2048) else if (sigType == SigType::RSA_2048)
s.read(sig, 256); s.read(sig, 256);
else if (sigType == SELIPTICAL_CURVE) else if (sigType == SigType::ELIPTICAL_CURVE)
s.read(sig, 64); s.read(sig, 64);
s.seek(60, SEEK_CUR); s.seek(60, SEEK_CUR);
s.read(issuer, 64); s.read(issuer, 64);
s.read(&keyType, 4); s.read(&keyType, 4);
s.read(subject, 64); s.read(subject, 64);
keyType = (KeyType)SBig(keyType); keyType = KeyType(SBig(uint32_t(keyType)));
if (keyType == KRSA_4096) if (keyType == KeyType::RSA_4096)
s.read(key, 512); s.read(key, 512);
else if (keyType == KRSA_2048) else if (keyType == KeyType::RSA_2048)
s.read(key, 256); s.read(key, 256);
s.read(&modulus, 8); s.read(&modulus, 8);
@ -345,18 +345,14 @@ DiscWii::DiscWii(std::unique_ptr<IDiscIO>&& dio)
: DiscBase(std::move(dio)) : DiscBase(std::move(dio))
{ {
/* Read partition info */ /* Read partition info */
struct PartInfo { struct PartInfo
{
uint32_t partCount; uint32_t partCount;
uint32_t partInfoOff; uint32_t partInfoOff;
struct Part struct Part
{ {
uint32_t partDataOff; uint32_t partDataOff;
enum Type : uint32_t IPartition::Kind partType;
{
PART_DATA = 0,
PART_UPDATE = 1,
PART_CHANNEL = 2
} partType;
} parts[4]; } parts[4];
PartInfo(IDiscIO& dio) PartInfo(IDiscIO& dio)
{ {
@ -370,7 +366,7 @@ DiscWii::DiscWii(std::unique_ptr<IDiscIO>&& dio)
{ {
s->read(&parts[p], 8); s->read(&parts[p], 8);
parts[p].partDataOff = SBig(parts[p].partDataOff); 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); } partInfo(*m_discIO);
@ -380,15 +376,17 @@ DiscWii::DiscWii(std::unique_ptr<IDiscIO>&& dio)
for (uint32_t p=0 ; p<partInfo.partCount && p<4 ; ++p) for (uint32_t p=0 ; p<partInfo.partCount && p<4 ; ++p)
{ {
PartInfo::Part& part = partInfo.parts[p]; PartInfo::Part& part = partInfo.parts[p];
IPartition::Kind kind = IPartition::PART_DATA; IPartition::Kind kind;
if (part.partType == PartInfo::Part::PART_DATA) switch (part.partType)
kind = IPartition::PART_DATA; {
else if (part.partType == PartInfo::Part::PART_UPDATE) case IPartition::Kind::Data:
kind = IPartition::PART_UPDATE; case IPartition::Kind::Update:
else if (part.partType == PartInfo::Part::PART_CHANNEL) case IPartition::Kind::Channel:
kind = IPartition::PART_CHANNEL; kind = part.partType;
else break;
LogModule.report(LogVisor::FatalError, "invalid partition type %s", part.partType); default:
LogModule.report(LogVisor::FatalError, "invalid partition type %d", part.partType);
}
m_partitions.emplace_back(new PartitionWii(*this, kind, part.partDataOff << 2)); m_partitions.emplace_back(new PartitionWii(*this, kind, part.partDataOff << 2));
} }
} }