From 4ee1691d79d18f5a702f25e3ace79d4ab6049e23 Mon Sep 17 00:00:00 2001 From: Steve Brokenshire Date: Sat, 3 Feb 2018 13:24:09 +0000 Subject: [PATCH] frmPreferences: Clean up and delete account directory on account delete --- source/forms/preferences/frmPreferences.cpp | 37 +++++++++++++++++++-- source/forms/preferences/frmPreferences.h | 1 + 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/source/forms/preferences/frmPreferences.cpp b/source/forms/preferences/frmPreferences.cpp index 07a4715..8157bbb 100644 --- a/source/forms/preferences/frmPreferences.cpp +++ b/source/forms/preferences/frmPreferences.cpp @@ -328,7 +328,7 @@ void frmPreferences::DeleteAccount( wxCommandEvent& event ) accountDirDelFull.Append(wxT("/.xestiacal/accounts/")); accountDirDelFull.Append(accountDirFull); - wxRmDir(accountDirDelFull); + DeleteDirectory(accountDirDelFull); } @@ -425,4 +425,37 @@ void frmPreferences::SetupPointers(bool *reloadAccountInc){ reloadAccountConfig = reloadAccountInc; -} \ No newline at end of file +} + +void frmPreferences::DeleteDirectory(wxString directoryPath) +{ + + // Open the directory and look for files and directories + // to delete. + + wxDir directoryHandle(directoryPath); + + if (!directoryHandle.IsOpened()) + { + return; + } + + wxString directoryFilename; + + bool continueProcessing = directoryHandle.GetFirst(&directoryFilename, wxEmptyString, wxDIR_FILES|wxDIR_DIRS|wxDIR_HIDDEN); + while (continueProcessing) + { + wxString directoryFilenameFull = directoryPath + "/" + directoryFilename; + if (wxDir::Exists(directoryFilenameFull)) + { + DeleteDirectory(directoryFilenameFull); + continueProcessing = directoryHandle.GetNext(&directoryFilename); + continue; + } + wxRemoveFile(directoryFilenameFull); + continueProcessing = directoryHandle.GetNext(&directoryFilename); + } + directoryHandle.Close(); + + wxRmDir(directoryPath); +} diff --git a/source/forms/preferences/frmPreferences.h b/source/forms/preferences/frmPreferences.h index a5eec97..29f9b90 100644 --- a/source/forms/preferences/frmPreferences.h +++ b/source/forms/preferences/frmPreferences.h @@ -63,6 +63,7 @@ class frmPreferences : public frmPreferencesADT void DeleteAccount( wxCommandEvent& event ); void SavePreferences( wxCommandEvent& event ); void CloseWindow( wxCommandEvent& event ); + void DeleteDirectory( wxString directoryPath ); public: /** Constructor */ frmPreferences( wxWindow* parent ); -- 2.39.5