ToolEnvironment.cpp 4.1 KB

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