Project.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 "../ToolEvents.h"
  12. #include "../Platform/Platform.h"
  13. #include "ProjectFile.h"
  14. #include "ProjectBuildSettings.h"
  15. #include "ProjectUserPrefs.h"
  16. #include "Project.h"
  17. using namespace rapidjson;
  18. namespace ToolCore
  19. {
  20. Project::Project(Context* context) :
  21. Object(context),
  22. loading_(false),
  23. dirty_(false)
  24. {
  25. version_ = "1.0.0";
  26. userPrefs_ = new ProjectUserPrefs(context_);
  27. buildSettings_ = new ProjectBuildSettings(context_);
  28. }
  29. Project::~Project()
  30. {
  31. }
  32. void Project::SaveUserPrefs()
  33. {
  34. }
  35. bool Project::LoadUserPrefs()
  36. {
  37. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  38. // If we're in CLI mode, the Build folder is always relative to project
  39. if (tsystem->IsCLI())
  40. {
  41. String path = GetPath(projectFilePath_) + "Build";
  42. userPrefs_->SetLastBuildPath(path);
  43. }
  44. return true;
  45. }
  46. void Project::SaveBuildSettings()
  47. {
  48. buildSettings_->Save(GetProjectPath() + "BuildSettings.json");
  49. }
  50. bool Project::LoadBuildSettings()
  51. {
  52. buildSettings_->Load(GetProjectPath() + "BuildSettings.json");
  53. return true;
  54. }
  55. void Project::AddPlatform(PlatformID platformID)
  56. {
  57. if (ContainsPlatform(platformID))
  58. return;
  59. SetDirty();
  60. platforms_.Push(platformID);
  61. }
  62. void Project::RemovePlatform(PlatformID platformID)
  63. {
  64. if (!ContainsPlatform(platformID))
  65. return;
  66. }
  67. bool Project::ContainsPlatform(PlatformID platformID)
  68. {
  69. for (List<PlatformID>::ConstIterator i = platforms_.Begin(); i != platforms_.End(); ++i)
  70. {
  71. if ((*i) == platformID)
  72. return true;
  73. }
  74. return false;
  75. }
  76. bool Project::Load(const String& fullpath)
  77. {
  78. loading_ = true;
  79. if (fullpath.Contains(".atomic")) {
  80. projectPath_ = AddTrailingSlash(GetPath(fullpath));
  81. projectFilePath_ = fullpath;
  82. }
  83. else
  84. {
  85. projectPath_ = AddTrailingSlash(fullpath);
  86. projectFilePath_ = projectPath_ + GetFileName(RemoveTrailingSlash(projectPath_)) + ".atomic";
  87. }
  88. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  89. bool result = pfile->Load(this);
  90. loading_ = false;
  91. LoadBuildSettings();
  92. LoadUserPrefs();
  93. if ( true /*result*/) {
  94. VariantMap data;
  95. data[ProjectLoaded::P_PROJECTPATH] = projectFilePath_;
  96. SendEvent(E_PROJECTLOADED, data);
  97. }
  98. return result;
  99. }
  100. String Project::GetBuildSettingsFullPath()
  101. {
  102. String path = GetPath(projectFilePath_);
  103. String filename = GetFileName(projectFilePath_);
  104. String buildSettingsPath = path + filename + ".buildsettings";
  105. return buildSettingsPath;
  106. }
  107. String Project::GetUserPrefsFullPath()
  108. {
  109. String path = GetPath(projectFilePath_);
  110. String filename = GetFileName(projectFilePath_);
  111. String prefsPath = path + filename + ".userprefs";
  112. return prefsPath;
  113. }
  114. void Project::Save(const String& fullpath)
  115. {
  116. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  117. pfile->Save(this);
  118. dirty_ = false;
  119. }
  120. bool Project::IsComponentsDirOrFile(const String& fullPath)
  121. {
  122. String pathName;
  123. String fileName;
  124. String extension;
  125. SplitPath(fullPath, pathName, fileName, extension);
  126. if (extension.Length() && extension != ".js")
  127. return false;
  128. if (IsAbsoluteParentPath(componentsPath_, pathName))
  129. return true;
  130. return false;
  131. }
  132. bool Project::IsScriptsDirOrFile(const String& fullPath)
  133. {
  134. String pathName;
  135. String fileName;
  136. String extension;
  137. SplitPath(fullPath, pathName, fileName, extension);
  138. if (extension.Length() && extension != ".js")
  139. return false;
  140. if (IsAbsoluteParentPath(scriptsPath_, pathName))
  141. return true;
  142. return false;
  143. }
  144. bool Project::IsModulesDirOrFile(const String& fullPath)
  145. {
  146. String pathName;
  147. String fileName;
  148. String extension;
  149. SplitPath(fullPath, pathName, fileName, extension);
  150. if (extension.Length() && extension != ".js")
  151. return false;
  152. if (IsAbsoluteParentPath(modulesPath_, pathName))
  153. return true;
  154. return false;
  155. }
  156. }