ProjectUserPrefs.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "ProjectUserPrefs.h"
  2. #include <Atomic/IO/File.h>
  3. #include <Atomic/Resource/JSONFile.h>
  4. namespace ToolCore
  5. {
  6. ProjectUserPrefs::ProjectUserPrefs(Context* context) : Object(context)
  7. {
  8. #ifdef ATOMIC_PLATFORM_OSX
  9. defaultPlatform_ = PLATFORMID_MAC;
  10. #else
  11. defaultPlatform_ = PLATFORMID_WINDOWS;
  12. #endif
  13. }
  14. ProjectUserPrefs::~ProjectUserPrefs()
  15. {
  16. }
  17. bool ProjectUserPrefs::Load(const String& path)
  18. {
  19. SharedPtr<File> file(new File(context_, path));
  20. if (!file->IsOpen())
  21. return false;
  22. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  23. bool result = jsonFile->Load(*file);
  24. file->Close();
  25. if (!result)
  26. return false;
  27. JSONValue root = jsonFile->GetRoot();
  28. if (root == JSONValue::EMPTY)
  29. return false;
  30. lastBuildPath_ = root.GetString("lastBuildPath");
  31. return true;
  32. }
  33. void ProjectUserPrefs::Save(const String& path)
  34. {
  35. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  36. JSONValue root = jsonFile->CreateRoot();
  37. SharedPtr<File> file(new File(context_, path, FILE_WRITE));
  38. root.SetString("lastBuildPath", lastBuildPath_);
  39. jsonFile->Save(*file, String(" "));
  40. file->Close();
  41. }
  42. }