ToolPrefs.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 <Atomic/IO/Log.h>
  8. #include <Atomic/IO/File.h>
  9. #include <Atomic/IO/FileSystem.h>
  10. #include <Atomic/Resource/JSONFile.h>
  11. #include "ToolPrefs.h"
  12. namespace ToolCore
  13. {
  14. ToolPrefs::ToolPrefs(Context* context) : Object(context)
  15. {
  16. }
  17. ToolPrefs::~ToolPrefs()
  18. {
  19. }
  20. const String& ToolPrefs::GetAntPath()
  21. {
  22. #ifdef ATOMIC_PLATFORM_OSX
  23. static String defaultAntPath("/usr/local/bin/ant");
  24. if (!antPath_.Length())
  25. return defaultAntPath;
  26. return antPath_;
  27. #else
  28. return antPath_;
  29. #endif
  30. }
  31. String ToolPrefs::GetPrefsPath()
  32. {
  33. FileSystem* fs = GetSubsystem<FileSystem>();
  34. String path = fs->GetAppPreferencesDir("AtomicGameEngine", "ToolCore");
  35. path += "ToolPrefs.json";
  36. return path;
  37. }
  38. void ToolPrefs::Load()
  39. {
  40. String path = GetPrefsPath();
  41. SharedPtr<File> file(new File(context_, path));
  42. if (!file->IsOpen())
  43. return;
  44. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  45. bool result = jsonFile->Load(*file);
  46. file->Close();
  47. if (!result)
  48. return;
  49. JSONValue root = jsonFile->GetRoot();
  50. if (!root.IsObject())
  51. return;
  52. JSONValue androidRoot = root.Get("android");
  53. if (androidRoot.IsObject()) {
  54. androidSDKPath_ = androidRoot.Get("androidSDKPath").GetString();
  55. jdkRootPath_ = androidRoot.Get("jdkRootPath").GetString();
  56. antPath_ = androidRoot.Get("antPath").GetString();
  57. }
  58. }
  59. void ToolPrefs::Save()
  60. {
  61. String path = GetPrefsPath();
  62. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  63. JSONValue root = jsonFile->GetRoot();
  64. SharedPtr<File> file(new File(context_, path, FILE_WRITE));
  65. JSONValue androidRoot;
  66. androidRoot.Set("androidSDKPath", androidSDKPath_);
  67. androidRoot.Set("jdkRootPath", jdkRootPath_);
  68. androidRoot.Set("antPath", antPath_);
  69. root.Set("android", androidRoot);
  70. jsonFile->Save(*file, String(" "));
  71. file->Close();
  72. }
  73. }