Audacity  3.0.3
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
FileConfig Class Referenceabstract

#include <FileConfig.h>

Inheritance diagram for FileConfig:
[legend]
Collaboration diagram for FileConfig:
[legend]

Public Member Functions

 FileConfig (const wxString &appName=wxEmptyString, const wxString &vendorName=wxEmptyString, const wxString &localFilename=wxEmptyString, const wxString &globalFilename=wxEmptyString, long style=wxCONFIG_USE_LOCAL_FILE|wxCONFIG_USE_GLOBAL_FILE, const wxMBConv &conv=wxConvAuto())
 
void Init ()
 
virtual ~FileConfig ()
 
virtual void SetPath (const wxString &strPath) wxOVERRIDE
 
virtual const wxString & GetPath () const wxOVERRIDE
 
virtual bool GetFirstGroup (wxString &str, long &lIndex) const wxOVERRIDE
 
virtual bool GetNextGroup (wxString &str, long &lIndex) const wxOVERRIDE
 
virtual bool GetFirstEntry (wxString &str, long &lIndex) const wxOVERRIDE
 
virtual bool GetNextEntry (wxString &str, long &lIndex) const wxOVERRIDE
 
virtual size_t GetNumberOfEntries (bool bRecursive=false) const wxOVERRIDE
 
virtual size_t GetNumberOfGroups (bool bRecursive=false) const wxOVERRIDE
 
virtual bool HasGroup (const wxString &strName) const wxOVERRIDE
 
virtual bool HasEntry (const wxString &strName) const wxOVERRIDE
 
virtual bool Flush (bool bCurrentOnly=false) wxOVERRIDE
 
virtual bool RenameEntry (const wxString &oldName, const wxString &newName) wxOVERRIDE
 
virtual bool RenameGroup (const wxString &oldName, const wxString &newName) wxOVERRIDE
 
virtual bool DeleteEntry (const wxString &key, bool bDeleteGroupIfEmpty=true) wxOVERRIDE
 
virtual bool DeleteGroup (const wxString &key) wxOVERRIDE
 
virtual bool DeleteAll () wxOVERRIDE
 
void SetVersionKeysInit (int major, int minor, int micro)
 
void GetVersionKeysInit (int &major, int &minor, int &micro) const
 

Protected Member Functions

virtual bool DoReadString (const wxString &key, wxString *pStr) const wxOVERRIDE
 
virtual bool DoReadLong (const wxString &key, long *pl) const wxOVERRIDE
 
virtual bool DoWriteString (const wxString &key, const wxString &szValue) wxOVERRIDE
 
virtual bool DoWriteLong (const wxString &key, long lValue) wxOVERRIDE
 
virtual void Warn ()=0
 Override to notify the user of error conditions involving writability of config files. More...
 
const FilePathGetFilePath () const
 

Private Attributes

const wxString mAppName
 
const wxString mVendorName
 
const wxString mLocalFilename
 
const wxString mGlobalFilename
 
const long mStyle
 
const wxMBConv & mConv
 
std::unique_ptr< wxFileConfig > mConfig
 
int mVersionMajorKeyInit {}
 
int mVersionMinorKeyInit {}
 
int mVersionMicroKeyInit {}
 
bool mDirty
 

Detailed Description

Definition at line 20 of file FileConfig.h.

Constructor & Destructor Documentation

◆ FileConfig()

FileConfig::FileConfig ( const wxString &  appName = wxEmptyString,
const wxString &  vendorName = wxEmptyString,
const wxString &  localFilename = wxEmptyString,
const wxString &  globalFilename = wxEmptyString,
long  style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE,
const wxMBConv &  conv = wxConvAuto() 
)

Definition at line 28 of file FileConfig.cpp.

34 : wxConfigBase(appName, vendorName, localFilename, globalFilename, style),
35  mAppName(appName),
36  mVendorName(vendorName),
37  mLocalFilename(localFilename),
38  mGlobalFilename(globalFilename),
39  mStyle(style),
40  mConv(conv),
41  mDirty(false)
42 {
43 }

◆ ~FileConfig()

FileConfig::~FileConfig ( )
virtual

Definition at line 88 of file FileConfig.cpp.

89 {
90  wxASSERT(mDirty == false);
91 }

References mDirty.

Member Function Documentation

◆ DeleteAll()

bool FileConfig::DeleteAll ( )
virtual

Definition at line 229 of file FileConfig.cpp.

230 {
231  auto res = mConfig->DeleteAll();
232  if (res)
233  {
234  mDirty = true;
235  }
236  return res;
237 }

References mConfig, and mDirty.

Referenced by ResetPreferences().

Here is the caller graph for this function:

◆ DeleteEntry()

bool FileConfig::DeleteEntry ( const wxString &  key,
bool  bDeleteGroupIfEmpty = true 
)
virtual

Definition at line 209 of file FileConfig.cpp.

210 {
211  auto res = mConfig->DeleteEntry(key, bDeleteGroupIfEmpty);
212  if (res)
213  {
214  mDirty = true;
215  }
216  return res;
217 }

References key, mConfig, and mDirty.

Referenced by KeyConfigPrefs::Commit(), TracksPrefs::Commit(), ModuleSettings::GetModuleStatus(), AudacityApp::OnExit(), KeyConfigPrefs::OnImportDefaults(), anonymous_namespace{AudacityApp.cpp}::PopulatePreferences(), PluginManager::RemovePrivateConfig(), PluginManager::RemoveSharedConfig(), ToolBarConfiguration::Write(), and Importer::WriteImportItems().

Here is the caller graph for this function:

◆ DeleteGroup()

bool FileConfig::DeleteGroup ( const wxString &  key)
virtual

Definition at line 219 of file FileConfig.cpp.

220 {
221  auto res = mConfig->DeleteGroup(key);
222  if (res)
223  {
224  mDirty = true;
225  }
226  return res;
227 }

References key, mConfig, and mDirty.

Referenced by TagsEditorDialog::OnSaveDefaults(), anonymous_namespace{AudacityApp.cpp}::PopulatePreferences(), PluginManager::RemovePrivateConfigSubgroup(), and PluginManager::RemoveSharedConfigSubgroup().

Here is the caller graph for this function:

◆ DoReadLong()

bool FileConfig::DoReadLong ( const wxString &  key,
long *  pl 
) const
protectedvirtual

Definition at line 244 of file FileConfig.cpp.

245 {
246  return mConfig->Read(key, pl);
247 }

References key, and mConfig.

◆ DoReadString()

bool FileConfig::DoReadString ( const wxString &  key,
wxString *  pStr 
) const
protectedvirtual

Definition at line 239 of file FileConfig.cpp.

240 {
241  return mConfig->Read(key, pStr);
242 }

References key, and mConfig.

◆ DoWriteLong()

bool FileConfig::DoWriteLong ( const wxString &  key,
long  lValue 
)
protectedvirtual

Definition at line 266 of file FileConfig.cpp.

267 {
268  bool res = mConfig->Write(key, lValue);
269  if (res)
270  {
271  mDirty = true;
272  }
273  return res;
274 }

References key, mConfig, and mDirty.

◆ DoWriteString()

bool FileConfig::DoWriteString ( const wxString &  key,
const wxString &  szValue 
)
protectedvirtual

Definition at line 256 of file FileConfig.cpp.

257 {
258  bool res = mConfig->Write(key, szValue);
259  if (res)
260  {
261  mDirty = true;
262  }
263  return res;
264 }

References key, mConfig, and mDirty.

◆ Flush()

bool FileConfig::Flush ( bool  bCurrentOnly = false)
virtual

Definition at line 143 of file FileConfig.cpp.

144 {
145  if (!mDirty)
146  {
147  return true;
148  }
149 
150  while (true)
151  {
152  FilePath backup = mLocalFilename + ".bkp";
153 
154  if (!wxFileExists(backup) || (wxRemove(backup) == 0))
155  {
156  if (!wxFileExists(mLocalFilename) || (wxRename(mLocalFilename, backup) == 0))
157  {
158  wxFileOutputStream stream(mLocalFilename);
159  if (stream.IsOk())
160  {
161  if (mConfig->Save(stream))
162  {
163  stream.Sync();
164  if (stream.IsOk() && stream.Close())
165  {
166  if (!wxFileExists(backup) || (wxRemove(backup) == 0))
167  {
168  mDirty = false;
169  return true;
170  }
171  }
172  }
173  }
174 
175  if (wxFileExists(backup))
176  {
177  wxRemove(mLocalFilename);
178  wxRename(backup, mLocalFilename);
179  }
180  }
181  }
182 
183  Warn();
184  }
185 
186  return false;
187 }

References mConfig, mDirty, mLocalFilename, and Warn().

Referenced by SetPreferenceCommand::Apply(), ApplyMacroDialog::ApplyMacroToProject(), ProjectSelectionManager::AS_SetSelectionFormat(), ProjectSelectionManager::AS_SetSnapTo(), ScreenshotCommand::CapturePreferences(), DeviceToolBar::ChangeHost(), ExportMP3::CheckFileName(), GUIPrefs::Commit(), KeyConfigPrefs::Commit(), QualityPrefs::Commit(), TracksPrefs::Commit(), ExportMP3::Export(), DeviceToolBar::FillHostDevices(), FindFFmpegLibs(), MP3Exporter::FindLibrary(), AudioIO::Init(), EffectNoiseRemoval::Init(), UpdateManager::IsTimeForUpdatesChecking(), LoadFFmpeg(), EnumSettingBase::Migrate(), SpectrogramSettings::ColorSchemeEnumSetting::Migrate(), TracksViewModeEnumSetting::Migrate(), ViewActions::Handler::OnAdvancedVZoom(), ApplyMacroDialog::OnApplyToFiles(), AdornedRulerPanel::OnAutoScroll(), PrefsDialog::OnCancel(), ScreenshotBigDialog::OnClose(), BrowserDialog::OnClose(), FrequencyPlotDialog::OnCloseButton(), ScreenshotBigDialog::OnCloseWindow(), ScreenshotBigDialog::OnDirChoose(), SplashDialog::OnDontShow(), TagsEditorDialog::OnDontShow(), AudacityApp::OnExit(), ExportMultipleDialog::OnExport(), KeyConfigPrefs::OnImportDefaults(), ExportMP3Options::OnMono(), TrackActions::Handler::OnMoveSelectionWithTracks(), PrefsDialog::OnOK(), ExportFFmpegOptions::OnOK(), SoundActivatedRecordDialog::OnOK(), TagsEditorDialog::OnOk(), TimerRecordDialog::OnOK(), FFmpegNotFoundDialog::OnOk(), MeterPanel::OnPreferences(), PluginActions::Handler::OnResetConfig(), BenchmarkDialog::OnRun(), TagsEditorDialog::OnSaveDefaults(), LabelTrackMenuTable::OnSetFont(), ViewActions::Handler::OnShowClipping(), ViewActions::Handler::OnShowExtraMenus(), ViewActions::Handler::OnShowNameOverlay(), TrackActions::Handler::OnSyncLock(), AdornedRulerPanel::OnSyncSelToQuickPlay(), TransportActions::Handler::OnTogglePlayRecording(), AdornedRulerPanel::OnToggleQuickPlay(), TransportActions::Handler::OnToggleSoundActivated(), TransportActions::Handler::OnToggleSWPlaythrough(), LabelEditActions::Handler::OnToggleTypeToCreateLabel(), ToolsToolBar::OnTool(), FFmpegImportPlugin::Open(), Registry::OrderingPreferenceInitializer::operator()(), anonymous_namespace{HelpMenus.cpp}::QuickFixDialog::PopulateOrExchange(), anonymous_namespace{AudacityApp.cpp}::PopulatePreferences(), EffectNoiseReduction::Settings::PrefsIO(), CommandManager::RemoveDuplicateShortcuts(), PluginManager::RemovePrivateConfig(), PluginManager::RemovePrivateConfigSubgroup(), PluginManager::RemoveSharedConfig(), PluginManager::RemoveSharedConfigSubgroup(), MacrosWindow::SaveChanges(), SaveEncoding(), DependencyDialog::SaveFutureActionChoice(), SaveOtherFormat(), GlobalPrefsDialog::SavePreferredPage(), ProjectManager::SaveWindowSize(), SelectionBar::SelectionModeUpdated(), PluginManager::SetConfig(), ToolsToolBar::SetCurrentTool(), Importer::SetDefaultOpenType(), DeviceToolBar::SetDevices(), Importer::SetLastOpenType(), ModuleSettings::SetModuleStatus(), TracksPrefs::SetPinnedHeadPositionPreference(), TracksPrefs::SetPinnedHeadPreference(), Journal::SetRecordEnabled(), HelpSystem::ShowHelp(), EffectNoiseRemoval::ShowInterface(), ShowWarningDialog(), ProjectSelectionManager::SSBL_SetBandwidthSelectionFormatName(), ProjectSelectionManager::SSBL_SetFrequencySelectionFormatName(), UpdateManager::Start(), EffectAutoDuck::Startup(), EffectChangeSpeed::Startup(), EffectClickRemoval::Startup(), EffectCompressor::Startup(), EffectDtmf::Startup(), EffectEqualization::Startup(), EffectLoudness::Startup(), EffectNoise::Startup(), EffectNormalize::Startup(), EffectScienFilter::Startup(), ExportCLOptions::TransferDataFromWindow(), ExportFFmpegAC3Options::TransferDataFromWindow(), ExportFFmpegAACOptions::TransferDataFromWindow(), ExportFFmpegAMRNBOptions::TransferDataFromWindow(), ExportFFmpegOPUSOptions::TransferDataFromWindow(), ExportFFmpegWMAOptions::TransferDataFromWindow(), ExportFLACOptions::TransferDataFromWindow(), ExportMP3Options::TransferDataFromWindow(), ExportOGGOptions::TransferDataFromWindow(), ProjectSelectionManager::TT_SetAudioTimeFormat(), EffectEqualization::UpdateDefaultCurves(), Registry::Visit(), ToolManager::WriteConfig(), Importer::WriteImportItems(), and LabelDialog::WriteSize().

Here is the call graph for this function:

◆ GetFilePath()

const FilePath& FileConfig::GetFilePath ( ) const
inlineprotected

Definition at line 80 of file FileConfig.h.

80 { return mLocalFilename; }

Referenced by AudacityFileConfig::Warn().

Here is the caller graph for this function:

◆ GetFirstEntry()

bool FileConfig::GetFirstEntry ( wxString &  str,
long &  lIndex 
) const
virtual

Definition at line 113 of file FileConfig.cpp.

114 {
115  return mConfig->GetFirstEntry(str, lIndex);
116 }

References mConfig.

Referenced by ModulePrefs::GetAllModuleStatuses(), and Tags::LoadDefaults().

Here is the caller graph for this function:

◆ GetFirstGroup()

bool FileConfig::GetFirstGroup ( wxString &  str,
long &  lIndex 
) const
virtual

Definition at line 103 of file FileConfig.cpp.

104 {
105  return mConfig->GetFirstGroup(str, lIndex);
106 }

References mConfig.

Referenced by PluginManager::LoadGroup(), and anonymous_namespace{AudacityApp.cpp}::PopulatePreferences().

Here is the caller graph for this function:

◆ GetNextEntry()

bool FileConfig::GetNextEntry ( wxString &  str,
long &  lIndex 
) const
virtual

Definition at line 118 of file FileConfig.cpp.

119 {
120  return mConfig->GetNextEntry(str, lIndex);
121 }

References mConfig.

Referenced by ModulePrefs::GetAllModuleStatuses(), and Tags::LoadDefaults().

Here is the caller graph for this function:

◆ GetNextGroup()

bool FileConfig::GetNextGroup ( wxString &  str,
long &  lIndex 
) const
virtual

Definition at line 108 of file FileConfig.cpp.

109 {
110  return mConfig->GetNextGroup(str, lIndex);
111 }

References mConfig.

Referenced by PluginManager::LoadGroup(), and anonymous_namespace{AudacityApp.cpp}::PopulatePreferences().

Here is the caller graph for this function:

◆ GetNumberOfEntries()

size_t FileConfig::GetNumberOfEntries ( bool  bRecursive = false) const
virtual

Definition at line 123 of file FileConfig.cpp.

124 {
125  return mConfig->GetNumberOfEntries(bRecursive);
126 }

References mConfig.

◆ GetNumberOfGroups()

size_t FileConfig::GetNumberOfGroups ( bool  bRecursive = false) const
virtual

Definition at line 128 of file FileConfig.cpp.

129 {
130  return mConfig->GetNumberOfGroups(bRecursive);
131 }

References mConfig.

◆ GetPath()

const wxString & FileConfig::GetPath ( ) const
virtual

Definition at line 98 of file FileConfig.cpp.

99 {
100  return mConfig->GetPath();
101 }

References mConfig.

Referenced by PluginManager::GetSubgroups(), Tags::LoadDefaults(), anonymous_namespace{AudacityApp.cpp}::PopulatePreferences(), ToolManager::ReadConfig(), and ToolManager::WriteConfig().

Here is the caller graph for this function:

◆ GetVersionKeysInit()

void FileConfig::GetVersionKeysInit ( int &  major,
int &  minor,
int &  micro 
) const
inline

Definition at line 56 of file FileConfig.h.

57  {
58  major = mVersionMajorKeyInit;
59  minor = mVersionMinorKeyInit;
60  micro = mVersionMicroKeyInit;
61  }

Referenced by AudacityApp::InitPart2(), and ToolManager::ReadConfig().

Here is the caller graph for this function:

◆ HasEntry()

bool FileConfig::HasEntry ( const wxString &  strName) const
virtual

Definition at line 138 of file FileConfig.cpp.

139 {
140  return mConfig->HasEntry(strName);
141 }

References mConfig.

Referenced by KeyConfigPrefs::Commit(), and CommandManager::NewIdentifier().

Here is the caller graph for this function:

◆ HasGroup()

bool FileConfig::HasGroup ( const wxString &  strName) const
virtual

Definition at line 133 of file FileConfig.cpp.

134 {
135  return mConfig->HasGroup(strName);
136 }

References mConfig.

◆ Init()

void FileConfig::Init ( )

Definition at line 45 of file FileConfig.cpp.

46 {
47  while (true)
48  {
49  mConfig = std::make_unique<wxFileConfig>
51 
52  // Prevent wxFileConfig from attempting a Flush() during object deletion. This happens
53  // because we don't use the wxFileConfig::Flush() method and so the wxFileConfig dirty
54  // flag never gets reset. During deletion, the dirty flag is checked and a Flush()
55  // performed. This can (and probably will) create bogus temporary files.
56  mConfig->DisableAutoSave();
57 
58  bool canRead = false;
59  bool canWrite = false;
60  int fd;
61 
62  fd = wxOpen(mLocalFilename, O_RDONLY, S_IREAD);
63  if (fd != -1 || errno == ENOENT)
64  {
65  canRead = true;
66  if (fd != -1)
67  {
68  wxClose(fd);
69  }
70  }
71 
72  fd = wxOpen(mLocalFilename, O_WRONLY | O_CREAT, S_IWRITE);
73  if (fd != -1)
74  {
75  canWrite = true;
76  wxClose(fd);
77  }
78 
79  if (canRead && canWrite)
80  {
81  break;
82  }
83 
84  Warn();
85  }
86 }

References mAppName, mConfig, mConv, mGlobalFilename, mLocalFilename, mStyle, mVendorName, and Warn().

Referenced by AudacityFileConfig::Create().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RenameEntry()

bool FileConfig::RenameEntry ( const wxString &  oldName,
const wxString &  newName 
)
virtual

Definition at line 189 of file FileConfig.cpp.

190 {
191  auto res = mConfig->RenameEntry(oldName, newName);
192  if (res)
193  {
194  mDirty = true;
195  }
196  return res;
197 }

References mConfig, and mDirty.

◆ RenameGroup()

bool FileConfig::RenameGroup ( const wxString &  oldName,
const wxString &  newName 
)
virtual

Definition at line 199 of file FileConfig.cpp.

200 {
201  auto res = mConfig->RenameGroup(oldName, newName);
202  if (res)
203  {
204  mDirty = true;
205  }
206  return res;
207 }

References mConfig, and mDirty.

◆ SetPath()

void FileConfig::SetPath ( const wxString &  strPath)
virtual

Definition at line 93 of file FileConfig.cpp.

94 {
95  mConfig->SetPath(strPath);
96 }

References mConfig.

Referenced by ModulePrefs::GetAllModuleStatuses(), PluginManager::GetSubgroups(), Tags::LoadDefaults(), PluginManager::LoadGroup(), CommandManager::NewIdentifier(), anonymous_namespace{AudacityApp.cpp}::PopulatePreferences(), ToolManager::ReadConfig(), PluginManager::SaveGroup(), and ToolManager::WriteConfig().

Here is the caller graph for this function:

◆ SetVersionKeysInit()

void FileConfig::SetVersionKeysInit ( int  major,
int  minor,
int  micro 
)
inline

Definition at line 50 of file FileConfig.h.

51  {
52  mVersionMajorKeyInit = major;
53  mVersionMinorKeyInit = minor;
54  mVersionMicroKeyInit = micro;
55  }

Referenced by anonymous_namespace{AudacityApp.cpp}::PopulatePreferences().

Here is the caller graph for this function:

◆ Warn()

virtual void FileConfig::Warn ( )
protectedpure virtual

Override to notify the user of error conditions involving writability of config files.

Implemented in AudacityFileConfig.

Referenced by Flush(), and Init().

Here is the caller graph for this function:

Member Data Documentation

◆ mAppName

const wxString FileConfig::mAppName
private

Definition at line 83 of file FileConfig.h.

Referenced by Init().

◆ mConfig

std::unique_ptr<wxFileConfig> FileConfig::mConfig
private

◆ mConv

const wxMBConv& FileConfig::mConv
private

Definition at line 88 of file FileConfig.h.

Referenced by Init().

◆ mDirty

bool FileConfig::mDirty
private

◆ mGlobalFilename

const wxString FileConfig::mGlobalFilename
private

Definition at line 86 of file FileConfig.h.

Referenced by Init().

◆ mLocalFilename

const wxString FileConfig::mLocalFilename
private

Definition at line 85 of file FileConfig.h.

Referenced by Flush(), and Init().

◆ mStyle

const long FileConfig::mStyle
private

Definition at line 87 of file FileConfig.h.

Referenced by Init().

◆ mVendorName

const wxString FileConfig::mVendorName
private

Definition at line 84 of file FileConfig.h.

Referenced by Init().

◆ mVersionMajorKeyInit

int FileConfig::mVersionMajorKeyInit {}
private

Definition at line 94 of file FileConfig.h.

◆ mVersionMicroKeyInit

int FileConfig::mVersionMicroKeyInit {}
private

Definition at line 96 of file FileConfig.h.

◆ mVersionMinorKeyInit

int FileConfig::mVersionMinorKeyInit {}
private

Definition at line 95 of file FileConfig.h.


The documentation for this class was generated from the following files:
FileConfig::mDirty
bool mDirty
Definition: FileConfig.h:98
FileConfig::mAppName
const wxString mAppName
Definition: FileConfig.h:83
FileConfig::mVendorName
const wxString mVendorName
Definition: FileConfig.h:84
FileConfig::mLocalFilename
const wxString mLocalFilename
Definition: FileConfig.h:85
FilePath
wxString FilePath
Definition: Project.h:20
FileConfig::mConfig
std::unique_ptr< wxFileConfig > mConfig
Definition: FileConfig.h:90
FileConfig::mVersionMicroKeyInit
int mVersionMicroKeyInit
Definition: FileConfig.h:96
FileConfig::mStyle
const long mStyle
Definition: FileConfig.h:87
FileConfig::mGlobalFilename
const wxString mGlobalFilename
Definition: FileConfig.h:86
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: CommandManager.cpp:201
FileConfig::mVersionMinorKeyInit
int mVersionMinorKeyInit
Definition: FileConfig.h:95
FileConfig::Warn
virtual void Warn()=0
Override to notify the user of error conditions involving writability of config files.
FileConfig::mVersionMajorKeyInit
int mVersionMajorKeyInit
Definition: FileConfig.h:94
FileConfig::mConv
const wxMBConv & mConv
Definition: FileConfig.h:88