OpenShot Audio Library | OpenShotAudio  0.3.2
juce_PropertiesFile.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2017 - ROLI Ltd.
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 5 End-User License
11  Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
12  27th April 2017).
13 
14  End User License Agreement: www.juce.com/juce-5-licence
15  Privacy Policy: www.juce.com/juce-5-privacy-policy
16 
17  Or: You may also use this code under the terms of the GPL v3 (see
18  www.gnu.org/licenses).
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
46 class JUCE_API PropertiesFile : public PropertySet,
47  public ChangeBroadcaster,
48  private Timer
49 {
50 public:
51  //==============================================================================
52  enum StorageFormat
53  {
54  storeAsBinary,
55  storeAsCompressedBinary,
56  storeAsXML
57  };
58 
59  //==============================================================================
61  struct JUCE_API Options
62  {
66  Options();
67 
71 
81 
86 
106 
111 
117 
119  bool doNotSave;
120 
130 
135  StorageFormat storageFormat;
136 
145 
163  File getDefaultFile() const;
164  };
165 
166  //==============================================================================
171  explicit PropertiesFile (const Options& options);
172 
177  PropertiesFile (const File& file,
178  const Options& options);
179 
183  ~PropertiesFile() override;
184 
185  //==============================================================================
190  bool isValidFile() const noexcept { return loadedOk; }
191 
192  //==============================================================================
201  bool saveIfNeeded();
202 
211  bool save();
212 
217  bool needsToBeSaved() const;
218 
222  void setNeedsToBeSaved (bool needsToBeSaved);
223 
225  bool reload();
226 
227  //==============================================================================
229  const File& getFile() const noexcept { return file; }
230 
231 
232 protected:
234  void propertyChanged() override;
235 
236 private:
237  //==============================================================================
238  File file;
239  Options options;
240  bool loadedOk = false, needsWriting = false;
241 
242  using ProcessScopedLock = const std::unique_ptr<InterProcessLock::ScopedLockType>;
243  InterProcessLock::ScopedLockType* createProcessLock() const;
244 
245  void timerCallback() override;
246  bool saveAsXml();
247  bool saveAsBinary();
248  bool loadAsXml();
249  bool loadAsBinary();
250  bool loadAsBinary (InputStream&);
251  bool writeToStream (OutputStream&);
252 
253  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PropertiesFile)
254 };
255 
256 } // namespace juce
const File & getFile() const noexcept
bool isValidFile() const noexcept