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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  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 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. namespace juce
  20. {
  21. //==============================================================================
  22. /**
  23. Manages a collection of properties.
  24. This is a slightly higher-level wrapper for managing PropertiesFile objects.
  25. It holds two different PropertiesFile objects internally, one for user-specific
  26. settings (stored in your user directory), and one for settings that are common to
  27. all users (stored in a folder accessible to all users).
  28. The class manages the creation of these files on-demand, allowing access via the
  29. getUserSettings() and getCommonSettings() methods.
  30. After creating an instance of an ApplicationProperties object, you should first
  31. of all call setStorageParameters() to tell it the parameters to use to create
  32. its files.
  33. @see PropertiesFile
  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. ScopedPointer<PropertiesFile> userProps, commonProps;
  94. int commonSettingsAreReadOnly;
  95. void openFiles();
  96. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ApplicationProperties)
  97. };
  98. } // namespace juce