ToolEnvironment.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. // before resource system exists so use rapidjson directly
  8. #include <rapidjson/document.h>
  9. #include <rapidjson/prettywriter.h>
  10. #include <rapidjson/filestream.h>
  11. #include <Atomic/IO/Log.h>
  12. #include <Atomic/IO/FileSystem.h>
  13. #include <Atomic/IO/File.h>
  14. #include "ToolEnvironment.h"
  15. using namespace rapidjson;
  16. namespace ToolCore
  17. {
  18. ToolEnvironment::ToolEnvironment(Context* context) : Object(context),
  19. toolPrefs_(new ToolPrefs(context))
  20. {
  21. }
  22. ToolEnvironment::~ToolEnvironment()
  23. {
  24. }
  25. bool ToolEnvironment::InitFromPackage()
  26. {
  27. toolPrefs_->Load();
  28. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  29. #ifdef ATOMIC_PLATFORM_WINDOWS
  30. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor.exe";
  31. String resourcesDir = fileSystem->GetProgramDir() + "Resources/";
  32. #else
  33. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor";
  34. String resourcesDir = GetPath(RemoveTrailingSlash(fileSystem->GetProgramDir())) + "Resources/";
  35. #endif
  36. //TODO: move this to deployment stuff
  37. playerAppFolder_ = resourcesDir + "ToolData/Deployment/MacOS/AtomicPlayer.app/";
  38. playerBinary_ = resourcesDir + "ToolData/Deployment/Windows/x64/AtomicPlayer.exe";
  39. resourceCoreDataDir_ = resourcesDir + "CoreData";
  40. resourcePlayerDataDir_ = resourcesDir + "PlayerData";
  41. toolDataDir_ = resourcesDir + "ToolData/";
  42. // AtomicNET
  43. netAssemblyLoadPaths_ = GetNativePath(ToString("%sAtomicNET/Windows/Atomic/", resourcesDir.CString()));
  44. #ifdef ATOMIC_PLATFORM_WINDOWS
  45. netCoreCLRAbsPath_ = GetNativePath(ToString("%sAtomicNET/Windows/x64/", resourcesDir.CString()));
  46. netTPAPaths_ = ToString("%sAtomicNET/Windows/Atomic/TPA/", resourcesDir.CString());
  47. #else
  48. netCoreCLRAbsPath_ = GetNativePath(ToString("%sAtomicNET/Windows/x64/", resourcesDir.CString()));
  49. netTPAPaths_ = ToString("%sAtomicNET/Windows/Atomic/TPA/", resourcesDir.CString());
  50. #endif
  51. return true;
  52. }
  53. bool ToolEnvironment::InitFromJSON(bool atomicTool)
  54. {
  55. toolPrefs_->Load();
  56. // make sure config path is initialized
  57. GetDevConfigFilename();
  58. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  59. if (atomicTool || !fileSystem->FileExists(devConfigFilename_))
  60. {
  61. // default to build directories
  62. SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
  63. SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
  64. netAssemblyLoadPaths_ = GetNativePath(ToString("%s/Artifacts/AtomicNET/", ATOMIC_ROOT_SOURCE_DIR));
  65. #ifdef ATOMIC_PLATFORM_WINDOWS
  66. netCoreCLRAbsPath_ = GetNativePath(ToString("%s/Submodules/CoreCLR/Windows/Release/x64/", ATOMIC_ROOT_SOURCE_DIR));
  67. netTPAPaths_ = ToString("%s/Artifacts/AtomicNET/TPA/", ATOMIC_ROOT_SOURCE_DIR);
  68. #else
  69. netCoreCLRAbsPath_ = GetNativePath(ToString("%s/Submodules/CoreCLR/MacOSX/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR));
  70. netTPAPaths_ = ToString("%s/Artifacts/AtomicNET/TPA/", ATOMIC_ROOT_SOURCE_DIR);
  71. #endif
  72. return true;
  73. }
  74. File jsonFile(context_, devConfigFilename_);
  75. if (!jsonFile.IsOpen())
  76. return false;
  77. String json;
  78. jsonFile.ReadText(json);
  79. if (!json.Length())
  80. return false;
  81. rapidjson::Document document;
  82. if (document.Parse<0>(json.CString()).HasParseError())
  83. {
  84. return false;
  85. }
  86. const Value::Member* rootSourceDir = document.FindMember("rootSourceDir");
  87. if (rootSourceDir && rootSourceDir->value.IsString())
  88. SetRootSourceDir(rootSourceDir->value.GetString());
  89. else
  90. return false;
  91. const Value::Member* rootBuildDir = document.FindMember("rootBuildDir");
  92. if (rootBuildDir && rootBuildDir->value.IsString())
  93. SetRootBuildDir(rootBuildDir->value.GetString(), true);
  94. else
  95. return false;
  96. return true;
  97. }
  98. const String& ToolEnvironment::GetDevConfigFilename()
  99. {
  100. if (devConfigFilename_.Length())
  101. return devConfigFilename_;
  102. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  103. #ifdef ATOMIC_PLATFORM_OSX
  104. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + ".atomicgameengine/toolEnv.json";
  105. #elif ATOMIC_PLATFORM_WINDOWS
  106. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + "AtomicGameEngine/toolEnv.json";
  107. #endif
  108. return devConfigFilename_;
  109. }
  110. void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
  111. {
  112. rootSourceDir_ = AddTrailingSlash(sourceDir);
  113. resourceCoreDataDir_ = rootSourceDir_ + "Resources/CoreData";
  114. resourcePlayerDataDir_ = rootSourceDir_ + "Resources/PlayerData";
  115. resourceEditorDataDir_ = rootSourceDir_ + "Resources/EditorData";
  116. toolDataDir_ = rootSourceDir_ + "Data/AtomicEditor/";
  117. }
  118. void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
  119. {
  120. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  121. rootBuildDir_ = AddTrailingSlash(buildDir);
  122. if (setBinaryPaths)
  123. {
  124. #ifdef ATOMIC_PLATFORM_WINDOWS
  125. #ifdef _DEBUG
  126. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Debug/AtomicPlayer.exe";
  127. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Debug/AtomicEditor.exe";
  128. #else
  129. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Release/AtomicPlayer.exe";
  130. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Release/AtomicEditor.exe";
  131. #endif
  132. // some build tools like ninja don't use Release/Debug folders
  133. if (!fileSystem->FileExists(playerBinary_))
  134. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.exe";
  135. if (!fileSystem->FileExists(editorBinary_))
  136. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.exe";
  137. playerAppFolder_ = rootSourceDir_ + "Data/AtomicEditor/Deployment/MacOS/AtomicPlayer.app";
  138. #elif ATOMIC_PLATFORM_OSX
  139. #ifdef ATOMIC_XCODE
  140. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/" + CMAKE_INTDIR + "/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  141. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/" + CMAKE_INTDIR + "/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  142. #else
  143. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  144. playerAppFolder_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/";
  145. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  146. #endif
  147. #endif
  148. }
  149. }
  150. String ToolEnvironment::GetIOSDeployBinary()
  151. {
  152. return GetToolDataDir() + "Deployment/IOS/ios-deploy/ios-deploy";
  153. }
  154. void ToolEnvironment::Dump()
  155. {
  156. LOGINFOF("Root Source Dir: %s", rootSourceDir_.CString());
  157. LOGINFOF("Root Build Dir: %s", rootBuildDir_.CString());
  158. LOGINFOF("Core Resource Dir: %s", resourceCoreDataDir_.CString());
  159. LOGINFOF("Player Resource Dir: %s", resourcePlayerDataDir_.CString());
  160. LOGINFOF("Editor Resource Dir: %s", resourceEditorDataDir_.CString());
  161. LOGINFOF("Editor Binary: %s", editorBinary_.CString());
  162. LOGINFOF("Player Binary: %s", playerBinary_.CString());
  163. LOGINFOF("Tool Binary: %s", toolBinary_.CString());
  164. LOGINFOF("Tool Data Dir: %s", toolDataDir_.CString());
  165. LOGINFOF("Deployment Data Dir: %s", deploymentDataDir_.CString());
  166. LOGINFOF("Dev Config File: %s", devConfigFilename_.CString());
  167. }
  168. }