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.

juce_ApplicationProperties.cpp 2.8KB

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