ToolEnvironment.cpp 5.4 KB

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