mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-08 16:11:14 +02:00
Bug119: Export Multiple /, *, ? handled incorrectly
This commit is contained in:
parent
5e95491bfc
commit
02ce3c312b
@ -36,7 +36,6 @@ and on Mac OS X for the filesystem.
|
|||||||
// Otherwise, you get link errors.
|
// Otherwise, you get link errors.
|
||||||
|
|
||||||
wxChar Internat::mDecimalSeparator = wxT('.'); // default
|
wxChar Internat::mDecimalSeparator = wxT('.'); // default
|
||||||
wxString Internat::forbid;
|
|
||||||
wxArrayString Internat::exclude;
|
wxArrayString Internat::exclude;
|
||||||
wxCharBuffer Internat::mFilename;
|
wxCharBuffer Internat::mFilename;
|
||||||
|
|
||||||
@ -50,9 +49,29 @@ void Internat::Init()
|
|||||||
// wxLogDebug(wxT("Decimal separator set to '%c'"), mDecimalSeparator);
|
// wxLogDebug(wxT("Decimal separator set to '%c'"), mDecimalSeparator);
|
||||||
|
|
||||||
// Setup list of characters that aren't allowed in file names
|
// Setup list of characters that aren't allowed in file names
|
||||||
forbid = wxFileName::GetForbiddenChars();
|
// Hey! The default wxPATH_NATIVE does not do as it should.
|
||||||
for(unsigned int i=0; i < forbid.Length(); i++)
|
#if defined(__WXMAC__)
|
||||||
exclude.Add( forbid.Mid(i, 1) );
|
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()
|
wxChar Internat::GetDecimalSeparator()
|
||||||
@ -204,17 +223,27 @@ char *Internat::VerifyFilename(const wxString &s, bool input)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxString Internat::SanitiseFilename(const wxString &name, const wxString &sub)
|
bool Internat::SanitiseFilename(wxString &name, const wxString &sub)
|
||||||
{
|
{
|
||||||
wxString temp = name;
|
bool result = false;
|
||||||
for(unsigned i=0; i<exclude.Count(); i++)
|
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)
|
wxString Internat::StripAccelerators(const wxString &s)
|
||||||
|
@ -61,8 +61,11 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** \brief Check a proposed file name string for illegal characters and
|
/** \brief Check a proposed file name string for illegal characters and
|
||||||
* remove them */
|
* remove them
|
||||||
static wxString SanitiseFilename(const wxString &name, const wxString &sub);
|
* 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
|
/** \brief Remove accelerator charactors from strings
|
||||||
*
|
*
|
||||||
@ -75,11 +78,13 @@ public:
|
|||||||
|
|
||||||
static wxString Parenthesize(const wxString &str);
|
static wxString Parenthesize(const wxString &str);
|
||||||
|
|
||||||
|
static const wxArrayString &GetExcludedCharacters()
|
||||||
|
{ return exclude; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static wxChar mDecimalSeparator;
|
static wxChar mDecimalSeparator;
|
||||||
|
|
||||||
// stuff for file name sanitisation
|
// stuff for file name sanitisation
|
||||||
static wxString forbid;
|
|
||||||
static wxArrayString exclude;
|
static wxArrayString exclude;
|
||||||
|
|
||||||
static wxCharBuffer mFilename;
|
static wxCharBuffer mFilename;
|
||||||
|
@ -118,11 +118,6 @@ ExportMultiple::ExportMultiple(AudacityProject *project)
|
|||||||
|
|
||||||
mBook = NULL;
|
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);
|
ShuttleGui S(this, eIsCreatingFromPrefs);
|
||||||
|
|
||||||
// Creating some of the widgets cause cause events to fire
|
// 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 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
|
// 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
|
{ // need to get user to fix file name
|
||||||
// build the dialog
|
// build the dialog
|
||||||
wxString msg;
|
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 );
|
wxTextEntryDialog dlg( this, msg, _("Save As..."), newname );
|
||||||
|
|
||||||
// And tell the validator about excluded chars
|
// And tell the validator about excluded chars
|
||||||
dlg.SetTextValidator( wxFILTER_EXCLUDE_CHAR_LIST );
|
dlg.SetTextValidator( wxFILTER_EXCLUDE_CHAR_LIST );
|
||||||
wxTextValidator *tv = dlg.GetTextValidator();
|
wxTextValidator *tv = dlg.GetTextValidator();
|
||||||
tv->SetExcludes(exclude);
|
tv->SetExcludes(Internat::GetExcludedCharacters());
|
||||||
|
|
||||||
// Show the dialog and bail if the user cancels
|
// Show the dialog and bail if the user cancels
|
||||||
if( dlg.ShowModal() == wxID_CANCEL )
|
if( dlg.ShowModal() == wxID_CANCEL )
|
||||||
|
@ -125,9 +125,6 @@ private:
|
|||||||
// List of file actually exported
|
// List of file actually exported
|
||||||
wxArrayString mExported;
|
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
|
wxChoice *mFormat; /**< Drop-down list of export formats
|
||||||
(combinations of plug-in and subformat) */
|
(combinations of plug-in and subformat) */
|
||||||
wxButton *mOptions;
|
wxButton *mOptions;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user