diff --git a/src/Linker/Linker.cpp b/src/Linker/Linker.cpp index c6d2940e..6c05aa65 100644 --- a/src/Linker/Linker.cpp +++ b/src/Linker/Linker.cpp @@ -613,9 +613,13 @@ public: bool Start(const int argc, const char** argv) override { - if (!m_args.ParseArgs(argc, argv)) + auto shouldContinue = true; + if (!m_args.ParseArgs(argc, argv, shouldContinue)) return false; + if (!shouldContinue) + return true; + if (!m_search_paths.BuildProjectIndependentSearchPaths()) return false; diff --git a/src/Linker/LinkerArgs.cpp b/src/Linker/LinkerArgs.cpp index a9b2d318..90320567 100644 --- a/src/Linker/LinkerArgs.cpp +++ b/src/Linker/LinkerArgs.cpp @@ -1,11 +1,13 @@ #include "LinkerArgs.h" +#include "GitVersion.h" #include "ObjLoading.h" #include "ObjWriting.h" #include "Utils/Arguments/UsageInformation.h" #include "Utils/FileUtils.h" #include +#include #include #include @@ -19,6 +21,12 @@ const CommandLineOption* const OPTION_HELP = .WithDescription("Displays usage information.") .Build(); +const CommandLineOption* const OPTION_VERSION = + CommandLineOption::Builder::Create() + .WithLongName("version") + .WithDescription("Prints the application version.") + .Build(); + const CommandLineOption* const OPTION_VERBOSE = CommandLineOption::Builder::Create() .WithShortName("v") @@ -88,6 +96,7 @@ const CommandLineOption* const OPTION_MENU_NO_OPTIMIZATION = const CommandLineOption* const COMMAND_LINE_OPTIONS[]{ OPTION_HELP, + OPTION_VERSION, OPTION_VERBOSE, OPTION_BASE_FOLDER, OPTION_OUTPUT_FOLDER, @@ -100,7 +109,7 @@ const CommandLineOption* const COMMAND_LINE_OPTIONS[]{ }; LinkerArgs::LinkerArgs() - : m_argument_parser(COMMAND_LINE_OPTIONS, std::extent::value), + : m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v), m_base_pattern(R"(\?base\?)"), m_game_pattern(R"(\?game\?)"), m_project_pattern(R"(\?project\?)"), @@ -125,6 +134,11 @@ void LinkerArgs::PrintUsage() usage.Print(); } +void LinkerArgs::PrintVersion() +{ + std::cout << "OpenAssetTools Linker " << std::string(GIT_VERSION) << "\n"; +} + void LinkerArgs::SetVerbose(const bool isVerbose) { m_verbose = isVerbose; @@ -198,8 +212,9 @@ std::set LinkerArgs::GetSearchPathsForProject(const std::set +#include + const CommandLineOption* const OPTION_HELP = CommandLineOption::Builder::Create().WithShortName("?").WithLongName("help").WithDescription("Displays usage information.").Build(); +const CommandLineOption* const OPTION_VERSION = + CommandLineOption::Builder::Create().WithLongName("version").WithDescription("Prints the application version.").Build(); + const CommandLineOption* const OPTION_VERBOSE = CommandLineOption::Builder::Create().WithShortName("v").WithLongName("verbose").WithDescription("Outputs a lot more and more detailed messages.").Build(); @@ -30,7 +37,14 @@ const CommandLineOption* const OPTION_DEFINE = CommandLineOption::Builder::Creat .Reusable() .Build(); -const CommandLineOption* const COMMAND_LINE_OPTIONS[]{OPTION_HELP, OPTION_VERBOSE, OPTION_OUTPUT_FOLDER, OPTION_BUILD_LOG, OPTION_DEFINE}; +const CommandLineOption* const COMMAND_LINE_OPTIONS[]{ + OPTION_HELP, + OPTION_VERSION, + OPTION_VERBOSE, + OPTION_OUTPUT_FOLDER, + OPTION_BUILD_LOG, + OPTION_DEFINE, +}; RawTemplaterArguments::RawTemplaterArguments() : m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v), @@ -50,8 +64,14 @@ void RawTemplaterArguments::PrintUsage() usage.Print(); } -bool RawTemplaterArguments::Parse(const int argc, const char** argv) +void RawTemplaterArguments::PrintVersion() { + std::cout << "OpenAssetTools RawTemplater " << std::string(GIT_VERSION) << "\n"; +} + +bool RawTemplaterArguments::ParseArgs(const int argc, const char** argv, bool& shouldContinue) +{ + shouldContinue = true; if (!m_argument_parser.ParseArguments(argc - 1, &argv[1])) { PrintUsage(); @@ -65,6 +85,14 @@ bool RawTemplaterArguments::Parse(const int argc, const char** argv) return false; } + // Check if the user wants to see the version + if (m_argument_parser.IsOptionSpecified(OPTION_VERSION)) + { + PrintVersion(); + shouldContinue = false; + return true; + } + m_input_files = m_argument_parser.GetArguments(); if (m_input_files.empty()) { diff --git a/src/RawTemplater/RawTemplaterArguments.h b/src/RawTemplater/RawTemplaterArguments.h index 463ccbc6..dadb1f88 100644 --- a/src/RawTemplater/RawTemplaterArguments.h +++ b/src/RawTemplater/RawTemplaterArguments.h @@ -14,6 +14,7 @@ class RawTemplaterArguments * \brief Prints a command line usage help text for the RawTemplater tool to stdout. */ static void PrintUsage(); + static void PrintVersion(); public: bool m_verbose; @@ -27,5 +28,5 @@ public: RawTemplaterArguments(); - bool Parse(int argc, const char** argv); + bool ParseArgs(int argc, const char** argv, bool& shouldContinue); }; diff --git a/src/Unlinker/Unlinker.cpp b/src/Unlinker/Unlinker.cpp index 2abcf354..f26cc12d 100644 --- a/src/Unlinker/Unlinker.cpp +++ b/src/Unlinker/Unlinker.cpp @@ -429,9 +429,13 @@ public: */ bool Start(const int argc, const char** argv) { - if (!m_args.ParseArgs(argc, argv)) + auto shouldContinue = true; + if (!m_args.ParseArgs(argc, argv, shouldContinue)) return false; + if (!shouldContinue) + return true; + if (!BuildSearchPaths()) return false; diff --git a/src/Unlinker/UnlinkerArgs.cpp b/src/Unlinker/UnlinkerArgs.cpp index 5c7bfaa0..79c1a181 100644 --- a/src/Unlinker/UnlinkerArgs.cpp +++ b/src/Unlinker/UnlinkerArgs.cpp @@ -1,10 +1,12 @@ #include "UnlinkerArgs.h" +#include "GitVersion.h" #include "ObjLoading.h" #include "ObjWriting.h" #include "Utils/Arguments/UsageInformation.h" #include "Utils/FileUtils.h" +#include #include #include @@ -16,6 +18,12 @@ const CommandLineOption* const OPTION_HELP = .WithDescription("Displays usage information.") .Build(); +const CommandLineOption* const OPTION_VERSION = + CommandLineOption::Builder::Create() + .WithLongName("version") + .WithDescription("Prints the application version.") + .Build(); + const CommandLineOption* const OPTION_VERBOSE = CommandLineOption::Builder::Create() .WithShortName("v") @@ -113,6 +121,7 @@ const CommandLineOption* const OPTION_LEGACY_MENUS = const CommandLineOption* const COMMAND_LINE_OPTIONS[]{ OPTION_HELP, + OPTION_VERSION, OPTION_VERBOSE, OPTION_MINIMAL_ZONE_FILE, OPTION_LOAD, @@ -155,6 +164,11 @@ void UnlinkerArgs::PrintUsage() usage.Print(); } +void UnlinkerArgs::PrintVersion() +{ + std::cout << "OpenAssetTools Unlinker " << std::string(GIT_VERSION) << "\n"; +} + void UnlinkerArgs::SetVerbose(const bool isVerbose) { m_verbose = isVerbose; @@ -237,8 +251,9 @@ void UnlinkerArgs::ParseCommaSeparatedAssetTypeString(const std::string& input) AddSpecifiedAssetType(std::string(lowerInput, currentPos, lowerInput.size() - currentPos)); } -bool UnlinkerArgs::ParseArgs(const int argc, const char** argv) +bool UnlinkerArgs::ParseArgs(const int argc, const char** argv, bool& shouldContinue) { + shouldContinue = true; if (!m_argument_parser.ParseArguments(argc - 1, &argv[1])) { PrintUsage(); @@ -252,6 +267,14 @@ bool UnlinkerArgs::ParseArgs(const int argc, const char** argv) return false; } + // Check if the user wants to see the version + if (m_argument_parser.IsOptionSpecified(OPTION_VERSION)) + { + PrintVersion(); + shouldContinue = false; + return true; + } + m_zones_to_unlink = m_argument_parser.GetArguments(); const size_t zoneCount = m_zones_to_unlink.size(); if (zoneCount < 1) diff --git a/src/Unlinker/UnlinkerArgs.h b/src/Unlinker/UnlinkerArgs.h index d26dca94..35872566 100644 --- a/src/Unlinker/UnlinkerArgs.h +++ b/src/Unlinker/UnlinkerArgs.h @@ -21,6 +21,7 @@ private: * \brief Prints a command line usage help text for the Unlinker tool to stdout. */ static void PrintUsage(); + static void PrintVersion(); void SetVerbose(bool isVerbose); bool SetImageDumpingMode(); @@ -60,7 +61,7 @@ public: bool m_verbose; UnlinkerArgs(); - bool ParseArgs(int argc, const char** argv); + bool ParseArgs(int argc, const char** argv, bool& shouldContinue); /** * \brief Converts the output path specified by command line arguments to a path applies for the specified zone. diff --git a/src/ZoneCodeGeneratorLib/ZoneCodeGenerator.cpp b/src/ZoneCodeGeneratorLib/ZoneCodeGenerator.cpp index b6b7a594..cdfcc209 100644 --- a/src/ZoneCodeGeneratorLib/ZoneCodeGenerator.cpp +++ b/src/ZoneCodeGeneratorLib/ZoneCodeGenerator.cpp @@ -64,9 +64,13 @@ public: int Run(const int argc, const char** argv) { - if (!m_args.Parse(argc, argv)) + auto shouldContinue = true; + if (!m_args.ParseArgs(argc, argv, shouldContinue)) return 1; + if (!shouldContinue) + return 0; + if (!ReadHeaderData() || !ReadCommandsData()) return 1; diff --git a/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.cpp b/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.cpp index 9f30103b..c2e1b737 100644 --- a/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.cpp +++ b/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.cpp @@ -1,5 +1,6 @@ #include "ZoneCodeGeneratorArguments.h" +#include "GitVersion.h" #include "Utils/Arguments/CommandLineOption.h" #include "Utils/Arguments/UsageInformation.h" @@ -9,6 +10,9 @@ const CommandLineOption* const OPTION_HELP = CommandLineOption::Builder::Create().WithShortName("?").WithLongName("help").WithDescription("Displays usage information.").Build(); +const CommandLineOption* const OPTION_VERSION = + CommandLineOption::Builder::Create().WithLongName("version").WithDescription("Prints the application version.").Build(); + const CommandLineOption* const OPTION_VERBOSE = CommandLineOption::Builder::Create().WithShortName("v").WithLongName("verbose").WithDescription("Outputs a lot more and more detailed messages.").Build(); @@ -70,7 +74,15 @@ const CommandLineOption* const OPTION_GENERATE = .Build(); const CommandLineOption* const COMMAND_LINE_OPTIONS[]{ - OPTION_HELP, OPTION_VERBOSE, OPTION_HEADER, OPTION_COMMANDS_FILE, OPTION_OUTPUT_FOLDER, OPTION_PRINT, OPTION_GENERATE}; + OPTION_HELP, + OPTION_VERSION, + OPTION_VERBOSE, + OPTION_HEADER, + OPTION_COMMANDS_FILE, + OPTION_OUTPUT_FOLDER, + OPTION_PRINT, + OPTION_GENERATE, +}; ZoneCodeGeneratorArguments::GenerationTask::GenerationTask() : m_all_assets(false) @@ -91,7 +103,7 @@ ZoneCodeGeneratorArguments::GenerationTask::GenerationTask(std::string assetName } ZoneCodeGeneratorArguments::ZoneCodeGeneratorArguments() - : m_argument_parser(COMMAND_LINE_OPTIONS, std::extent::value), + : m_argument_parser(COMMAND_LINE_OPTIONS, std::extent_v), m_task_flags(0) { m_verbose = false; @@ -109,8 +121,14 @@ void ZoneCodeGeneratorArguments::PrintUsage() usage.Print(); } -bool ZoneCodeGeneratorArguments::Parse(const int argc, const char** argv) +void ZoneCodeGeneratorArguments::PrintVersion() { + std::cout << "OpenAssetTools ZoneCodeGenerator " << std::string(GIT_VERSION) << "\n"; +} + +bool ZoneCodeGeneratorArguments::ParseArgs(const int argc, const char** argv, bool& shouldContinue) +{ + shouldContinue = true; if (!m_argument_parser.ParseArguments(argc - 1, &argv[1])) { PrintUsage(); @@ -124,6 +142,14 @@ bool ZoneCodeGeneratorArguments::Parse(const int argc, const char** argv) return false; } + // Check if the user wants to see the version + if (m_argument_parser.IsOptionSpecified(OPTION_VERSION)) + { + PrintVersion(); + shouldContinue = false; + return true; + } + // -v; --verbose m_verbose = m_argument_parser.IsOptionSpecified(OPTION_VERBOSE); diff --git a/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.h b/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.h index 1344d2af..351efc2e 100644 --- a/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.h +++ b/src/ZoneCodeGeneratorLib/ZoneCodeGeneratorArguments.h @@ -13,6 +13,7 @@ class ZoneCodeGeneratorArguments * \brief Prints a command line usage help text for the Unlinker tool to stdout. */ static void PrintUsage(); + static void PrintVersion(); public: static constexpr unsigned FLAG_TASK_GENERATE = 1 << 0; @@ -40,8 +41,7 @@ public: std::vector m_generation_tasks; ZoneCodeGeneratorArguments(); - - bool Parse(int argc, const char** argv); + bool ParseArgs(int argc, const char** argv, bool& shouldContinue); _NODISCARD bool ShouldGenerate() const; _NODISCARD bool ShouldPrint() const;