Project.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. }
  49. bool Project::LoadBuildSettings()
  50. {
  51. return true;
  52. }
  53. void Project::AddPlatform(PlatformID platformID)
  54. {
  55. if (ContainsPlatform(platformID))
  56. return;
  57. SetDirty();
  58. platforms_.Push(platformID);
  59. }
  60. void Project::RemovePlatform(PlatformID platformID)
  61. {
  62. if (!ContainsPlatform(platformID))
  63. return;
  64. }
  65. bool Project::ContainsPlatform(PlatformID platformID)
  66. {
  67. for (List<PlatformID>::ConstIterator i = platforms_.Begin(); i != platforms_.End(); ++i)
  68. {
  69. if ((*i) == platformID)
  70. return true;
  71. }
  72. return false;
  73. }
  74. bool Project::Load(const String& fullpath)
  75. {
  76. loading_ = true;
  77. if (fullpath.Contains(".atomic")) {
  78. projectPath_ = AddTrailingSlash(GetPath(fullpath));
  79. projectFilePath_ = fullpath;
  80. }
  81. else
  82. {
  83. projectPath_ = AddTrailingSlash(fullpath);
  84. projectFilePath_ = GetFileName(RemoveTrailingSlash(projectPath_) + ".atomic");
  85. }
  86. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  87. bool result = pfile->Load(this);
  88. loading_ = false;
  89. LoadBuildSettings();
  90. LoadUserPrefs();
  91. if ( true /*result*/) {
  92. VariantMap data;
  93. data[ProjectLoaded::P_PROJECTPATH] = projectFilePath_;
  94. SendEvent(E_PROJECTLOADED, data);
  95. }
  96. return result;
  97. }
  98. String Project::GetBuildSettingsFullPath()
  99. {
  100. String path = GetPath(projectFilePath_);
  101. String filename = GetFileName(projectFilePath_);
  102. String buildSettingsPath = path + filename + ".buildsettings";
  103. return buildSettingsPath;
  104. }
  105. String Project::GetUserPrefsFullPath()
  106. {
  107. String path = GetPath(projectFilePath_);
  108. String filename = GetFileName(projectFilePath_);
  109. String prefsPath = path + filename + ".userprefs";
  110. return prefsPath;
  111. }
  112. void Project::Save(const String& fullpath)
  113. {
  114. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  115. pfile->Save(this);
  116. dirty_ = false;
  117. }
  118. bool Project::IsComponentsDirOrFile(const String& fullPath)
  119. {
  120. String pathName;
  121. String fileName;
  122. String extension;
  123. SplitPath(fullPath, pathName, fileName, extension);
  124. if (extension.Length() && extension != ".js")
  125. return false;
  126. if (IsAbsoluteParentPath(componentsPath_, pathName))
  127. return true;
  128. return false;
  129. }
  130. bool Project::IsScriptsDirOrFile(const String& fullPath)
  131. {
  132. String pathName;
  133. String fileName;
  134. String extension;
  135. SplitPath(fullPath, pathName, fileName, extension);
  136. if (extension.Length() && extension != ".js")
  137. return false;
  138. if (IsAbsoluteParentPath(scriptsPath_, pathName))
  139. return true;
  140. return false;
  141. }
  142. bool Project::IsModulesDirOrFile(const String& fullPath)
  143. {
  144. String pathName;
  145. String fileName;
  146. String extension;
  147. SplitPath(fullPath, pathName, fileName, extension);
  148. if (extension.Length() && extension != ".js")
  149. return false;
  150. if (IsAbsoluteParentPath(modulesPath_, pathName))
  151. return true;
  152. return false;
  153. }
  154. }