Project.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include <rapidjson/document.h>
  5. #include <rapidjson/filestream.h>
  6. #include <rapidjson/prettywriter.h>
  7. #include <Atomic/IO/Log.h>
  8. #include <Atomic/IO/File.h>
  9. #include <Atomic/Resource/JSONFile.h>
  10. #include "../ToolSystem.h"
  11. #include "../Platform/Platform.h"
  12. #include "ProjectFile.h"
  13. #include "ProjectBuildSettings.h"
  14. #include "ProjectUserPrefs.h"
  15. #include "Project.h"
  16. using namespace rapidjson;
  17. namespace ToolCore
  18. {
  19. Project::Project(Context* context) :
  20. Object(context),
  21. loading_(false),
  22. dirty_(false)
  23. {
  24. version_ = "1.0.0";
  25. userPrefs_ = new ProjectUserPrefs(context_);
  26. buildSettings_ = new ProjectBuildSettings(context_);
  27. }
  28. Project::~Project()
  29. {
  30. }
  31. void Project::SaveUserPrefs()
  32. {
  33. }
  34. bool Project::LoadUserPrefs()
  35. {
  36. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  37. // If we're in CLI mode, the Build folder is always relative to project
  38. if (tsystem->IsCLI())
  39. {
  40. String path = GetPath(projectFilePath_) + "Build";
  41. userPrefs_->SetLastBuildPath(path);
  42. }
  43. return true;
  44. }
  45. void Project::SaveBuildSettings()
  46. {
  47. }
  48. bool Project::LoadBuildSettings()
  49. {
  50. return true;
  51. }
  52. void Project::AddPlatform(PlatformID platformID)
  53. {
  54. if (ContainsPlatform(platformID))
  55. return;
  56. SetDirty();
  57. platforms_.Push(platformID);
  58. }
  59. void Project::RemovePlatform(PlatformID platformID)
  60. {
  61. if (!ContainsPlatform(platformID))
  62. return;
  63. }
  64. bool Project::ContainsPlatform(PlatformID platformID)
  65. {
  66. for (List<PlatformID>::ConstIterator i = platforms_.Begin(); i != platforms_.End(); ++i)
  67. {
  68. if ((*i) == platformID)
  69. return true;
  70. }
  71. return false;
  72. }
  73. bool Project::Load(const String& fullpath)
  74. {
  75. loading_ = true;
  76. projectPath_ = GetPath(fullpath);
  77. projectFilePath_ = fullpath;
  78. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  79. bool result = pfile->Load(this);
  80. loading_ = false;
  81. LoadBuildSettings();
  82. LoadUserPrefs();
  83. return result;
  84. }
  85. String Project::GetBuildSettingsFullPath()
  86. {
  87. String path = GetPath(projectFilePath_);
  88. String filename = GetFileName(projectFilePath_);
  89. String buildSettingsPath = path + filename + ".buildsettings";
  90. return buildSettingsPath;
  91. }
  92. String Project::GetUserPrefsFullPath()
  93. {
  94. String path = GetPath(projectFilePath_);
  95. String filename = GetFileName(projectFilePath_);
  96. String prefsPath = path + filename + ".userprefs";
  97. return prefsPath;
  98. }
  99. void Project::Save(const String& fullpath)
  100. {
  101. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  102. pfile->Save(this);
  103. dirty_ = false;
  104. }
  105. bool Project::IsComponentsDirOrFile(const String& fullPath)
  106. {
  107. String pathName;
  108. String fileName;
  109. String extension;
  110. SplitPath(fullPath, pathName, fileName, extension);
  111. if (extension.Length() && extension != ".js")
  112. return false;
  113. if (IsAbsoluteParentPath(componentsPath_, pathName))
  114. return true;
  115. return false;
  116. }
  117. bool Project::IsScriptsDirOrFile(const String& fullPath)
  118. {
  119. String pathName;
  120. String fileName;
  121. String extension;
  122. SplitPath(fullPath, pathName, fileName, extension);
  123. if (extension.Length() && extension != ".js")
  124. return false;
  125. if (IsAbsoluteParentPath(scriptsPath_, pathName))
  126. return true;
  127. return false;
  128. }
  129. bool Project::IsModulesDirOrFile(const String& fullPath)
  130. {
  131. String pathName;
  132. String fileName;
  133. String extension;
  134. SplitPath(fullPath, pathName, fileName, extension);
  135. if (extension.Length() && extension != ".js")
  136. return false;
  137. if (IsAbsoluteParentPath(modulesPath_, pathName))
  138. return true;
  139. return false;
  140. }
  141. }