NewProjectCmd.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #include <Atomic/Core/StringUtils.h>
  8. #include <Atomic/IO/Log.h>
  9. #include <Atomic/IO/File.h>
  10. #include "../ToolSystem.h"
  11. #include "../Project/ProjectFile.h"
  12. #include "NewProjectCmd.h"
  13. #include <Poco/File.h>
  14. namespace ToolCore
  15. {
  16. NewProjectCmd::NewProjectCmd(Context* context) : Command(context)
  17. {
  18. }
  19. NewProjectCmd::~NewProjectCmd()
  20. {
  21. }
  22. bool NewProjectCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
  23. {
  24. String argument = arguments[startIndex].ToLower();
  25. String value = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;
  26. if (argument != "new")
  27. {
  28. errorMsg = "Unable to parse new command";
  29. return false;
  30. }
  31. if (!value.Length())
  32. {
  33. errorMsg = "Unable to parse new project path";
  34. return false;
  35. }
  36. projectPath_ = value;
  37. return true;
  38. }
  39. void NewProjectCmd::Run()
  40. {
  41. Poco::File projectDest(projectPath_.CString());
  42. if (projectDest.exists())
  43. {
  44. Error(ToString("New project path: %s already exists", projectPath_.CString()));
  45. return;
  46. }
  47. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  48. String templateDir = tsystem->GetDataPath();
  49. templateDir += "ProjectTemplates/Project2D/Resources";
  50. Poco::File projectSrc(templateDir.CString());
  51. if (!projectSrc.exists() || !projectSrc.isDirectory())
  52. {
  53. Error(ToString("New project path: %s source does not exist", templateDir.CString()));
  54. return;
  55. }
  56. LOGINFOF("Creating new project in: %s", projectPath_.CString());
  57. projectDest.createDirectory();
  58. projectSrc.copyTo((projectPath_ + "/Resources").CString());
  59. String filename("NewProject");
  60. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  61. pfile->WriteNewProject(projectPath_ + "/" + filename + ".atomic");
  62. Finished();
  63. }
  64. }