ToolEnvironment.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. #include <Atomic/IO/Log.h>
  23. #include <Atomic/IO/FileSystem.h>
  24. #include <Atomic/IO/File.h>
  25. #include "ToolEnvironment.h"
  26. namespace ToolCore
  27. {
  28. bool ToolEnvironment::bootstrapping_ = false;
  29. ToolEnvironment::ToolEnvironment(Context* context) : Object(context),
  30. cli_(false),
  31. toolPrefs_(new ToolPrefs(context))
  32. {
  33. }
  34. ToolEnvironment::~ToolEnvironment()
  35. {
  36. }
  37. bool ToolEnvironment::InitFromDistribution()
  38. {
  39. toolPrefs_->Load();
  40. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  41. #ifdef ATOMIC_PLATFORM_WINDOWS
  42. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor.exe";
  43. String resourcesDir = fileSystem->GetProgramDir() + "Resources/";
  44. playerBinary_ = resourcesDir + "ToolData/Deployment/Windows/x64/AtomicPlayer.exe";
  45. #elif ATOMIC_PLATFORM_LINUX
  46. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor";
  47. String resourcesDir = fileSystem->GetProgramDir() + "Resources/";
  48. playerBinary_ = resourcesDir + "ToolData/Deployment/Linux/AtomicPlayer";
  49. #else
  50. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor";
  51. String resourcesDir = GetPath(RemoveTrailingSlash(fileSystem->GetProgramDir())) + "Resources/";
  52. playerAppFolder_ = resourcesDir + "ToolData/Deployment/MacOS/AtomicPlayer.app/";
  53. #endif
  54. resourceCoreDataDir_ = resourcesDir + "CoreData";
  55. resourcePlayerDataDir_ = resourcesDir + "PlayerData";
  56. toolDataDir_ = resourcesDir + "ToolData/";
  57. // AtomicNET
  58. #ifdef ATOMIC_DEBUG
  59. String config = "Debug";
  60. #else
  61. String config = "Release";
  62. #endif
  63. atomicNETRootDir_ = resourcesDir + "ToolData/AtomicNET/";
  64. atomicNETCoreAssemblyDir_ = atomicNETRootDir_ + config + "/";
  65. #ifdef ATOMIC_PLATFORM_OSX
  66. monoExecutableDir_ = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/";
  67. atomicNETNuGetBinary_ = monoExecutableDir_ + "nuget";
  68. #endif
  69. return true;
  70. }
  71. bool ToolEnvironment::Initialize(bool cli)
  72. {
  73. bool result = true;
  74. cli_ = cli;
  75. toolPrefs_->Load();
  76. #ifdef ATOMIC_DEV_BUILD
  77. SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
  78. SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
  79. #else
  80. if (!bootstrapping_)
  81. {
  82. result = InitFromDistribution();
  83. }
  84. else
  85. {
  86. SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
  87. SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
  88. }
  89. #endif
  90. return result;
  91. }
  92. void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
  93. {
  94. rootSourceDir_ = AddTrailingSlash(sourceDir);
  95. resourceCoreDataDir_ = rootSourceDir_ + "Resources/CoreData";
  96. resourcePlayerDataDir_ = rootSourceDir_ + "Resources/PlayerData";
  97. resourceEditorDataDir_ = rootSourceDir_ + "Resources/EditorData";
  98. toolDataDir_ = rootSourceDir_ + "Data/AtomicEditor/";
  99. // AtomicNET
  100. #ifdef ATOMIC_DEBUG
  101. String config = "Debug";
  102. #else
  103. String config = "Release";
  104. #endif
  105. atomicNETRootDir_ = rootSourceDir_ + "Artifacts/AtomicNET/";
  106. atomicNETCoreAssemblyDir_ = rootSourceDir_ + "Artifacts/AtomicNET/" + config + "/";
  107. #if defined ATOMIC_PLATFORM_WINDOWS || defined ATOMIC_PLATFORM_LINUX
  108. atomicNETNuGetBinary_ = ToString("%sBuild/Managed/nuget/nuget.exe", rootSourceDir_.CString());
  109. #endif
  110. #ifdef ATOMIC_PLATFORM_OSX
  111. monoExecutableDir_ = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/";
  112. atomicNETNuGetBinary_ = monoExecutableDir_ + "nuget";
  113. #endif
  114. }
  115. void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
  116. {
  117. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  118. rootBuildDir_ = AddTrailingSlash(buildDir);
  119. if (setBinaryPaths)
  120. {
  121. #ifdef ATOMIC_PLATFORM_WINDOWS
  122. #ifdef _DEBUG
  123. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Debug/AtomicPlayer.exe";
  124. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Debug/AtomicEditor.exe";
  125. #else
  126. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Release/AtomicPlayer.exe";
  127. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Release/AtomicEditor.exe";
  128. #endif
  129. // some build tools like ninja don't use Release/Debug folders
  130. if (!fileSystem->FileExists(playerBinary_))
  131. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.exe";
  132. if (!fileSystem->FileExists(editorBinary_))
  133. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.exe";
  134. playerAppFolder_ = rootSourceDir_ + "Data/AtomicEditor/Deployment/MacOS/AtomicPlayer.app";
  135. #elif ATOMIC_PLATFORM_OSX
  136. #ifdef ATOMIC_XCODE
  137. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/" + CMAKE_INTDIR + "/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  138. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/" + CMAKE_INTDIR + "/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  139. #else
  140. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  141. playerAppFolder_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/";
  142. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  143. #endif
  144. #else
  145. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer";
  146. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor";
  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. ATOMIC_LOGINFOF("Root Source Dir: %s", rootSourceDir_.CString());
  157. ATOMIC_LOGINFOF("Root Build Dir: %s", rootBuildDir_.CString());
  158. ATOMIC_LOGINFOF("Core Resource Dir: %s", resourceCoreDataDir_.CString());
  159. ATOMIC_LOGINFOF("Player Resource Dir: %s", resourcePlayerDataDir_.CString());
  160. ATOMIC_LOGINFOF("Editor Resource Dir: %s", resourceEditorDataDir_.CString());
  161. ATOMIC_LOGINFOF("Editor Binary: %s", editorBinary_.CString());
  162. ATOMIC_LOGINFOF("Player Binary: %s", playerBinary_.CString());
  163. ATOMIC_LOGINFOF("Tool Binary: %s", toolBinary_.CString());
  164. ATOMIC_LOGINFOF("Tool Data Dir: %s", toolDataDir_.CString());
  165. ATOMIC_LOGINFOF("Deployment Data Dir: %s", deploymentDataDir_.CString());
  166. }
  167. }