| 1 | // Copyright 2021 Dolphin Emulator Project |
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | |
| 4 | #include <cstdlib> |
| 5 | #include <iostream> |
| 6 | #include <string> |
| 7 | #include <string_view> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include <fmt/ostream.h> |
| 11 | |
| 12 | #include "DolphinTool/ConvertCommand.h" |
| 13 | #include "DolphinTool/ExtractCommand.h" |
| 14 | #include "DolphinTool/HeaderCommand.h" |
| 15 | #include "DolphinTool/VerifyCommand.h" |
| 16 | |
| 17 | #ifdef _WIN32 |
| 18 | #include "Common/StringUtil.h" |
| 19 | #endif |
| 20 | |
| 21 | static void PrintUsage() |
| 22 | { |
| 23 | fmt::print(std::cerr, "usage: dolphin-tool COMMAND -h\n" |
| 24 | "\n" |
| 25 | "commands supported: [convert, verify, header, extract]\n"); |
| 26 | } |
| 27 | |
| 28 | #ifdef _WIN32 |
| 29 | #define main app_main |
| 30 | #endif |
| 31 | |
| 32 | int main(int argc, char* argv[]) |
| 33 | { |
| 34 | if (argc < 2) |
| 35 | { |
| 36 | PrintUsage(); |
| 37 | return EXIT_FAILURE; |
| 38 | } |
| 39 | |
| 40 | const std::string_view command_str = argv[1]; |
| 41 | // Take off the program name and command selector before passing arguments down |
| 42 | const std::vector<std::string> args(argv + 2, argv + argc); |
| 43 | |
| 44 | if (command_str == "convert") |
| 45 | return DolphinTool::ConvertCommand(args); |
| 46 | else if (command_str == "verify") |
| 47 | return DolphinTool::VerifyCommand(args); |
| 48 | else if (command_str == "header") |
| 49 | return DolphinTool::HeaderCommand(args); |
| 50 | else if (command_str == "extract") |
| 51 | return DolphinTool::Extract(args); |
| 52 | PrintUsage(); |
| 53 | return EXIT_FAILURE; |
| 54 | } |
| 55 | |
| 56 | #ifdef _WIN32 |
| 57 | int wmain(int, wchar_t*[], wchar_t*[]) |
| 58 | { |
| 59 | std::vector<std::string> args = Common::CommandLineToUtf8Argv(GetCommandLineW()); |
| 60 | const int argc = static_cast<int>(args.size()); |
| 61 | std::vector<char*> argv(args.size()); |
| 62 | for (size_t i = 0; i < args.size(); ++i) |
| 63 | argv[i] = args[i].data(); |
| 64 | |
| 65 | return main(argc, argv.data()); |
| 66 | } |
| 67 | |
| 68 | #undef main |
| 69 | #endif |