ToolEnvironment.cpp 6.4 KB

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