ToolEnvironment.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. // before resource system exists so use rapidjson directly
  23. #include <rapidjson/document.h>
  24. #include <rapidjson/prettywriter.h>
  25. #include <rapidjson/filestream.h>
  26. #include <Atomic/IO/Log.h>
  27. #include <Atomic/IO/FileSystem.h>
  28. #include <Atomic/IO/File.h>
  29. #include "ToolEnvironment.h"
  30. using namespace rapidjson;
  31. namespace ToolCore
  32. {
  33. ToolEnvironment::ToolEnvironment(Context* context) : Object(context),
  34. toolPrefs_(new ToolPrefs(context))
  35. {
  36. }
  37. ToolEnvironment::~ToolEnvironment()
  38. {
  39. }
  40. bool ToolEnvironment::InitFromPackage()
  41. {
  42. toolPrefs_->Load();
  43. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  44. #ifdef ATOMIC_PLATFORM_WINDOWS
  45. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor.exe";
  46. String resourcesDir = fileSystem->GetProgramDir() + "Resources/";
  47. #elif ATOMIC_PLATFORM_LINUX
  48. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor";
  49. String resourcesDir = fileSystem->GetProgramDir() + "Resources/";
  50. #else
  51. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor";
  52. String resourcesDir = GetPath(RemoveTrailingSlash(fileSystem->GetProgramDir())) + "Resources/";
  53. #endif
  54. //TODO: move this to deployment stuff
  55. playerAppFolder_ = resourcesDir + "ToolData/Deployment/MacOS/AtomicPlayer.app/";
  56. playerBinary_ = resourcesDir + "ToolData/Deployment/Windows/x64/AtomicPlayer.exe";
  57. resourceCoreDataDir_ = resourcesDir + "CoreData";
  58. resourcePlayerDataDir_ = resourcesDir + "PlayerData";
  59. toolDataDir_ = resourcesDir + "ToolData/";
  60. // AtomicNET
  61. // atomicNETNuGetBinary_ = ToString("%sBuild/Managed/nuget/nuget.exe", rootSourceDir_.CString());
  62. atomicNETRootDir_ = resourcesDir + "ToolData/AtomicNET/";
  63. atomicNETCoreAssemblyDir_ = atomicNETRootDir_ + "Release/";
  64. atomicNETManagedPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicPlayer.exe";
  65. atomicNETManagedIPCPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicIPCPlayer.exe";
  66. #ifdef ATOMIC_PLATFORM_OSX
  67. monoExecutableDir_ = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/";
  68. atomicNETNuGetBinary_ = monoExecutableDir_ + "nuget";
  69. #endif
  70. return true;
  71. }
  72. bool ToolEnvironment::InitFromJSON(bool atomicTool)
  73. {
  74. toolPrefs_->Load();
  75. // make sure config path is initialized
  76. GetDevConfigFilename();
  77. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  78. if (atomicTool || !fileSystem->FileExists(devConfigFilename_))
  79. {
  80. // default to build directories
  81. SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
  82. SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
  83. return true;
  84. }
  85. File jsonFile(context_, devConfigFilename_);
  86. if (!jsonFile.IsOpen())
  87. return false;
  88. String json;
  89. jsonFile.ReadText(json);
  90. if (!json.Length())
  91. return false;
  92. rapidjson::Document document;
  93. if (document.Parse<0>(json.CString()).HasParseError())
  94. {
  95. return false;
  96. }
  97. const Value::Member* rootSourceDir = document.FindMember("rootSourceDir");
  98. if (rootSourceDir && rootSourceDir->value.IsString())
  99. SetRootSourceDir(rootSourceDir->value.GetString());
  100. else
  101. return false;
  102. const Value::Member* rootBuildDir = document.FindMember("rootBuildDir");
  103. if (rootBuildDir && rootBuildDir->value.IsString())
  104. SetRootBuildDir(rootBuildDir->value.GetString(), true);
  105. else
  106. return false;
  107. return true;
  108. }
  109. const String& ToolEnvironment::GetDevConfigFilename()
  110. {
  111. if (devConfigFilename_.Length())
  112. return devConfigFilename_;
  113. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  114. #ifdef ATOMIC_PLATFORM_OSX
  115. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + ".atomicgameengine/toolEnv.json";
  116. #elif ATOMIC_PLATFORM_WINDOWS
  117. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + "AtomicGameEngine/toolEnv.json";
  118. #else
  119. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + ".atomicgameengine/toolEnv.json";
  120. #endif
  121. return devConfigFilename_;
  122. }
  123. void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
  124. {
  125. rootSourceDir_ = AddTrailingSlash(sourceDir);
  126. resourceCoreDataDir_ = rootSourceDir_ + "Resources/CoreData";
  127. resourcePlayerDataDir_ = rootSourceDir_ + "Resources/PlayerData";
  128. resourceEditorDataDir_ = rootSourceDir_ + "Resources/EditorData";
  129. toolDataDir_ = rootSourceDir_ + "Data/AtomicEditor/";
  130. // AtomicNET
  131. #ifdef ATOMIC_DEBUG
  132. String config = "Debug";
  133. #else
  134. String config = "Release";
  135. #endif
  136. atomicNETRootDir_ = rootSourceDir_ + "Artifacts/AtomicNET/";
  137. atomicNETCoreAssemblyDir_ = rootSourceDir_ + "Artifacts/AtomicNET/" + config + "/";
  138. atomicNETManagedPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicPlayer.exe";
  139. atomicNETManagedIPCPlayerBinary_ = atomicNETCoreAssemblyDir_ + "AtomicIPCPlayer.exe";
  140. #ifdef ATOMIC_PLATFORM_WINDOWS
  141. atomicNETNuGetBinary_ = ToString("%sBuild/Managed/nuget/nuget.exe", rootSourceDir_.CString());
  142. #endif
  143. #ifdef ATOMIC_PLATFORM_OSX
  144. monoExecutableDir_ = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/";
  145. atomicNETNuGetBinary_ = monoExecutableDir_ + "nuget";
  146. #endif
  147. }
  148. void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
  149. {
  150. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  151. rootBuildDir_ = AddTrailingSlash(buildDir);
  152. if (setBinaryPaths)
  153. {
  154. #ifdef ATOMIC_PLATFORM_WINDOWS
  155. #ifdef _DEBUG
  156. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Debug/AtomicPlayer.exe";
  157. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Debug/AtomicEditor.exe";
  158. #else
  159. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Release/AtomicPlayer.exe";
  160. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Release/AtomicEditor.exe";
  161. #endif
  162. // some build tools like ninja don't use Release/Debug folders
  163. if (!fileSystem->FileExists(playerBinary_))
  164. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.exe";
  165. if (!fileSystem->FileExists(editorBinary_))
  166. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.exe";
  167. playerAppFolder_ = rootSourceDir_ + "Data/AtomicEditor/Deployment/MacOS/AtomicPlayer.app";
  168. #elif ATOMIC_PLATFORM_OSX
  169. #ifdef ATOMIC_XCODE
  170. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/" + CMAKE_INTDIR + "/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  171. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/" + CMAKE_INTDIR + "/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  172. #else
  173. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  174. playerAppFolder_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/";
  175. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  176. #endif
  177. #else
  178. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer";
  179. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor";
  180. #endif
  181. }
  182. }
  183. String ToolEnvironment::GetIOSDeployBinary()
  184. {
  185. return GetToolDataDir() + "Deployment/IOS/ios-deploy/ios-deploy";
  186. }
  187. void ToolEnvironment::Dump()
  188. {
  189. ATOMIC_LOGINFOF("Root Source Dir: %s", rootSourceDir_.CString());
  190. ATOMIC_LOGINFOF("Root Build Dir: %s", rootBuildDir_.CString());
  191. ATOMIC_LOGINFOF("Core Resource Dir: %s", resourceCoreDataDir_.CString());
  192. ATOMIC_LOGINFOF("Player Resource Dir: %s", resourcePlayerDataDir_.CString());
  193. ATOMIC_LOGINFOF("Editor Resource Dir: %s", resourceEditorDataDir_.CString());
  194. ATOMIC_LOGINFOF("Editor Binary: %s", editorBinary_.CString());
  195. ATOMIC_LOGINFOF("Player Binary: %s", playerBinary_.CString());
  196. ATOMIC_LOGINFOF("Tool Binary: %s", toolBinary_.CString());
  197. ATOMIC_LOGINFOF("Tool Data Dir: %s", toolDataDir_.CString());
  198. ATOMIC_LOGINFOF("Deployment Data Dir: %s", deploymentDataDir_.CString());
  199. ATOMIC_LOGINFOF("Dev Config File: %s", devConfigFilename_.CString());
  200. }
  201. }