ToolMain.cpp 1.7 KB

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