diff --git a/src/Bin/LodTool/LodTool.cpp b/src/Bin/LodTool/LodTool.cpp index 5b5011dc843c..74ae79126f36 100644 --- a/src/Bin/LodTool/LodTool.cpp +++ b/src/Bin/LodTool/LodTool.cpp @@ -1,5 +1,6 @@ #include "LodToolOptions.h" +#include "Library/Cli/CliUtf8fy.h" #include "Library/Lod/LodReader.h" #include "Library/LodFormats/LodFormats.h" #include "Library/Serialization/Serialization.h" @@ -41,6 +42,7 @@ int runDump(const LodToolOptions &options) { int main(int argc, char **argv) { try { + CliUtf8fy _(argc, argv); LodToolOptions options = LodToolOptions::parse(argc, argv); if (options.helpPrinted) return 1; diff --git a/src/Library/Cli/CMakeLists.txt b/src/Library/Cli/CMakeLists.txt index 4b719c5aa91d..ced8077fdeb5 100644 --- a/src/Library/Cli/CMakeLists.txt +++ b/src/Library/Cli/CMakeLists.txt @@ -4,7 +4,8 @@ set(LIBRARY_CLI_SOURCES CliApp.cpp) set(LIBRARY_CLI_HEADERS - CliApp.h) + CliApp.h + CliUtf8fy.h) add_library(library_cli ${LIBRARY_CLI_SOURCES} ${LIBRARY_CLI_HEADERS}) target_link_libraries(library_cli CLI11::CLI11) diff --git a/src/Library/Cli/CliUtf8fy.h b/src/Library/Cli/CliUtf8fy.h new file mode 100644 index 000000000000..7ac1a9a0dc64 --- /dev/null +++ b/src/Library/Cli/CliUtf8fy.h @@ -0,0 +1,35 @@ +#pragma once + +#include + +#include + +/** + * Utility class that converts program arguments to utf-8 on Windows, and does nothing on POSIX. + * + * Use it like this: + * ``` + * int main(int argc, char **argv) { + * try { + * CliUtf8fy _(argc, argv); + * // Use argc & argv here. + * } catch (...) { + * // Your error processing here. + * } + * } + * ``` + * + * Note that while `CliUtf8fy` constructor shouldn't normally throw, it can theoretically throw. + * + * Also note that `CliUtf8fy` is only needed if the program isn't using `platformMain`. + */ +class CliUtf8fy { + public: + CliUtf8fy(int /*argc*/, char **&argv) { + _app = std::make_unique(); + argv = _app->ensure_utf8(argv); + } + + private: + std::unique_ptr _app; +};