ToolEnvironment.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. // before resource system exists so use rapidjson directly
  2. #include <rapidjson/document.h>
  3. #include <rapidjson/prettywriter.h>
  4. #include <rapidjson/filestream.h>
  5. #include <Atomic/IO/Log.h>
  6. #include <Atomic/IO/FileSystem.h>
  7. #include <Atomic/IO/File.h>
  8. #include "ToolEnvironment.h"
  9. using namespace rapidjson;
  10. namespace ToolCore
  11. {
  12. ToolEnvironment::ToolEnvironment(Context* context) : Object(context),
  13. toolPrefs_(new ToolPrefs(context))
  14. {
  15. }
  16. ToolEnvironment::~ToolEnvironment()
  17. {
  18. }
  19. bool ToolEnvironment::InitFromPackage()
  20. {
  21. toolPrefs_->Load();
  22. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  23. #ifdef ATOMIC_PLATFORM_WINDOWS
  24. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor.exe";
  25. String resourcesDir = fileSystem->GetProgramDir() + "Resources/";
  26. #else
  27. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor";
  28. String resourcesDir = GetPath(RemoveTrailingSlash(fileSystem->GetProgramDir())) + "Resources/";
  29. #endif
  30. //TODO: move this to deployment stuff
  31. playerAppFolder_ = resourcesDir + "ToolData/Deployment/MacOS/AtomicPlayer.app/";
  32. playerBinary_ = resourcesDir + "ToolData/Deployment/Windows/x86/AtomicPlayer.exe";
  33. resourceCoreDataDir_ = resourcesDir + "CoreData";
  34. resourcePlayerDataDir_ = resourcesDir + "PlayerData";
  35. toolDataDir_ = resourcesDir + "ToolData/";
  36. return true;
  37. }
  38. bool ToolEnvironment::InitFromJSON(bool atomicTool)
  39. {
  40. toolPrefs_->Load();
  41. // make sure config path is initialized
  42. GetDevConfigFilename();
  43. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  44. if (atomicTool || !fileSystem->FileExists(devConfigFilename_))
  45. {
  46. // default to build directories
  47. SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
  48. SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
  49. return true;
  50. }
  51. File jsonFile(context_, devConfigFilename_);
  52. if (!jsonFile.IsOpen())
  53. return false;
  54. String json;
  55. jsonFile.ReadText(json);
  56. if (!json.Length())
  57. return false;
  58. rapidjson::Document document;
  59. if (document.Parse<0>(json.CString()).HasParseError())
  60. {
  61. return false;
  62. }
  63. const Value::Member* rootSourceDir = document.FindMember("rootSourceDir");
  64. if (rootSourceDir && rootSourceDir->value.IsString())
  65. SetRootSourceDir(rootSourceDir->value.GetString());
  66. else
  67. return false;
  68. const Value::Member* rootBuildDir = document.FindMember("rootBuildDir");
  69. if (rootBuildDir && rootBuildDir->value.IsString())
  70. SetRootBuildDir(rootBuildDir->value.GetString(), true);
  71. else
  72. return false;
  73. return true;
  74. }
  75. const String& ToolEnvironment::GetDevConfigFilename()
  76. {
  77. if (devConfigFilename_.Length())
  78. return devConfigFilename_;
  79. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  80. #ifdef ATOMIC_PLATFORM_OSX
  81. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + ".atomicgameengine/toolEnv.json";
  82. #elif ATOMIC_PLATFORM_WINDOWS
  83. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + "AtomicGameEngine/toolEnv.json";
  84. #endif
  85. return devConfigFilename_;
  86. }
  87. void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
  88. {
  89. rootSourceDir_ = AddTrailingSlash(sourceDir);
  90. resourceCoreDataDir_ = rootSourceDir_ + "Resources/CoreData";
  91. resourcePlayerDataDir_ = rootSourceDir_ + "Resources/PlayerData";
  92. resourceEditorDataDir_ = rootSourceDir_ + "Resources/EditorData";
  93. toolDataDir_ = rootSourceDir_ + "Data/AtomicEditor/";
  94. }
  95. void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
  96. {
  97. rootBuildDir_ = AddTrailingSlash(buildDir);
  98. if (setBinaryPaths)
  99. {
  100. #ifdef ATOMIC_PLATFORM_WINDOWS
  101. #ifdef _DEBUG
  102. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Debug/AtomicPlayer.exe";
  103. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Debug/AtomicEditor.exe";
  104. #else
  105. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Release/AtomicPlayer.exe";
  106. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Release/AtomicEditor.exe";
  107. #endif
  108. playerAppFolder_ = rootSourceDir_ + "Data/AtomicEditor/Deployment/MacOS/AtomicPlayer.app";
  109. #elif ATOMIC_PLATFORM_OSX
  110. #ifdef ATOMIC_XCODE
  111. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/" + CMAKE_INTDIR + "/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  112. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/" + CMAKE_INTDIR + "/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  113. #else
  114. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  115. playerAppFolder_ = rootBuildDir_ + "Source/AtomicPlayer/Application/AtomicPlayer.app/";
  116. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  117. #endif
  118. #endif
  119. }
  120. }
  121. String ToolEnvironment::GetIOSDeployBinary()
  122. {
  123. return GetToolDataDir() + "Deployment/IOS/ios-deploy/ios-deploy";
  124. }
  125. void ToolEnvironment::Dump()
  126. {
  127. LOGINFOF("Root Source Dir: %s", rootSourceDir_.CString());
  128. LOGINFOF("Root Build Dir: %s", rootBuildDir_.CString());
  129. LOGINFOF("Core Resource Dir: %s", resourceCoreDataDir_.CString());
  130. LOGINFOF("Player Resource Dir: %s", resourcePlayerDataDir_.CString());
  131. LOGINFOF("Editor Resource Dir: %s", resourceEditorDataDir_.CString());
  132. LOGINFOF("Editor Binary: %s", editorBinary_.CString());
  133. LOGINFOF("Player Binary: %s", playerBinary_.CString());
  134. LOGINFOF("Tool Binary: %s", toolBinary_.CString());
  135. LOGINFOF("Tool Data Dir: %s", toolDataDir_.CString());
  136. LOGINFOF("Deployment Data Dir: %s", deploymentDataDir_.CString());
  137. LOGINFOF("Dev Config File: %s", devConfigFilename_.CString());
  138. }
  139. }