Project.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. projectPath_ = GetPath(fullpath);
  78. projectFilePath_ = fullpath;
  79. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  80. bool result = pfile->Load(this);
  81. loading_ = false;
  82. LoadBuildSettings();
  83. LoadUserPrefs();
  84. if ( true /*result*/) {
  85. VariantMap data;
  86. data[ProjectLoaded::P_PROJECTPATH] = projectFilePath_;
  87. SendEvent(E_PROJECTLOADED, data);
  88. }
  89. return result;
  90. }
  91. String Project::GetBuildSettingsFullPath()
  92. {
  93. String path = GetPath(projectFilePath_);
  94. String filename = GetFileName(projectFilePath_);
  95. String buildSettingsPath = path + filename + ".buildsettings";
  96. return buildSettingsPath;
  97. }
  98. String Project::GetUserPrefsFullPath()
  99. {
  100. String path = GetPath(projectFilePath_);
  101. String filename = GetFileName(projectFilePath_);
  102. String prefsPath = path + filename + ".userprefs";
  103. return prefsPath;
  104. }
  105. void Project::Save(const String& fullpath)
  106. {
  107. SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
  108. pfile->Save(this);
  109. dirty_ = false;
  110. }
  111. bool Project::IsComponentsDirOrFile(const String& fullPath)
  112. {
  113. String pathName;
  114. String fileName;
  115. String extension;
  116. SplitPath(fullPath, pathName, fileName, extension);
  117. if (extension.Length() && extension != ".js")
  118. return false;
  119. if (IsAbsoluteParentPath(componentsPath_, pathName))
  120. return true;
  121. return false;
  122. }
  123. bool Project::IsScriptsDirOrFile(const String& fullPath)
  124. {
  125. String pathName;
  126. String fileName;
  127. String extension;
  128. SplitPath(fullPath, pathName, fileName, extension);
  129. if (extension.Length() && extension != ".js")
  130. return false;
  131. if (IsAbsoluteParentPath(scriptsPath_, pathName))
  132. return true;
  133. return false;
  134. }
  135. bool Project::IsModulesDirOrFile(const String& fullPath)
  136. {
  137. String pathName;
  138. String fileName;
  139. String extension;
  140. SplitPath(fullPath, pathName, fileName, extension);
  141. if (extension.Length() && extension != ".js")
  142. return false;
  143. if (IsAbsoluteParentPath(modulesPath_, pathName))
  144. return true;
  145. return false;
  146. }
  147. }