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.

131 lines
5.1KB

  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. #pragma once
  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. */
  34. class JUCE_API ApplicationProperties
  35. {
  36. public:
  37. //==============================================================================
  38. /**
  39. Creates an ApplicationProperties object.
  40. Before using it, you must call setStorageParameters() to give it the info
  41. it needs to create the property files.
  42. */
  43. ApplicationProperties();
  44. /** Destructor. */
  45. ~ApplicationProperties();
  46. //==============================================================================
  47. /** Gives the object the information it needs to create the appropriate properties files.
  48. See the PropertiesFile::Options class for details about what options you need to set.
  49. */
  50. void setStorageParameters (const PropertiesFile::Options& options);
  51. /** Returns the current storage parameters.
  52. @see setStorageParameters
  53. */
  54. const PropertiesFile::Options& getStorageParameters() const noexcept { return options; }
  55. //==============================================================================
  56. /** Returns the user settings file.
  57. The first time this is called, it will create and load the properties file.
  58. Note that when you search the user PropertiesFile for a value that it doesn't contain,
  59. the common settings are used as a second-chance place to look. This is done via the
  60. PropertySet::setFallbackPropertySet() method - by default the common settings are set
  61. to the fallback for the user settings.
  62. @see getCommonSettings
  63. */
  64. PropertiesFile* getUserSettings();
  65. /** Returns the common settings file.
  66. The first time this is called, it will create and load the properties file.
  67. @param returnUserPropsIfReadOnly if this is true, and the common properties file is
  68. read-only (e.g. because the user doesn't have permission to write
  69. to shared files), then this will return the user settings instead,
  70. (like getUserSettings() would do). This is handy if you'd like to
  71. write a value to the common settings, but if that's no possible,
  72. then you'd rather write to the user settings than none at all.
  73. If returnUserPropsIfReadOnly is false, this method will always return
  74. the common settings, even if any changes to them can't be saved.
  75. @see getUserSettings
  76. */
  77. PropertiesFile* getCommonSettings (bool returnUserPropsIfReadOnly);
  78. //==============================================================================
  79. /** Saves both files if they need to be saved.
  80. @see PropertiesFile::saveIfNeeded
  81. */
  82. bool saveIfNeeded();
  83. /** Flushes and closes both files if they are open.
  84. This flushes any pending changes to disk with PropertiesFile::saveIfNeeded()
  85. and closes both files. They will then be re-opened the next time getUserSettings()
  86. or getCommonSettings() is called.
  87. */
  88. void closeFiles();
  89. private:
  90. //==============================================================================
  91. PropertiesFile::Options options;
  92. ScopedPointer<PropertiesFile> userProps, commonProps;
  93. int commonSettingsAreReadOnly;
  94. void openFiles();
  95. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ApplicationProperties)
  96. };