| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- // before resource system exists so use rapidjson directly
- #include <rapidjson/document.h>
- #include <rapidjson/prettywriter.h>
- #include <rapidjson/filestream.h>
- #include <Atomic/IO/FileSystem.h>
- #include <Atomic/IO/File.h>
- #include "ToolEnvironment.h"
- using namespace rapidjson;
- namespace ToolCore
- {
- ToolEnvironment::ToolEnvironment(Context* context) : Object(context)
- {
- }
- ToolEnvironment::~ToolEnvironment()
- {
- }
- bool ToolEnvironment::InitFromJSON()
- {
- #ifndef ATOMIC_DEV_BUILD
- return false;
- #else
- // make sure config path is initialized
- GetDevConfigFilename();
- FileSystem* fileSystem = GetSubsystem<FileSystem>();
- if (!fileSystem->FileExists(devConfigFilename_))
- return false;
- File jsonFile(context_, devConfigFilename_);
- if (!jsonFile.IsOpen())
- return false;
- String json;
- jsonFile.ReadText(json);
- if (!json.Length())
- return false;
- rapidjson::Document document;
- if (document.Parse<0>(json.CString()).HasParseError())
- {
- return false;
- }
- const Value::Member* rootSourceDir = document.FindMember("rootSourceDir");
- if (rootSourceDir && rootSourceDir->value.IsString())
- SetRootSourceDir(rootSourceDir->value.GetString());
- else
- return false;
- const Value::Member* rootBuildDir = document.FindMember("rootBuildDir");
- if (rootBuildDir && rootBuildDir->value.IsString())
- SetRootBuildDir(rootBuildDir->value.GetString(), true);
- else
- return false;
- return true;
- #endif
- }
- const String& ToolEnvironment::GetDevConfigFilename()
- {
- if (devConfigFilename_.Length())
- return devConfigFilename_;
- FileSystem* fileSystem = GetSubsystem<FileSystem>();
- #ifdef ATOMIC_PLATFORM_OSX
- devConfigFilename_ = fileSystem->GetUserDocumentsDir() + ".atomicgameengine/toolEnv.json";
- #endif
- return devConfigFilename_;
- }
- void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
- {
- rootSourceDir_ = AddTrailingSlash(sourceDir);
- resourceCoreDataDir_ = rootSourceDir_ + "Data/AtomicPlayer/Resources/CoreData";
- resourceEditorDataDir_ = rootSourceDir_ + "Data/AtomicEditor/Resources/EditorData";
- }
- void ToolEnvironment::SetRootBuildDir(const String& buildDir, bool setBinaryPaths)
- {
- rootBuildDir_ = AddTrailingSlash(buildDir);
- if (setBinaryPaths)
- {
- #ifdef ATOMIC_PLATFORM_OSX
- playerBinary_ = rootBuildDir_ + "Source/AtomicPlayer/AtomicPlayer.app/Contents/MacOS/AtomicPlayer";
- editorBinary_ = rootBuildDir_ + "Source/AtomicEditor/AtomicEditor.app/Contents/MacOS/AtomicEditor";
- #endif
- }
- }
- }
|