ProjectUserPrefs.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #include "ProjectUserPrefs.h"
  8. #include <Atomic/IO/File.h>
  9. #include <Atomic/Resource/JSONFile.h>
  10. namespace ToolCore
  11. {
  12. ProjectUserPrefs::ProjectUserPrefs(Context* context) : Object(context)
  13. {
  14. #ifdef ATOMIC_PLATFORM_OSX
  15. defaultPlatform_ = PLATFORMID_MAC;
  16. #else
  17. defaultPlatform_ = PLATFORMID_WINDOWS;
  18. #endif
  19. }
  20. ProjectUserPrefs::~ProjectUserPrefs()
  21. {
  22. }
  23. bool ProjectUserPrefs::Load(const String& path)
  24. {
  25. SharedPtr<File> file(new File(context_, path));
  26. if (!file->IsOpen())
  27. return false;
  28. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  29. bool result = jsonFile->Load(*file);
  30. file->Close();
  31. if (!result)
  32. return false;
  33. JSONValue& root = jsonFile->GetRoot();
  34. if (!root.IsObject())
  35. return false;
  36. lastBuildPath_ = root.Get("lastBuildPath").GetString();
  37. return true;
  38. }
  39. void ProjectUserPrefs::Save(const String& path)
  40. {
  41. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  42. JSONValue& root = jsonFile->GetRoot();
  43. SharedPtr<File> file(new File(context_, path, FILE_WRITE));
  44. root.Set("lastBuildPath", lastBuildPath_);
  45. jsonFile->Save(*file, String(" "));
  46. file->Close();
  47. }
  48. }