PlatformAddCmd.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #include <Atomic/Core/StringUtils.h>
  2. #include <Atomic/IO/Log.h>
  3. #include <Atomic/IO/File.h>
  4. #include "../ToolSystem.h"
  5. #include "../Project/Project.h"
  6. #include "PlatformAddCmd.h"
  7. #include <Poco/File.h>
  8. namespace ToolCore
  9. {
  10. PlatformAddCmd::PlatformAddCmd(Context* context) : Command(context)
  11. {
  12. }
  13. PlatformAddCmd::~PlatformAddCmd()
  14. {
  15. }
  16. bool PlatformAddCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
  17. {
  18. String argument = arguments[startIndex].ToLower();
  19. String value = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;
  20. if (argument != "platform-add")
  21. {
  22. errorMsg = "Unable to parse build command";
  23. return false;
  24. }
  25. if (!value.Length())
  26. {
  27. errorMsg = "Unable to parse platform";
  28. return false;
  29. }
  30. platformToAdd_ = value.ToLower();
  31. return true;
  32. }
  33. void PlatformAddCmd::Run()
  34. {
  35. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  36. Project* project = tsystem->GetProject();
  37. Platform* platform = tsystem->GetPlatformByName(platformToAdd_);
  38. if (!platform)
  39. {
  40. Error(ToString("Unknown platform: %s", platformToAdd_.CString()));
  41. return;
  42. }
  43. if (project->ContainsPlatform(platform->GetPlatformID()))
  44. {
  45. Error(ToString("Project already contains platform: %s", platformToAdd_.CString()));
  46. return;
  47. }
  48. LOGINFOF("Adding platform: %s", platformToAdd_.CString());
  49. project->AddPlatform(platform->GetPlatformID());
  50. Finished();
  51. }
  52. }