From 4770b1f0a4c91c71eea8e54a180a7ba99b77834d Mon Sep 17 00:00:00 2001 From: MalevolentStrix Date: Mon, 28 Jun 2021 21:47:43 +0530 Subject: [PATCH] Bug 2740 - Directories in Directories preferences can be set to unwritable locations Add a new function WritableLocationCheck() for checking the directory permissions before setting preferences for Open, Save, Import, Export, Macro Output and Temporary Files directory in Edit->Preferences->Directories and delete the old block of the same test --- src/prefs/DirectoriesPrefs.cpp | 35 ++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/prefs/DirectoriesPrefs.cpp b/src/prefs/DirectoriesPrefs.cpp index 35f6617c7..df35245e6 100644 --- a/src/prefs/DirectoriesPrefs.cpp +++ b/src/prefs/DirectoriesPrefs.cpp @@ -267,6 +267,22 @@ void DirectoriesPrefs::PopulateOrExchange(ShuttleGui &S) S.EndScroller(); } +bool WritableLocationCheck(const FilePath &path) +{ + bool Status = wxFileName ::IsDirWritable(path); + if (!Status) + { + AudacityMessageBox( + XO("Directory %s does not have write permissions") + .Format(path), + XO("Error"), + wxOK | wxICON_ERROR); + return true; + } + + return false; +} + void DirectoriesPrefs::OnTempBrowse(wxCommandEvent &evt) { wxString oldTemp = gPrefs->Read(PreferenceKey(Operation::Open, PathType::_None), @@ -295,6 +311,11 @@ void DirectoriesPrefs::OnTempBrowse(wxCommandEvent &evt) return; } + if (WritableLocationCheck(dlog.GetPath())) + { + return; + } + // Append an "audacity_temp" directory to this path if necessary (the // default, the existing pref (as stored in the control), and any path // ending in a directory with the same name as what we'd add should be OK @@ -371,19 +392,9 @@ void DirectoriesPrefs::OnBrowse(wxCommandEvent &evt) } } - if (evt.GetId() == SaveButtonID || evt.GetId() == ExportButtonID) + if (WritableLocationCheck(dlog.GetPath())) { - bool Status = wxFileName ::IsDirWritable(dlog.GetPath()); - wxString path{dlog.GetPath()}; - if (!Status) - { - AudacityMessageBox( - XO("Directory %s does not have write permissions") - .Format(path), - XO("Error"), - wxOK | wxICON_ERROR); - return; - } + return; } tc->SetValue(dlog.GetPath());