Bug 1854 - Un-warned export file overwrite danger in 2.2.2 Chains and 2.3.0 MacrosWindow
Now we add a suffix of 001, 002 and so on up to 100. Then fall back to prompting.
This commit is contained in:
parent
3c0ee4d3c1
commit
ca694a1b22
|
@ -558,7 +558,6 @@ wxString MacroCommands::BuildCleanFileName(const wxString &fileName, const wxStr
|
||||||
cleanedName += wxFileName::GetPathSeparator();
|
cleanedName += wxFileName::GetPathSeparator();
|
||||||
cleanedName += justName;
|
cleanedName += justName;
|
||||||
cleanedName += extension;
|
cleanedName += extension;
|
||||||
wxGetApp().AddFileToHistory(cleanedName);
|
|
||||||
|
|
||||||
return cleanedName;
|
return cleanedName;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4982,19 +4982,45 @@ void AudacityProject::OnExport(const wxString & Format )
|
||||||
|
|
||||||
// Prompt for file name and/or extension?
|
// Prompt for file name and/or extension?
|
||||||
bool bPromptingRequired = (mBatchMode == 0) || mFileName.IsEmpty() || Format.IsEmpty();
|
bool bPromptingRequired = (mBatchMode == 0) || mFileName.IsEmpty() || Format.IsEmpty();
|
||||||
|
wxString filename;
|
||||||
|
|
||||||
|
if (!bPromptingRequired) {
|
||||||
|
|
||||||
if (bPromptingRequired) {
|
|
||||||
e.SetDefaultFormat(Format);
|
|
||||||
e.Process(this, false, 0.0, mTracks->GetEndTime());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// We're in batch mode, and we have an mFileName and Format.
|
// We're in batch mode, and we have an mFileName and Format.
|
||||||
wxString extension = ".";
|
wxString extension = ".";
|
||||||
extension += Format;
|
extension += Format;
|
||||||
extension.MakeLower();
|
extension.MakeLower();
|
||||||
|
|
||||||
wxString filename = MacroCommands::BuildCleanFileName(mFileName, extension);
|
filename = MacroCommands::BuildCleanFileName(mFileName, extension);
|
||||||
|
|
||||||
|
// Bug 1854, No warning of file overwrite (when export is called from Macros).
|
||||||
|
int counter = 0;
|
||||||
|
bPromptingRequired = wxFileExists(filename);
|
||||||
|
|
||||||
|
// We'll try alternative names to avoid overwriting.
|
||||||
|
while ( bPromptingRequired && counter < 100 ) {
|
||||||
|
counter++;
|
||||||
|
wxString number;
|
||||||
|
number.Printf("%03i", counter);
|
||||||
|
// So now the name has a number in it too.
|
||||||
|
filename = MacroCommands::BuildCleanFileName(mFileName, number + extension);
|
||||||
|
bPromptingRequired = wxFileExists(filename);
|
||||||
|
}
|
||||||
|
// If we've run out of alternative names, we will fall back to prompting - even if in a macro.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (bPromptingRequired)
|
||||||
|
{
|
||||||
|
// Do export with prompting.
|
||||||
|
e.SetDefaultFormat(Format);
|
||||||
|
e.Process(this, false, t0, t1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxGetApp().AddFileToHistory(filename);
|
||||||
|
// We're in batch mode, the file does not exist already.
|
||||||
|
// We really can proceed without prompting.
|
||||||
int nChannels = MacroCommands::IsMono() ? 1 : 2;
|
int nChannels = MacroCommands::IsMono() ? 1 : 2;
|
||||||
e.Process(
|
e.Process(
|
||||||
this, // AudacityProject
|
this, // AudacityProject
|
||||||
|
@ -5006,6 +5032,7 @@ void AudacityProject::OnExport(const wxString & Format )
|
||||||
t1 // t1
|
t1 // t1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudacityProject::OnExportAudio(const CommandContext &WXUNUSED(context) ){ OnExport("");}
|
void AudacityProject::OnExportAudio(const CommandContext &WXUNUSED(context) ){ OnExport("");}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user