OpenShot Audio Library | OpenShotAudio  0.6.0
juce_PropertiesFile.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2022 - Raw Material Software Limited
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11  Agreement and JUCE Privacy Policy.
12 
13  End User License Agreement: www.juce.com/juce-7-licence
14  Privacy Policy: www.juce.com/juce-privacy-policy
15 
16  Or: You may also use this code under the terms of the GPL v3 (see
17  www.gnu.org/licenses).
18 
19  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21  DISCLAIMED.
22 
23  ==============================================================================
24 */
25 
26 namespace juce
27 {
28 
29 //==============================================================================
45 class JUCE_API PropertiesFile : public PropertySet,
46  public ChangeBroadcaster,
47  private Timer
48 {
49 public:
50  //==============================================================================
51  enum StorageFormat
52  {
53  storeAsBinary,
54  storeAsCompressedBinary,
55  storeAsXML
56  };
57 
58  //==============================================================================
60  struct JUCE_API Options
61  {
65  Options();
66 
70 
80 
85 
105 
110 
116 
118  bool doNotSave;
119 
129 
134  StorageFormat storageFormat;
135 
144 
162  File getDefaultFile() const;
163  };
164 
165  //==============================================================================
170  explicit PropertiesFile (const Options& options);
171 
176  PropertiesFile (const File& file,
177  const Options& options);
178 
182  ~PropertiesFile() override;
183 
184  //==============================================================================
189  bool isValidFile() const noexcept { return loadedOk; }
190 
191  //==============================================================================
200  bool saveIfNeeded();
201 
210  bool save();
211 
216  bool needsToBeSaved() const;
217 
221  void setNeedsToBeSaved (bool needsToBeSaved);
222 
224  bool reload();
225 
226  //==============================================================================
228  const File& getFile() const noexcept { return file; }
229 
230 
231 protected:
233  void propertyChanged() override;
234 
235 private:
236  //==============================================================================
237  File file;
238  Options options;
239  bool loadedOk = false, needsWriting = false;
240 
241  using ProcessScopedLock = const std::unique_ptr<InterProcessLock::ScopedLockType>;
242  InterProcessLock::ScopedLockType* createProcessLock() const;
243 
244  void timerCallback() override;
245  bool saveAsXml();
246  bool saveAsBinary();
247  bool loadAsXml();
248  bool loadAsBinary();
249  bool loadAsBinary (InputStream&);
250  bool writeToStream (OutputStream&);
251 
252  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertiesFile)
253 };
254 
255 } // namespace juce
const File & getFile() const noexcept
bool isValidFile() const noexcept