ToolEnvironment.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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/x86/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/AnyCPU/TPA/", resourcesDir.CString());
  47. netTPAPaths_ += ToString(";%sAtomicNET/Windows/Atomic/TPA/", resourcesDir.CString());
  48. #else
  49. String coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/OSX/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR);
  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. String coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/OSX/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR);
  70. #endif
  71. return true;
  72. }
  73. File jsonFile(context_, devConfigFilename_);
  74. if (!jsonFile.IsOpen())
  75. return false;
  76. String json;
  77. jsonFile.ReadText(json);
  78. if (!json.Length())
  79. return false;
  80. rapidjson::Document document;
  81. if (document.Parse<0>(json.CString()).HasParseError())
  82. {
  83. return false;
  84. }
  85. const Value::Member* rootSourceDir = document.FindMember("rootSourceDir");
  86. if (rootSourceDir && rootSourceDir->value.IsString())
  87. SetRootSourceDir(rootSourceDir->value.GetString());
  88. else
  89. return false;
  90. const Value::Member* rootBuildDir = document.FindMember("rootBuildDir");
  91. if (rootBuildDir && rootBuildDir->value.IsString())
  92. SetRootBuildDir(rootBuildDir->value.GetString(), true);
  93. else
  94. return false;
  95. return true;
  96. }
  97. const String& ToolEnvironment::GetDevConfigFilename()
  98. {
  99. if (devConfigFilename_.Length())
  100. return devConfigFilename_;
  101. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  102. #ifdef ATOMIC_PLATFORM_OSX
  103. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + ".atomicgameengine/toolEnv.json";
  104. #elif ATOMIC_PLATFORM_WINDOWS
  105. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + "AtomicGameEngine/toolEnv.json";
  106. #endif
  107. return devConfigFilename_;
  108. }
  109. void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
  110. {
  111. rootSourceDir_ = AddTrailingSlash(sourceDir);
  112. resourceCoreDataDir_ = rootSourceDir_ + "Resources/CoreData";
  113. resourcePlayerDataDir_ = rootSourceDir_ + "Resources/PlayerData";
  114. resourceEditorDataDir_ = rootSourceDir_ + "Resources/EditorData";
  115. toolDataDir_ = rootSourceDir_ + "Data/AtomicEditor/";
  116. }
  117. void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
  118. {
  119. rootBuildDir_ = AddTrailingSlash(buildDir);
  120. if (setBinaryPaths)
  121. {
  122. #ifdef ATOMIC_PLATFORM_WINDOWS
  123. #ifdef _DEBUG
  124. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Debug/AtomicPlayer.exe";
  125. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Debug/AtomicEditor.exe";
  126. #else
  127. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Release/AtomicPlayer.exe";
  128. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Release/AtomicEditor.exe";
  129. #endif
  130. playerAppFolder_ = rootSourceDir_ + "Data/AtomicEditor/Deployment/MacOS/AtomicPlayer.app";
  131. #elif ATOMIC_PLATFORM_OSX
  132. #ifdef ATOMIC_XCODE
  133. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/" + CMAKE_INTDIR + "/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  134. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/" + CMAKE_INTDIR + "/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  135. #else
  136. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  137. playerAppFolder_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/";
  138. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  139. #endif
  140. #endif
  141. }
  142. }
  143. String ToolEnvironment::GetIOSDeployBinary()
  144. {
  145. return GetToolDataDir() + "Deployment/IOS/ios-deploy/ios-deploy";
  146. }
  147. void ToolEnvironment::Dump()
  148. {
  149. LOGINFOF("Root Source Dir: %s", rootSourceDir_.CString());
  150. LOGINFOF("Root Build Dir: %s", rootBuildDir_.CString());
  151. LOGINFOF("Core Resource Dir: %s", resourceCoreDataDir_.CString());
  152. LOGINFOF("Player Resource Dir: %s", resourcePlayerDataDir_.CString());
  153. LOGINFOF("Editor Resource Dir: %s", resourceEditorDataDir_.CString());
  154. LOGINFOF("Editor Binary: %s", editorBinary_.CString());
  155. LOGINFOF("Player Binary: %s", playerBinary_.CString());
  156. LOGINFOF("Tool Binary: %s", toolBinary_.CString());
  157. LOGINFOF("Tool Data Dir: %s", toolDataDir_.CString());
  158. LOGINFOF("Deployment Data Dir: %s", deploymentDataDir_.CString());
  159. LOGINFOF("Dev Config File: %s", devConfigFilename_.CString());
  160. }
  161. }