From cc9f9b53bafaaecaf9d3bf961e64cb4c31a8987b Mon Sep 17 00:00:00 2001 From: elsid Date: Tue, 30 Jan 2024 01:29:38 +0100 Subject: [PATCH] Convert BsaVersion to enum class --- apps/bsatool/bsatool.cpp | 16 +++++++++------- apps/launcher/datafilespage.cpp | 2 +- components/bsa/bsa_file.cpp | 18 +++++++++--------- components/bsa/bsa_file.hpp | 12 ++++++------ components/bsa/compressedbsafile.cpp | 2 +- components/vfs/bsaarchive.hpp | 10 +++++----- 6 files changed, 31 insertions(+), 29 deletions(-) diff --git a/apps/bsatool/bsatool.cpp b/apps/bsatool/bsatool.cpp index 28711df929..171e5606c4 100644 --- a/apps/bsatool/bsatool.cpp +++ b/apps/bsatool/bsatool.cpp @@ -329,17 +329,19 @@ int main(int argc, char** argv) switch (bsaVersion) { - case Bsa::BSAVER_COMPRESSED: + case Bsa::BsaVersion::Unknown: + break; + case Bsa::BsaVersion::Uncompressed: + return call(info); + case Bsa::BsaVersion::Compressed: return call(info); - case Bsa::BSAVER_BA2_GNRL: + case Bsa::BsaVersion::BA2GNRL: return call(info); - case Bsa::BSAVER_BA2_DX10: + case Bsa::BsaVersion::BA2DX10: return call(info); - case Bsa::BSAVER_UNCOMPRESSED: - return call(info); - default: - throw std::runtime_error("Unrecognised BSA archive"); } + + throw std::runtime_error("Unrecognised BSA archive"); } catch (std::exception& e) { diff --git a/apps/launcher/datafilespage.cpp b/apps/launcher/datafilespage.cpp index 9b14a91934..92b86e9cec 100644 --- a/apps/launcher/datafilespage.cpp +++ b/apps/launcher/datafilespage.cpp @@ -819,7 +819,7 @@ void Launcher::DataFilesPage::addArchivesFromDir(const QString& path) for (const auto& fileinfo : dir.entryInfoList(archiveFilter)) { const auto absPath = fileinfo.absoluteFilePath(); - if (Bsa::BSAFile::detectVersion(Files::pathFromQString(absPath)) == Bsa::BSAVER_UNKNOWN) + if (Bsa::BSAFile::detectVersion(Files::pathFromQString(absPath)) == Bsa::BsaVersion::Unknown) continue; const auto fileName = fileinfo.fileName(); diff --git a/components/bsa/bsa_file.cpp b/components/bsa/bsa_file.cpp index b3e24c75ab..c8b0021152 100644 --- a/components/bsa/bsa_file.cpp +++ b/components/bsa/bsa_file.cpp @@ -335,7 +335,7 @@ BsaVersion Bsa::BSAFile::detectVersion(const std::filesystem::path& filePath) if (fsize < 12) { - return BSAVER_UNKNOWN; + return BsaVersion::Unknown; } // Get essential header numbers @@ -345,23 +345,23 @@ BsaVersion Bsa::BSAFile::detectVersion(const std::filesystem::path& filePath) input.read(reinterpret_cast(head), 12); - if (head[0] == static_cast(BSAVER_UNCOMPRESSED)) + if (head[0] == static_cast(BsaVersion::Uncompressed)) { - return BSAVER_UNCOMPRESSED; + return BsaVersion::Uncompressed; } - if (head[0] == static_cast(BSAVER_COMPRESSED) || head[0] == ESM::fourCC("BTDX")) + if (head[0] == static_cast(BsaVersion::Compressed) || head[0] == ESM::fourCC("BTDX")) { if (head[1] == static_cast(0x01)) { if (head[2] == ESM::fourCC("GNRL")) - return BSAVER_BA2_GNRL; + return BsaVersion::BA2GNRL; if (head[2] == ESM::fourCC("DX10")) - return BSAVER_BA2_DX10; - return BSAVER_UNKNOWN; + return BsaVersion::BA2DX10; + return BsaVersion::Unknown; } - return BSAVER_COMPRESSED; + return BsaVersion::Compressed; } - return BSAVER_UNKNOWN; + return BsaVersion::Unknown; } diff --git a/components/bsa/bsa_file.hpp b/components/bsa/bsa_file.hpp index 8a953245d2..03a0703885 100644 --- a/components/bsa/bsa_file.hpp +++ b/components/bsa/bsa_file.hpp @@ -35,13 +35,13 @@ namespace Bsa { - enum BsaVersion + enum class BsaVersion : std::uint32_t { - BSAVER_UNKNOWN = 0x0, - BSAVER_UNCOMPRESSED = 0x100, - BSAVER_COMPRESSED = 0x415342, // B, S, A, - BSAVER_BA2_GNRL, // used by FO4, BSA which contains files - BSAVER_BA2_DX10 // used by FO4, BSA which contains textures + Unknown = 0x0, + Uncompressed = 0x100, + Compressed = 0x415342, // B, S, A, + BA2GNRL, // used by FO4, BSA which contains files + BA2DX10 // used by FO4, BSA which contains textures }; /** diff --git a/components/bsa/compressedbsafile.cpp b/components/bsa/compressedbsafile.cpp index b916de7919..99efe7a587 100644 --- a/components/bsa/compressedbsafile.cpp +++ b/components/bsa/compressedbsafile.cpp @@ -70,7 +70,7 @@ namespace Bsa input.read(reinterpret_cast(&mHeader), sizeof(mHeader)); - if (mHeader.mFormat != BSAVER_COMPRESSED) // BSA + if (mHeader.mFormat != static_cast(BsaVersion::Compressed)) // BSA fail("Unrecognized compressed BSA format"); if (mHeader.mVersion != Version_TES4 && mHeader.mVersion != Version_FO3 && mHeader.mVersion != Version_SSE) fail("Unrecognized compressed BSA version"); diff --git a/components/vfs/bsaarchive.hpp b/components/vfs/bsaarchive.hpp index 83a68a0589..9418cce745 100644 --- a/components/vfs/bsaarchive.hpp +++ b/components/vfs/bsaarchive.hpp @@ -79,15 +79,15 @@ namespace VFS { switch (Bsa::BSAFile::detectVersion(path)) { - case Bsa::BSAVER_UNKNOWN: + case Bsa::BsaVersion::Unknown: break; - case Bsa::BSAVER_UNCOMPRESSED: + case Bsa::BsaVersion::Uncompressed: return std::make_unique>(path); - case Bsa::BSAVER_COMPRESSED: + case Bsa::BsaVersion::Compressed: return std::make_unique>(path); - case Bsa::BSAVER_BA2_GNRL: + case Bsa::BsaVersion::BA2GNRL: return std::make_unique>(path); - case Bsa::BSAVER_BA2_DX10: + case Bsa::BsaVersion::BA2DX10: return std::make_unique>(path); }