ToolPrefs.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. // Check that the tool prefs file exists
  42. FileSystem* fs = GetSubsystem<FileSystem>();
  43. if (!fs->FileExists(path))
  44. return;
  45. SharedPtr<File> file(new File(context_, path));
  46. if (!file->IsOpen())
  47. return;
  48. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  49. bool result = jsonFile->Load(*file);
  50. file->Close();
  51. if (!result)
  52. return;
  53. JSONValue root = jsonFile->GetRoot();
  54. if (!root.IsObject())
  55. return;
  56. JSONValue androidRoot = root.Get("android");
  57. if (androidRoot.IsObject()) {
  58. androidSDKPath_ = androidRoot.Get("androidSDKPath").GetString();
  59. jdkRootPath_ = androidRoot.Get("jdkRootPath").GetString();
  60. antPath_ = androidRoot.Get("antPath").GetString();
  61. }
  62. }
  63. void ToolPrefs::Save()
  64. {
  65. String path = GetPrefsPath();
  66. SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
  67. JSONValue root = jsonFile->GetRoot();
  68. SharedPtr<File> file(new File(context_, path, FILE_WRITE));
  69. JSONValue androidRoot;
  70. androidRoot.Set("androidSDKPath", androidSDKPath_);
  71. androidRoot.Set("jdkRootPath", jdkRootPath_);
  72. androidRoot.Set("antPath", antPath_);
  73. root.Set("android", androidRoot);
  74. jsonFile->Save(*file, String(" "));
  75. file->Close();
  76. }
  77. }