ToolPrefs.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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.IsObject())
  45. return;
  46. JSONValue androidRoot = root.Get("android");
  47. if (androidRoot.IsObject()) {
  48. androidSDKPath_ = androidRoot.Get("androidSDKPath").GetString();
  49. jdkRootPath_ = androidRoot.Get("jdkRootPath").GetString();
  50. antPath_ = androidRoot.Get("antPath").GetString();
  51. }
  52. }
  53. void ToolPrefs::Save()
  54. {
  55. String path = GetPrefsPath();
  56. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  57. JSONValue root = jsonFile->GetRoot();
  58. SharedPtr<File> file(new File(context_, path, FILE_WRITE));
  59. JSONValue androidRoot;
  60. androidRoot.Set("androidSDKPath", androidSDKPath_);
  61. androidRoot.Set("jdkRootPath", jdkRootPath_);
  62. androidRoot.Set("antPath", antPath_);
  63. root.Set("android", androidRoot);
  64. jsonFile->Save(*file, String(" "));
  65. file->Close();
  66. }
  67. }