ToolEnvironment.cpp 4.9 KB

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