ToolPrefs.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. const String& ToolPrefs::GetAntPath()
  15. {
  16. #ifdef ATOMIC_PLATFORM_OSX
  17. static String defaultAntPath("/usr/local/bin/ant");
  18. if (!antPath_.Length())
  19. return defaultAntPath;
  20. return antPath_;
  21. #else
  22. return antPath_;
  23. #endif
  24. }
  25. String ToolPrefs::GetPrefsPath()
  26. {
  27. FileSystem* fs = GetSubsystem<FileSystem>();
  28. String path = fs->GetAppPreferencesDir("AtomicGameEngine", "ToolCore");
  29. path += "ToolPrefs.json";
  30. return path;
  31. }
  32. void ToolPrefs::Load()
  33. {
  34. String path = GetPrefsPath();
  35. SharedPtr<File> file(new File(context_, path));
  36. if (!file->IsOpen())
  37. return;
  38. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  39. bool result = jsonFile->Load(*file);
  40. file->Close();
  41. if (!result)
  42. return;
  43. JSONValue root = jsonFile->GetRoot();
  44. if (root == JSONValue::EMPTY)
  45. return;
  46. JSONValue androidRoot = root.GetChild("android");
  47. if (androidRoot.IsObject()) {
  48. androidSDKPath_ = androidRoot.GetString("androidSDKPath");
  49. jdkRootPath_ = androidRoot.GetString("jdkRootPath");
  50. antPath_ = androidRoot.GetString("antPath");
  51. }
  52. }
  53. void ToolPrefs::Save()
  54. {
  55. String path = GetPrefsPath();
  56. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  57. JSONValue root = jsonFile->CreateRoot();
  58. SharedPtr<File> file(new File(context_, path, FILE_WRITE));
  59. JSONValue androidRoot = root.CreateChild("android");
  60. androidRoot.SetString("androidSDKPath", androidSDKPath_);
  61. androidRoot.SetString("jdkRootPath", jdkRootPath_);
  62. androidRoot.SetString("antPath", antPath_);
  63. jsonFile->Save(*file, String(" "));
  64. file->Close();
  65. }
  66. }