Skip to content

Commit efdf48f

Browse files
committed
Add additional checks for macro output directory.
This bug still available in case: using old settings file or manual set it into settings file. commit addapted from upstream
1 parent 72e7985 commit efdf48f

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

src/FileNames.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,22 @@ char *FileNames::VerifyFilename(const wxString &s, bool input)
716716
}
717717
#endif
718718

719+
bool FileNames::WritableLocationCheck(const FilePath& path)
720+
{
721+
bool status = wxFileName::IsDirWritable(path);
722+
723+
if (!status)
724+
{
725+
SneedacityMessageBox(
726+
XO("Directory %s does not have write permissions")
727+
.Format(path),
728+
XO("Error"),
729+
wxOK | wxICON_ERROR);
730+
}
731+
732+
return status;
733+
}
734+
719735
// Using this with wxStringArray::Sort will give you a list that
720736
// is alphabetical, without depending on case. If you use the
721737
// default sort, you will get strings with 'R' before 'a', because it is in caps.

src/FileNames.h

+3
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,9 @@ namespace FileNames
221221
SNEEDACITY_DLL_API char *VerifyFilename(const wxString &s, bool input = true);
222222
#endif
223223

224+
//! Check location on writable access and return true if checked successfully.
225+
SNEEDACITY_DLL_API bool WritableLocationCheck(const FilePath& path);
226+
224227
// wxString compare function for sorting case, which is needed to load correctly.
225228
SNEEDACITY_DLL_API int CompareNoCase(const wxString& first, const wxString& second);
226229

src/menus/FileMenus.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ void DoExport(SneedacityProject &project, const FileExtension &format)
6363
// We either use a configured output path,
6464
// or we use the default documents folder - just as for exports.
6565
FilePath pathName = FileNames::FindDefaultPath(FileNames::Operation::MacrosOut);
66+
67+
if (!FileNames::WritableLocationCheck(pathName))
68+
{
69+
return;
70+
}
6671
/*
6772
// If we've gotten to this point, we are in batch mode, have a file format,
6873
// and the project has either been saved or a file has been imported. So, we

src/prefs/DirectoriesPrefs.cpp

+3-18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "../widgets/SneedacityMessageBox.h"
3939
#include "../widgets/ReadOnlyText.h"
4040
#include "../widgets/wxTextCtrlWrapper.h"
41+
#include "../FileNames.h"
4142

4243
using namespace FileNames;
4344
using namespace TempDirectory;
@@ -267,22 +268,6 @@ void DirectoriesPrefs::PopulateOrExchange(ShuttleGui &S)
267268
S.EndScroller();
268269
}
269270

270-
bool WritableLocationCheck(const FilePath &path)
271-
{
272-
bool Status = wxFileName ::IsDirWritable(path);
273-
if (!Status)
274-
{
275-
SneedacityMessageBox(
276-
XO("Directory %s does not have write permissions")
277-
.Format(path),
278-
XO("Error"),
279-
wxOK | wxICON_ERROR);
280-
return true;
281-
}
282-
283-
return false;
284-
}
285-
286271
void DirectoriesPrefs::OnTempBrowse(wxCommandEvent &evt)
287272
{
288273
wxString oldTemp = gPrefs->Read(PreferenceKey(Operation::Open, PathType::_None),
@@ -311,7 +296,7 @@ void DirectoriesPrefs::OnTempBrowse(wxCommandEvent &evt)
311296
return;
312297
}
313298

314-
if (WritableLocationCheck(dlog.GetPath()))
299+
if (!FileNames::WritableLocationCheck(dlog.GetPath()))
315300
{
316301
return;
317302
}
@@ -392,7 +377,7 @@ void DirectoriesPrefs::OnBrowse(wxCommandEvent &evt)
392377
}
393378
}
394379

395-
if (WritableLocationCheck(dlog.GetPath()))
380+
if (!FileNames::WritableLocationCheck(dlog.GetPath()))
396381
{
397382
return;
398383
}

0 commit comments

Comments
 (0)