From c6389ad6553b3e9776013eb9e9d014b1a55b2720 Mon Sep 17 00:00:00 2001 From: gera Date: Wed, 14 Jul 2021 14:56:25 +0300 Subject: [PATCH] Cherry-pick commit with directory checking on unwritable. Additional cases, when user manualy set directory. --- src/FileNames.cpp | 16 ++++++++++++++++ src/FileNames.h | 3 +++ src/menus/FileMenus.cpp | 5 +++++ src/prefs/DirectoriesPrefs.cpp | 11 +++++++++++ 4 files changed, 35 insertions(+) diff --git a/src/FileNames.cpp b/src/FileNames.cpp index 2e5b861c4..536f92ca5 100644 --- a/src/FileNames.cpp +++ b/src/FileNames.cpp @@ -716,6 +716,22 @@ char *FileNames::VerifyFilename(const wxString &s, bool input) } #endif +bool FileNames::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 status; +} + // Using this with wxStringArray::Sort will give you a list that // is alphabetical, without depending on case. If you use the // default sort, you will get strings with 'R' before 'a', because it is in caps. diff --git a/src/FileNames.h b/src/FileNames.h index 92be64df3..6f1cc5ecf 100644 --- a/src/FileNames.h +++ b/src/FileNames.h @@ -221,6 +221,9 @@ namespace FileNames AUDACITY_DLL_API char *VerifyFilename(const wxString &s, bool input = true); #endif + //! Check location on writable access and return true if checked successfully. + AUDACITY_DLL_API bool WritableLocationCheck(const FilePath& path); + // wxString compare function for sorting case, which is needed to load correctly. AUDACITY_DLL_API int CompareNoCase(const wxString& first, const wxString& second); diff --git a/src/menus/FileMenus.cpp b/src/menus/FileMenus.cpp index b36c10fa3..24460e84f 100644 --- a/src/menus/FileMenus.cpp +++ b/src/menus/FileMenus.cpp @@ -63,6 +63,11 @@ void DoExport(AudacityProject &project, const FileExtension &format) // We either use a configured output path, // or we use the default documents folder - just as for exports. FilePath pathName = FileNames::FindDefaultPath(FileNames::Operation::MacrosOut); + + if (!FileNames::WritableLocationCheck(pathName)) + { + return; + } /* // If we've gotten to this point, we are in batch mode, have a file format, // and the project has either been saved or a file has been imported. So, we diff --git a/src/prefs/DirectoriesPrefs.cpp b/src/prefs/DirectoriesPrefs.cpp index b63fd3156..0220f85f7 100644 --- a/src/prefs/DirectoriesPrefs.cpp +++ b/src/prefs/DirectoriesPrefs.cpp @@ -38,6 +38,7 @@ #include "../widgets/AudacityMessageBox.h" #include "../widgets/ReadOnlyText.h" #include "../widgets/wxTextCtrlWrapper.h" +#include "../FileNames.h" using namespace FileNames; using namespace TempDirectory; @@ -295,6 +296,11 @@ void DirectoriesPrefs::OnTempBrowse(wxCommandEvent &evt) return; } + if (!FileNames::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,6 +377,11 @@ void DirectoriesPrefs::OnBrowse(wxCommandEvent &evt) } } + if (!FileNames::WritableLocationCheck(dlog.GetPath())) + { + return; + } + tc->SetValue(dlog.GetPath()); }