Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.6KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. ApplicationProperties::ApplicationProperties()
  16. {
  17. }
  18. ApplicationProperties::~ApplicationProperties()
  19. {
  20. closeFiles();
  21. }
  22. //==============================================================================
  23. void ApplicationProperties::setStorageParameters (const PropertiesFile::Options& newOptions)
  24. {
  25. options = newOptions;
  26. }
  27. //==============================================================================
  28. void ApplicationProperties::openFiles()
  29. {
  30. // You need to call setStorageParameters() before trying to get hold of the properties!
  31. jassert (options.applicationName.isNotEmpty());
  32. if (options.applicationName.isNotEmpty())
  33. {
  34. PropertiesFile::Options o (options);
  35. if (userProps == nullptr)
  36. {
  37. o.commonToAllUsers = false;
  38. userProps.reset (new PropertiesFile (o));
  39. }
  40. if (commonProps == nullptr)
  41. {
  42. o.commonToAllUsers = true;
  43. commonProps.reset (new PropertiesFile (o));
  44. }
  45. userProps->setFallbackPropertySet (commonProps.get());
  46. }
  47. }
  48. PropertiesFile* ApplicationProperties::getUserSettings()
  49. {
  50. if (userProps == nullptr)
  51. openFiles();
  52. return userProps.get();
  53. }
  54. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly)
  55. {
  56. if (commonProps == nullptr)
  57. openFiles();
  58. if (returnUserPropsIfReadOnly)
  59. {
  60. if (commonSettingsAreReadOnly == 0)
  61. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  62. if (commonSettingsAreReadOnly > 0)
  63. return userProps.get();
  64. }
  65. return commonProps.get();
  66. }
  67. bool ApplicationProperties::saveIfNeeded()
  68. {
  69. return (userProps == nullptr || userProps->saveIfNeeded())
  70. && (commonProps == nullptr || commonProps->saveIfNeeded());
  71. }
  72. void ApplicationProperties::closeFiles()
  73. {
  74. userProps.reset();
  75. commonProps.reset();
  76. }
  77. } // namespace juce