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.

127 lines
4.9KB

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