ToolEnvironment.cpp 6.8 KB

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