ToolEnvironment.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. //TODO: move this to deployment stuff
  27. playerBinary_ = resourcesDir + "ToolData/Deployment/Windows/x86/AtomicPlayer.exe";
  28. #else
  29. editorBinary_ = fileSystem->GetProgramDir() + "AtomicEditor";
  30. String resourcesDir = GetPath(RemoveTrailingSlash(fileSystem->GetProgramDir())) + "Resources/";
  31. //TODO: move this to deployment stuff
  32. playerAppFolder_ = resourcesDir + "ToolData/Deployment/MacOS/AtomicPlayer.app/";
  33. #endif
  34. resourceCoreDataDir_ = resourcesDir + "CoreData";
  35. resourcePlayerDataDir_ = resourcesDir + "PlayerData";
  36. toolDataDir_ = resourcesDir + "ToolData/";
  37. return true;
  38. }
  39. bool ToolEnvironment::InitFromJSON(bool atomicTool)
  40. {
  41. toolPrefs_->Load();
  42. // make sure config path is initialized
  43. GetDevConfigFilename();
  44. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  45. if (atomicTool || !fileSystem->FileExists(devConfigFilename_))
  46. {
  47. // default to build directories
  48. SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
  49. SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
  50. return true;
  51. }
  52. File jsonFile(context_, devConfigFilename_);
  53. if (!jsonFile.IsOpen())
  54. return false;
  55. String json;
  56. jsonFile.ReadText(json);
  57. if (!json.Length())
  58. return false;
  59. rapidjson::Document document;
  60. if (document.Parse<0>(json.CString()).HasParseError())
  61. {
  62. return false;
  63. }
  64. const Value::Member* rootSourceDir = document.FindMember("rootSourceDir");
  65. if (rootSourceDir && rootSourceDir->value.IsString())
  66. SetRootSourceDir(rootSourceDir->value.GetString());
  67. else
  68. return false;
  69. const Value::Member* rootBuildDir = document.FindMember("rootBuildDir");
  70. if (rootBuildDir && rootBuildDir->value.IsString())
  71. SetRootBuildDir(rootBuildDir->value.GetString(), true);
  72. else
  73. return false;
  74. return true;
  75. }
  76. const String& ToolEnvironment::GetDevConfigFilename()
  77. {
  78. if (devConfigFilename_.Length())
  79. return devConfigFilename_;
  80. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  81. #ifdef ATOMIC_PLATFORM_OSX
  82. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + ".atomicgameengine/toolEnv.json";
  83. #elif ATOMIC_PLATFORM_WINDOWS
  84. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + "AtomicGameEngine/toolEnv.json";
  85. #endif
  86. return devConfigFilename_;
  87. }
  88. void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
  89. {
  90. rootSourceDir_ = AddTrailingSlash(sourceDir);
  91. resourceCoreDataDir_ = rootSourceDir_ + "Resources/CoreData";
  92. resourcePlayerDataDir_ = rootSourceDir_ + "Resources/PlayerData";
  93. resourceEditorDataDir_ = rootSourceDir_ + "Resources/EditorData";
  94. toolDataDir_ = rootSourceDir_ + "Data/AtomicEditor/";
  95. }
  96. void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
  97. {
  98. rootBuildDir_ = AddTrailingSlash(buildDir);
  99. if (setBinaryPaths)
  100. {
  101. #ifdef ATOMIC_PLATFORM_WINDOWS
  102. #ifdef _DEBUG
  103. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Debug/AtomicPlayer.exe";
  104. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Debug/AtomicEditor.exe";
  105. #else
  106. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/Application/Release/AtomicPlayer.exe";
  107. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/Release/AtomicEditor.exe";
  108. #endif
  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. }