1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-05 14:18:53 +02:00

Bug119: Export Multiple /, *, ? handled incorrectly

This commit is contained in:
Paul Licameli 2016-06-20 22:23:06 -04:00
parent 5e95491bfc
commit 02ce3c312b
4 changed files with 53 additions and 26 deletions

View File

@ -36,7 +36,6 @@ and on Mac OS X for the filesystem.
// Otherwise, you get link errors.
wxChar Internat::mDecimalSeparator = wxT('.'); // default
wxString Internat::forbid;
wxArrayString Internat::exclude;
wxCharBuffer Internat::mFilename;
@ -50,9 +49,29 @@ void Internat::Init()
// wxLogDebug(wxT("Decimal separator set to '%c'"), mDecimalSeparator);
// Setup list of characters that aren't allowed in file names
forbid = wxFileName::GetForbiddenChars();
for(unsigned int i=0; i < forbid.Length(); i++)
exclude.Add( forbid.Mid(i, 1) );
// Hey! The default wxPATH_NATIVE does not do as it should.
#if defined(__WXMAC__)
wxPathFormat format = wxPATH_MAC;
#elif defined(__WXGTK__)
wxPathFormat format = wxPATH_UNIX;
#elif defined(__WXMSW__)
wxPathFormat format = wxPATH_WIN;
#endif
// This is supposed to return characters not permitted in paths to files
// or to directories
auto forbid = wxFileName::GetForbiddenChars(format);
for(auto cc: forbid)
exclude.Add(wxString{ cc });
// The path separators may not be forbidden, so add them
auto separators = wxFileName::GetPathSeparators(format);
for(auto cc: separators) {
if (forbid.Find(cc) == wxNOT_FOUND)
exclude.Add(wxString{ cc });
}
}
wxChar Internat::GetDecimalSeparator()
@ -204,17 +223,27 @@ char *Internat::VerifyFilename(const wxString &s, bool input)
}
#endif
wxString Internat::SanitiseFilename(const wxString &name, const wxString &sub)
bool Internat::SanitiseFilename(wxString &name, const wxString &sub)
{
wxString temp = name;
for(unsigned i=0; i<exclude.Count(); i++)
bool result = false;
for(const auto &item : exclude)
{
if(temp.Contains(exclude.Item(i)))
if(name.Contains(item))
{
temp.Replace(exclude.Item(i),sub);
name.Replace(item, sub);
result = true;
}
}
return temp;
#ifdef __WXMAC__
// Special Mac stuff
// '/' is permitted in file names as seen in dialogs, even though it is
// the path separator. The "real" filename as seen in the terminal has ':'.
// Do NOT return true if this is the only subsitution.
name.Replace(wxT("/"), wxT(":"));
#endif
return result;
}
wxString Internat::StripAccelerators(const wxString &s)

View File

@ -61,8 +61,11 @@ public:
#endif
/** \brief Check a proposed file name string for illegal characters and
* remove them */
static wxString SanitiseFilename(const wxString &name, const wxString &sub);
* remove them
* return true iff name is "visibly" changed (not necessarily equivalent to
* character-wise changed)
*/
static bool SanitiseFilename(wxString &name, const wxString &sub);
/** \brief Remove accelerator charactors from strings
*
@ -75,11 +78,13 @@ public:
static wxString Parenthesize(const wxString &str);
static const wxArrayString &GetExcludedCharacters()
{ return exclude; }
private:
static wxChar mDecimalSeparator;
// stuff for file name sanitisation
static wxString forbid;
static wxArrayString exclude;
static wxCharBuffer mFilename;

View File

@ -118,11 +118,6 @@ ExportMultiple::ExportMultiple(AudacityProject *project)
mBook = NULL;
// create array of characters not allowed in file names
wxString forbid = wxFileName::GetForbiddenChars();
for(unsigned int i=0; i < forbid.Length(); i++)
exclude.Add( forbid.Mid(i, 1) );
ShuttleGui S(this, eIsCreatingFromPrefs);
// Creating some of the widgets cause cause events to fire
@ -973,22 +968,23 @@ int ExportMultiple::DoExport(int channels,
wxString ExportMultiple::MakeFileName(const wxString &input)
{
wxString newname; // name we are generating
wxString newname = input; // name we are generating
// strip out anything that isn't allowed in file names on this platform
newname = Internat::SanitiseFilename(input, wxT("_"));
auto changed = Internat::SanitiseFilename(newname, wxT("_"));
if(!newname.IsSameAs(input))
if(changed)
{ // need to get user to fix file name
// build the dialog
wxString msg;
msg.Printf(_("Label or track \"%s\" is not a legal file name. You cannot use any of: %s\nUse..."), input.c_str(), wxFileName::GetForbiddenChars().c_str());
msg.Printf(_("Label or track \"%s\" is not a legal file name. You cannot use any of: %s\nUse..."), input.c_str(),
::wxJoin(Internat::GetExcludedCharacters(), wxChar(' ')));
wxTextEntryDialog dlg( this, msg, _("Save As..."), newname );
// And tell the validator about excluded chars
dlg.SetTextValidator( wxFILTER_EXCLUDE_CHAR_LIST );
wxTextValidator *tv = dlg.GetTextValidator();
tv->SetExcludes(exclude);
tv->SetExcludes(Internat::GetExcludedCharacters());
// Show the dialog and bail if the user cancels
if( dlg.ShowModal() == wxID_CANCEL )

View File

@ -125,9 +125,6 @@ private:
// List of file actually exported
wxArrayString mExported;
/** Array of characters not allowed to be in file names on this platform */
wxArrayString exclude;
wxChoice *mFormat; /**< Drop-down list of export formats
(combinations of plug-in and subformat) */
wxButton *mOptions;