NewProjectCmd.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/ProjectFile.h"
  6. #include "NewProjectCmd.h"
  7. #include <Poco/File.h>
  8. namespace ToolCore
  9. {
  10. NewProjectCmd::NewProjectCmd(Context* context) : Command(context)
  11. {
  12. }
  13. NewProjectCmd::~NewProjectCmd()
  14. {
  15. }
  16. bool NewProjectCmd::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 != "new")
  21. {
  22. errorMsg = "Unable to parse new command";
  23. return false;
  24. }
  25. if (!value.Length())
  26. {
  27. errorMsg = "Unable to parse new project path";
  28. return false;
  29. }
  30. projectPath_ = value;
  31. return true;
  32. }
  33. void NewProjectCmd::Run()
  34. {
  35. Poco::File projectDest(projectPath_.CString());
  36. if (projectDest.exists())
  37. {
  38. Error(ToString("New project path: %s already exists", projectPath_.CString()));
  39. return;
  40. }
  41. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  42. String templateDir = tsystem->GetDataPath();
  43. templateDir += "ProjectTemplates/Project2D/Resources";
  44. Poco::File projectSrc(templateDir.CString());
  45. if (!projectSrc.exists() || !projectSrc.isDirectory())
  46. {
  47. Error(ToString("New project path: %s source does not exist", templateDir.CString()));
  48. return;
  49. }
  50. LOGINFOF("Creating new project in: %s", projectPath_.CString());
  51. projectDest.createDirectory();
  52. projectSrc.copyTo((projectPath_ + "/Resources").CString());
  53. String filename("NewProject");
  54. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  55. pfile->WriteNewProject(projectPath_ + "/" + filename + ".atomic");
  56. Finished();
  57. }
  58. }