ToolPrefs.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include <Atomic/IO/Log.h>
  2. #include <Atomic/IO/File.h>
  3. #include <Atomic/IO/FileSystem.h>
  4. #include <Atomic/Resource/JSONFile.h>
  5. #include "ToolPrefs.h"
  6. namespace ToolCore
  7. {
  8. ToolPrefs::ToolPrefs(Context* context) : Object(context)
  9. {
  10. }
  11. ToolPrefs::~ToolPrefs()
  12. {
  13. }
  14. String ToolPrefs::GetPrefsPath()
  15. {
  16. FileSystem* fs = GetSubsystem<FileSystem>();
  17. String path = fs->GetAppPreferencesDir("AtomicGameEngine", "ToolCore");
  18. path += "ToolPrefs.json";
  19. return path;
  20. }
  21. void ToolPrefs::Load()
  22. {
  23. String path = GetPrefsPath();
  24. SharedPtr<File> file(new File(context_, path));
  25. if (!file->IsOpen())
  26. return;
  27. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  28. bool result = jsonFile->Load(*file);
  29. file->Close();
  30. if (!result)
  31. return;
  32. JSONValue root = jsonFile->GetRoot();
  33. if (root == JSONValue::EMPTY)
  34. return;
  35. JSONValue androidRoot = root.GetChild("android");
  36. if (androidRoot.IsObject()) {
  37. androidSDKPath_ = androidRoot.GetString("androidSDKPath");
  38. jdkRootPath_ = androidRoot.GetString("jdkRootPath");
  39. antPath_ = androidRoot.GetString("antPath");
  40. }
  41. }
  42. void ToolPrefs::Save()
  43. {
  44. String path = GetPrefsPath();
  45. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  46. JSONValue root = jsonFile->CreateRoot();
  47. SharedPtr<File> file(new File(context_, path, FILE_WRITE));
  48. JSONValue androidRoot = root.CreateChild("android");
  49. androidRoot.SetString("androidSDKPath", androidSDKPath_);
  50. androidRoot.SetString("jdkRootPath", jdkRootPath_);
  51. androidRoot.SetString("antPath", antPath_);
  52. jsonFile->Save(*file, String(" "));
  53. file->Close();
  54. }
  55. }