ToolEnvironment.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/FileSystem.h>
  6. #include <Atomic/IO/File.h>
  7. #include "ToolEnvironment.h"
  8. using namespace rapidjson;
  9. namespace ToolCore
  10. {
  11. ToolEnvironment::ToolEnvironment(Context* context) : Object(context)
  12. {
  13. }
  14. ToolEnvironment::~ToolEnvironment()
  15. {
  16. }
  17. bool ToolEnvironment::InitFromJSON()
  18. {
  19. #ifndef ATOMIC_DEV_BUILD
  20. return false;
  21. #else
  22. // make sure config path is initialized
  23. GetDevConfigFilename();
  24. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  25. if (!fileSystem->FileExists(devConfigFilename_))
  26. return false;
  27. File jsonFile(context_, devConfigFilename_);
  28. if (!jsonFile.IsOpen())
  29. return false;
  30. String json;
  31. jsonFile.ReadText(json);
  32. if (!json.Length())
  33. return false;
  34. rapidjson::Document document;
  35. if (document.Parse<0>(json.CString()).HasParseError())
  36. {
  37. return false;
  38. }
  39. const Value::Member* rootSourceDir = document.FindMember("rootSourceDir");
  40. if (rootSourceDir && rootSourceDir->value.IsString())
  41. SetRootSourceDir(rootSourceDir->value.GetString());
  42. else
  43. return false;
  44. const Value::Member* rootBuildDir = document.FindMember("rootBuildDir");
  45. if (rootBuildDir && rootBuildDir->value.IsString())
  46. SetRootBuildDir(rootBuildDir->value.GetString(), true);
  47. else
  48. return false;
  49. return true;
  50. #endif
  51. }
  52. const String& ToolEnvironment::GetDevConfigFilename()
  53. {
  54. if (devConfigFilename_.Length())
  55. return devConfigFilename_;
  56. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  57. #ifdef ATOMIC_PLATFORM_OSX
  58. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + ".atomicgameengine/toolEnv.json";
  59. #elif ATOMIC_PLATFORM_WINDOWS
  60. devConfigFilename_ = fileSystem->GetUserDocumentsDir() + "AtomicGameEngine/toolEnv.json";
  61. #endif
  62. return devConfigFilename_;
  63. }
  64. void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
  65. {
  66. rootSourceDir_ = AddTrailingSlash(sourceDir);
  67. resourceCoreDataDir_ = rootSourceDir_ + "Data/AtomicPlayer/Resources/CoreData";
  68. resourcePlayerDataDir_ = rootSourceDir_ + "Data/AtomicPlayer/Resources/PlayerData";
  69. resourceEditorDataDir_ = rootSourceDir_ + "Data/AtomicEditor/Resources/EditorData";
  70. }
  71. void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
  72. {
  73. rootBuildDir_ = AddTrailingSlash(buildDir);
  74. if (setBinaryPaths)
  75. {
  76. #ifdef ATOMIC_PLATFORM_OSX
  77. playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
  78. editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.app/Contents/MacOS/AtomicEditor";
  79. #endif
  80. }
  81. }
  82. }