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
This commit is contained in:
MalevolentStrix 2021-06-28 21:47:43 +05:30 committed by Dmitry Vedenko
parent 8d0487ea85
commit 4770b1f0a4
1 changed files with 23 additions and 12 deletions

View File

@ -267,6 +267,22 @@ void DirectoriesPrefs::PopulateOrExchange(ShuttleGui &S)
S.EndScroller(); 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) void DirectoriesPrefs::OnTempBrowse(wxCommandEvent &evt)
{ {
wxString oldTemp = gPrefs->Read(PreferenceKey(Operation::Open, PathType::_None), wxString oldTemp = gPrefs->Read(PreferenceKey(Operation::Open, PathType::_None),
@ -295,6 +311,11 @@ void DirectoriesPrefs::OnTempBrowse(wxCommandEvent &evt)
return; return;
} }
if (WritableLocationCheck(dlog.GetPath()))
{
return;
}
// Append an "audacity_temp" directory to this path if necessary (the // Append an "audacity_temp" directory to this path if necessary (the
// default, the existing pref (as stored in the control), and any path // 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 // 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()); return;
wxString path{dlog.GetPath()};
if (!Status)
{
AudacityMessageBox(
XO("Directory %s does not have write permissions")
.Format(path),
XO("Error"),
wxOK | wxICON_ERROR);
return;
}
} }
tc->SetValue(dlog.GetPath()); tc->SetValue(dlog.GetPath());