NewProjectCmd.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <Atomic/Core/StringUtils.h>
  2. #include <Atomic/IO/Log.h>
  3. #include <Atomic/IO/File.h>
  4. #include "../ToolSystem.h"
  5. #include "NewProjectCmd.h"
  6. #include <Poco/File.h>
  7. namespace ToolCore
  8. {
  9. NewProjectCmd::NewProjectCmd(Context* context) : Command(context)
  10. {
  11. }
  12. NewProjectCmd::~NewProjectCmd()
  13. {
  14. }
  15. bool NewProjectCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
  16. {
  17. String argument = arguments[startIndex].ToLower();
  18. String value = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;
  19. if (argument != "new")
  20. {
  21. errorMsg = "Unable to parse new command";
  22. return false;
  23. }
  24. if (!value.Length())
  25. {
  26. errorMsg = "Unable to parse new project path";
  27. return false;
  28. }
  29. projectPath_ = value;
  30. return true;
  31. }
  32. void NewProjectCmd::Run()
  33. {
  34. Poco::File projectDest(projectPath_.CString());
  35. if (projectDest.exists())
  36. {
  37. Error(ToString("New project path: %s already exists", projectPath_.CString()));
  38. return;
  39. }
  40. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  41. String templateDir = tsystem->GetDataPath();
  42. templateDir += "/Atomic/ProjectTemplates/Project2D/Resources";
  43. Poco::File projectSrc(templateDir.CString());
  44. if (!projectSrc.exists() || !projectSrc.isDirectory())
  45. {
  46. Error(ToString("New project path: %s source does not exist", templateDir.CString()));
  47. return;
  48. }
  49. LOGINFOF("Creating new project in: %s", projectPath_.CString());
  50. projectDest.createDirectory();
  51. projectSrc.copyTo((projectPath_ + "/Resources").CString());
  52. String filename("NewProject");
  53. File file(context_, projectPath_ + "/" + filename + ".atomic", FILE_WRITE);
  54. file.Close();
  55. Finished();
  56. }
  57. }