ToolEnvironment.cpp 5.1 KB

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