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.h 5.3KB

9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_APPLICATIONPROPERTIES_H_INCLUDED
  18. #define JUCE_APPLICATIONPROPERTIES_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Manages a collection of properties.
  22. This is a slightly higher-level wrapper for managing PropertiesFile objects.
  23. It holds two different PropertiesFile objects internally, one for user-specific
  24. settings (stored in your user directory), and one for settings that are common to
  25. all users (stored in a folder accessible to all users).
  26. The class manages the creation of these files on-demand, allowing access via the
  27. getUserSettings() and getCommonSettings() methods.
  28. After creating an instance of an ApplicationProperties object, you should first
  29. of all call setStorageParameters() to tell it the parameters to use to create
  30. its files.
  31. @see PropertiesFile
  32. */
  33. class JUCE_API ApplicationProperties
  34. {
  35. public:
  36. //==============================================================================
  37. /**
  38. Creates an ApplicationProperties object.
  39. Before using it, you must call setStorageParameters() to give it the info
  40. it needs to create the property files.
  41. */
  42. ApplicationProperties();
  43. /** Destructor. */
  44. ~ApplicationProperties();
  45. //==============================================================================
  46. /** Gives the object the information it needs to create the appropriate properties files.
  47. See the PropertiesFile::Options class for details about what options you need to set.
  48. */
  49. void setStorageParameters (const PropertiesFile::Options& options);
  50. /** Returns the current storage parameters.
  51. @see setStorageParameters
  52. */
  53. const PropertiesFile::Options& getStorageParameters() const noexcept { return options; }
  54. //==============================================================================
  55. /** Returns the user settings file.
  56. The first time this is called, it will create and load the properties file.
  57. Note that when you search the user PropertiesFile for a value that it doesn't contain,
  58. the common settings are used as a second-chance place to look. This is done via the
  59. PropertySet::setFallbackPropertySet() method - by default the common settings are set
  60. to the fallback for the user settings.
  61. @see getCommonSettings
  62. */
  63. PropertiesFile* getUserSettings();
  64. /** Returns the common settings file.
  65. The first time this is called, it will create and load the properties file.
  66. @param returnUserPropsIfReadOnly if this is true, and the common properties file is
  67. read-only (e.g. because the user doesn't have permission to write
  68. to shared files), then this will return the user settings instead,
  69. (like getUserSettings() would do). This is handy if you'd like to
  70. write a value to the common settings, but if that's no possible,
  71. then you'd rather write to the user settings than none at all.
  72. If returnUserPropsIfReadOnly is false, this method will always return
  73. the common settings, even if any changes to them can't be saved.
  74. @see getUserSettings
  75. */
  76. PropertiesFile* getCommonSettings (bool returnUserPropsIfReadOnly);
  77. //==============================================================================
  78. /** Saves both files if they need to be saved.
  79. @see PropertiesFile::saveIfNeeded
  80. */
  81. bool saveIfNeeded();
  82. /** Flushes and closes both files if they are open.
  83. This flushes any pending changes to disk with PropertiesFile::saveIfNeeded()
  84. and closes both files. They will then be re-opened the next time getUserSettings()
  85. or getCommonSettings() is called.
  86. */
  87. void closeFiles();
  88. private:
  89. //==============================================================================
  90. PropertiesFile::Options options;
  91. ScopedPointer<PropertiesFile> userProps, commonProps;
  92. int commonSettingsAreReadOnly;
  93. void openFiles();
  94. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ApplicationProperties)
  95. };
  96. #endif // JUCE_APPLICATIONPROPERTIES_H_INCLUDED