AtomicTool.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include <Atomic/Core/ProcessUtils.h>
  2. #include <Atomic/IO/Log.h>
  3. #include <Atomic/Engine/Engine.h>
  4. #include <ToolCore/ToolSystem.h>
  5. #include <ToolCore/License/LicenseSystem.h>
  6. #include <ToolCore/Command/Command.h>
  7. #include <ToolCore/Command/CommandParser.h>
  8. #include "AtomicTool.h"
  9. using namespace ToolCore;
  10. DEFINE_APPLICATION_MAIN(AtomicTool::AtomicTool);
  11. namespace AtomicTool
  12. {
  13. AtomicTool::AtomicTool(Context* context) :
  14. Application(context)
  15. {
  16. }
  17. AtomicTool::~AtomicTool()
  18. {
  19. }
  20. void AtomicTool::Setup()
  21. {
  22. const Vector<String>& arguments = GetArguments();
  23. for (unsigned i = 0; i < arguments.Size(); ++i)
  24. {
  25. if (arguments[i].Length() > 1)
  26. {
  27. String argument = arguments[i].ToLower();
  28. String value = i + 1 < arguments.Size() ? arguments[i + 1] : String::EMPTY;
  29. if (argument == "--cli-data-path")
  30. {
  31. if (!value.Length())
  32. ErrorExit("Unable to parse --cli-data-path");
  33. cliDataPath_ = value;
  34. }
  35. }
  36. }
  37. if (!cliDataPath_.Length())
  38. ErrorExit("Unable to parse --data-path");
  39. engineParameters_["Headless"] = true;
  40. engineParameters_["ResourcePaths"] = "";
  41. }
  42. void AtomicTool::HandleCommandFinished(StringHash eventType, VariantMap& eventData)
  43. {
  44. GetSubsystem<Engine>()->Exit();
  45. }
  46. void AtomicTool::HandleCommandError(StringHash eventType, VariantMap& eventData)
  47. {
  48. String error = "Command Error";
  49. const String& message = eventData[CommandError::P_MESSAGE].ToString();
  50. if (message.Length())
  51. error = message;
  52. ErrorExit(error);
  53. }
  54. void AtomicTool::Start()
  55. {
  56. // Subscribe to events
  57. SubscribeToEvent(E_COMMANDERROR, HANDLER(AtomicTool, HandleCommandError));
  58. SubscribeToEvent(E_COMMANDFINISHED, HANDLER(AtomicTool, HandleCommandFinished));
  59. const Vector<String>& arguments = GetArguments();
  60. ToolSystem* tsystem = new ToolSystem(context_);
  61. context_->RegisterSubsystem(tsystem);
  62. tsystem->SetDataPath(cliDataPath_);
  63. SharedPtr<CommandParser> parser(new CommandParser(context_));
  64. SharedPtr<Command> cmd(parser->Parse(arguments));
  65. if (!cmd)
  66. {
  67. String error = "No command found";
  68. if (parser->GetErrorMessage().Length())
  69. error = parser->GetErrorMessage();
  70. ErrorExit(error);
  71. }
  72. // BEGIN LICENSE MANAGEMENT
  73. GetSubsystem<LicenseSystem>()->Initialize();
  74. // END LICENSE MANAGEMENT
  75. cmd->Run();
  76. }
  77. void AtomicTool::Stop()
  78. {
  79. }
  80. }