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.

134 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2020 - 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 6 End-User License
  8. Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
  9. End User License Agreement: www.juce.com/juce-6-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. //==============================================================================
  21. /**
  22. Manages a collection of properties.
  23. This is a slightly higher-level wrapper for managing PropertiesFile objects.
  24. It holds two different PropertiesFile objects internally, one for user-specific
  25. settings (stored in your user directory), and one for settings that are common to
  26. all users (stored in a folder accessible to all users).
  27. The class manages the creation of these files on-demand, allowing access via the
  28. getUserSettings() and getCommonSettings() methods.
  29. After creating an instance of an ApplicationProperties object, you should first
  30. of all call setStorageParameters() to tell it the parameters to use to create
  31. its files.
  32. @see PropertiesFile
  33. @tags{DataStructures}
  34. */
  35. class JUCE_API ApplicationProperties
  36. {
  37. public:
  38. //==============================================================================
  39. /**
  40. Creates an ApplicationProperties object.
  41. Before using it, you must call setStorageParameters() to give it the info
  42. it needs to create the property files.
  43. */
  44. ApplicationProperties();
  45. /** Destructor. */
  46. ~ApplicationProperties();
  47. //==============================================================================
  48. /** Gives the object the information it needs to create the appropriate properties files.
  49. See the PropertiesFile::Options class for details about what options you need to set.
  50. */
  51. void setStorageParameters (const PropertiesFile::Options& options);
  52. /** Returns the current storage parameters.
  53. @see setStorageParameters
  54. */
  55. const PropertiesFile::Options& getStorageParameters() const noexcept { return options; }
  56. //==============================================================================
  57. /** Returns the user settings file.
  58. The first time this is called, it will create and load the properties file.
  59. Note that when you search the user PropertiesFile for a value that it doesn't contain,
  60. the common settings are used as a second-chance place to look. This is done via the
  61. PropertySet::setFallbackPropertySet() method - by default the common settings are set
  62. to the fallback for the user settings.
  63. @see getCommonSettings
  64. */
  65. PropertiesFile* getUserSettings();
  66. /** Returns the common settings file.
  67. The first time this is called, it will create and load the properties file.
  68. @param returnUserPropsIfReadOnly if this is true, and the common properties file is
  69. read-only (e.g. because the user doesn't have permission to write
  70. to shared files), then this will return the user settings instead,
  71. (like getUserSettings() would do). This is handy if you'd like to
  72. write a value to the common settings, but if that's no possible,
  73. then you'd rather write to the user settings than none at all.
  74. If returnUserPropsIfReadOnly is false, this method will always return
  75. the common settings, even if any changes to them can't be saved.
  76. @see getUserSettings
  77. */
  78. PropertiesFile* getCommonSettings (bool returnUserPropsIfReadOnly);
  79. //==============================================================================
  80. /** Saves both files if they need to be saved.
  81. @see PropertiesFile::saveIfNeeded
  82. */
  83. bool saveIfNeeded();
  84. /** Flushes and closes both files if they are open.
  85. This flushes any pending changes to disk with PropertiesFile::saveIfNeeded()
  86. and closes both files. They will then be re-opened the next time getUserSettings()
  87. or getCommonSettings() is called.
  88. */
  89. void closeFiles();
  90. private:
  91. //==============================================================================
  92. PropertiesFile::Options options;
  93. std::unique_ptr<PropertiesFile> userProps, commonProps;
  94. int commonSettingsAreReadOnly = 0;
  95. void openFiles();
  96. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ApplicationProperties)
  97. };
  98. } // namespace juce