Audacity 3.2.0
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
FileConfig Class Reference

#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 ()
 
const FilePathGetFilePath () const
 

Private Attributes

const wxString mAppName
 
const wxString mVendorName
 
const wxString mLocalFilename
 
const wxString mGlobalFilename
 
const long mStyle
 
std::unique_ptr< 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.Clone()),//pass to Init() instead?
41 mDirty(false)
42{
43}
const wxString mVendorName
Definition: FileConfig.h:85
bool mDirty
Definition: FileConfig.h:99
const wxString mGlobalFilename
Definition: FileConfig.h:87
const long mStyle
Definition: FileConfig.h:88
const wxString mAppName
Definition: FileConfig.h:84
std::unique_ptr< wxMBConv > mConv
Definition: FileConfig.h:89
const wxString mLocalFilename
Definition: FileConfig.h:86

◆ ~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}
std::unique_ptr< wxFileConfig > mConfig
Definition: FileConfig.h:91

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}
static const AudacityProject::AttachedObjects::RegisteredFactory key

References key, mConfig, and mDirty.

Referenced by KeyConfigPrefs::Commit(), ModuleSettings::GetModuleStatus(), AudacityApp::OnExit(), KeyConfigPrefs::OnImportDefaults(), anonymous_namespace{AudacityApp.cpp}::PopulatePreferences(), PluginManager::RemoveConfig(), 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(), and PluginManager::RemoveConfigSubgroup().

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}
wxString FilePath
Definition: Project.h:21
virtual void Warn()
Definition: FileConfig.cpp:288

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

Referenced by SetPreferenceCommand::Apply(), ApplyMacroDialog::ApplyMacroToProject(), ProjectSelectionManager::AS_SetSelectionFormat(), AudacityApp::AssociateFileTypes(), ScreenshotCommand::CapturePreferences(), DeviceToolBar::ChangeHost(), AudioSetupToolBar::ChangeHost(), ExportMP3::CheckFileName(), cloud::audiocom::UserService::ClearUserData(), SettingTransaction::Commit(), DevicePrefs::Commit(), GUIPrefs::Commit(), KeyConfigPrefs::Commit(), TracksPrefs::Commit(), cloud::audiocom::OAuthService::DoAuthorise(), ToolsToolBar::DoToolChanged(), cloud::audiocom::UserService::DownloadAvatar(), AudioSetupToolBar::FillHostDevices(), DeviceToolBar::FillHostDevices(), MP3Exporter::FindLibrary(), AudioIO::Init(), EffectNoiseRemoval::Init(), MP3ExportProcessor::Initialize(), UpdateManager::IsTimeForUpdatesChecking(), LoadFFmpeg(), EnumSettingBase::Migrate(), SpectrogramSettings::ColorSchemeEnumSetting::Migrate(), TracksViewModeEnumSetting::Migrate(), ViewActions::Handler::OnAdvancedVZoom(), ApplyMacroDialog::OnApplyToFiles(), AdornedRulerPanel::OnAutoScroll(), PrefsDialog::OnCancel(), BrowserDialog::OnClose(), ScreenshotBigDialog::OnClose(), FrequencyPlotDialog::OnCloseButton(), ScreenshotBigDialog::OnCloseWindow(), AudioPasteDialog::OnContinue(), ScreenshotBigDialog::OnDirChoose(), SplashDialog::OnDontShow(), AudacityApp::OnExit(), KeyConfigPrefs::OnImportDefaults(), anonymous_namespace{TrackMenus.cpp}::OnMoveSelectionWithTracks(), PrefsDialog::OnOK(), ExportFFmpegOptions::OnOK(), SoundActivatedRecordDialog::OnOK(), TagsEditorDialog::OnOk(), TimerRecordDialog::OnOK(), FFmpegNotFoundDialog::OnOk(), MeterPanel::OnPreferences(), anonymous_namespace{PluginMenus.cpp}::OnResetConfig(), TagsEditorDialog::OnSaveDefaults(), LabelTrackMenuTable::OnSetFont(), ViewActions::Handler::OnShowClipping(), ViewActions::Handler::OnShowExtraMenus(), ViewActions::Handler::OnShowNameOverlay(), anonymous_namespace{TrackMenus.cpp}::OnSyncLock(), AdornedRulerPanel::OnSyncSelToQuickPlay(), anonymous_namespace{TransportMenus.cpp}::OnTogglePlayRecording(), anonymous_namespace{TransportMenus.cpp}::OnToggleSoundActivated(), anonymous_namespace{TransportMenus.cpp}::OnToggleSWPlaythrough(), anonymous_namespace{LabelMenus.cpp}::OnToggleTypeToCreateLabel(), FFmpegImportPlugin::Open(), Registry::OrderingPreferenceInitializer::operator()(), anonymous_namespace{HelpMenus.cpp}::QuickFixDialog::PopulateOrExchange(), anonymous_namespace{AudacityApp.cpp}::PopulatePreferences(), EffectNoiseReduction::Settings::PrefsIO(), ProjectRate::ProjectRate(), ReadSnapTo(), PluginManager::RemoveConfig(), PluginManager::RemoveConfigSubgroup(), CommandManager::RemoveDuplicateShortcuts(), MacrosWindow::SaveChanges(), DependencyDialog::SaveFutureActionChoice(), GlobalPrefsDialog::SavePreferredPage(), PluginManager::SetConfigValue(), Importer::SetDefaultOpenType(), AudioSetupToolBar::SetDevices(), DeviceToolBar::SetDevices(), Importer::SetLastOpenType(), ProjectTimeSignature::SetLowerTimeSignature(), ModuleSettings::SetModuleStatus(), TracksPrefs::SetPinnedHeadPositionPreference(), TracksPrefs::SetPinnedHeadPreference(), Journal::SetRecordEnabled(), ProjectSnap::SetSnapMode(), ProjectSnap::SetSnapTo(), ProjectTimeSignature::SetTempo(), ProjectTimeSignature::SetUpperTimeSignature(), HelpSystem::ShowHelp(), EffectNoiseRemoval::ShowHostInterface(), ShowWarningDialog(), ProjectSelectionManager::SSBL_SetBandwidthSelectionFormatName(), ProjectSelectionManager::SSBL_SetFrequencySelectionFormatName(), UpdateManager::Start(), ProjectSelectionManager::TT_SetAudioTimeFormat(), cloud::audiocom::OAuthService::UnlinkAccount(), EQCurveReader::UpdateDefaultCurves(), anonymous_namespace{SelectionBar.cpp}::UpdateSelectionMode(), cloud::audiocom::UserService::UpdateUserData(), 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 81 of file FileConfig.h.

81{ 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}
#define str(a)

References mConfig, and str.

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, and str.

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, and str.

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, and str.

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 {
61 }
int mVersionMajorKeyInit
Definition: FileConfig.h:95
int mVersionMinorKeyInit
Definition: FileConfig.h:96
int mVersionMicroKeyInit
Definition: FileConfig.h:97

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(), DeduceSnapTo(), CommandManager::NewIdentifier(), ReadSnapMode(), and ReadSnapTo().

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 {
55 }

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

Here is the caller graph for this function:

◆ Warn()

void FileConfig::Warn ( )
protectedvirtual

Override to notify the user of error conditions involving writability of config files. Default implementation does nothing

Reimplemented in AudacityFileConfig.

Definition at line 288 of file FileConfig.cpp.

289{
290}

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 84 of file FileConfig.h.

Referenced by Init().

◆ mConfig

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

◆ mConv

std::unique_ptr<wxMBConv> FileConfig::mConv
private

Definition at line 89 of file FileConfig.h.

Referenced by Init().

◆ mDirty

bool FileConfig::mDirty
private

◆ mGlobalFilename

const wxString FileConfig::mGlobalFilename
private

Definition at line 87 of file FileConfig.h.

Referenced by Init().

◆ mLocalFilename

const wxString FileConfig::mLocalFilename
private

Definition at line 86 of file FileConfig.h.

Referenced by Flush(), and Init().

◆ mStyle

const long FileConfig::mStyle
private

Definition at line 88 of file FileConfig.h.

Referenced by Init().

◆ mVendorName

const wxString FileConfig::mVendorName
private

Definition at line 85 of file FileConfig.h.

Referenced by Init().

◆ mVersionMajorKeyInit

int FileConfig::mVersionMajorKeyInit {}
private

Definition at line 95 of file FileConfig.h.

◆ mVersionMicroKeyInit

int FileConfig::mVersionMicroKeyInit {}
private

Definition at line 97 of file FileConfig.h.

◆ mVersionMinorKeyInit

int FileConfig::mVersionMinorKeyInit {}
private

Definition at line 96 of file FileConfig.h.


The documentation for this class was generated from the following files: