Project.cpp 3.7 KB

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