1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-07 07:12:34 +02:00

Bug 1440 - Cancelling Export Multiple by labels containing illegal characters exports the cancelled file with empty name.

Also made ExportMultipleByTrack more like ExportMultipleByLabel in that it continues on exporting tracks even if one track has a bad name.
This commit is contained in:
James Crook 2016-07-15 16:20:25 +01:00
parent 68285298ed
commit 7c7fc55bc2

View File

@ -120,7 +120,7 @@ ExportMultiple::ExportMultiple(AudacityProject *project)
ShuttleGui S(this, eIsCreatingFromPrefs);
// Creating some of the widgets cause cause events to fire
// Creating some of the widgets cause events to fire
// and we don't want that until after we're completely
// created. (Observed on Windows)
mInitialized = false;
@ -625,6 +625,7 @@ bool ExportMultiple::DirOk()
return fn.Mkdir(0777, wxPATH_MKDIR_FULL);
}
// TODO: JKC July2016: Merge labels/tracks duplicated export code.
int ExportMultiple::ExportMultipleByLabel(bool byName,
const wxString &prefix, bool addNumber)
{
@ -632,12 +633,11 @@ int ExportMultiple::ExportMultipleByLabel(bool byName,
bool tagsPrompt = mProject->GetShowId3Dialog();
int numFiles = mNumLabels;
int l = 0; // counter for files done
ExportKitArray exportSettings; // dynamic array we will use to store the
// settings needed to do the exports with in
ExportKitArray exportSettings; // dynamic array for settings.
exportSettings.Alloc(numFiles); // Allocate some guessed space to use.
// Account for exporting before first label
if (mFirst->GetValue()) {
if( mFirst->GetValue() ) {
l--;
numFiles++;
}
@ -658,30 +658,27 @@ int ExportMultiple::ExportMultipleByLabel(bool byName,
const LabelStruct *info = NULL;
/* Examine all labels a first time, sort out all data but don't do any
* exporting yet (so this run is quick but interactive) */
while (l < mNumLabels) {
while( l < mNumLabels ) {
// Get file name and starting time
if (l < 0) {
if( l < 0 ) {
// create wxFileName for output file
name = (mFirstFileName->GetValue());
setting.t0 = 0.0;
}
else {
} else {
info = mLabels->GetLabel(l);
name = (info->title);
setting.t0 = info->selectedRegion.t0();
}
// Figure out the ending time
if (info && !info->selectedRegion.isPoint()) {
if( info && !info->selectedRegion.isPoint() ) {
setting.t1 = info->selectedRegion.t1();
}
else if (l < mNumLabels-1) {
} else if( l < mNumLabels-1 ) {
// Use start of next label as end
const LabelStruct *info1 = mLabels->GetLabel(l+1);
setting.t1 = info1->selectedRegion.t0();
}
else {
} else {
setting.t1 = mTracks->GetEndTime();
}
@ -692,9 +689,9 @@ int ExportMultiple::ExportMultipleByLabel(bool byName,
title = name;
// Numbering files...
if (!byName) {
if( !byName ) {
name.Printf(wxT("%s-%02d"), prefix.c_str(), l+1);
} else if (addNumber) {
} else if( addNumber ) {
// Following discussion with GA, always have 2 digits
// for easy file-name sorting (on Windows)
name.Prepend(wxString::Format(wxT("%02d-"), l+1));
@ -702,8 +699,16 @@ int ExportMultiple::ExportMultipleByLabel(bool byName,
// store sanitised and user checked name in object
setting.destfile.SetName(MakeFileName(name));
wxASSERT(setting.destfile.IsOk()); // scream if file name is broke
if( setting.destfile.GetName().IsEmpty() )
{ // user cancelled dialogue, or deleted everything in field.
// or maybe the label was empty??
// So we ignore this one and keep going.
}
else
{
// FIXME: TRAP_ERR User could have given an illegal filename prefix.
// in that case we should tell them, not fail silently.
wxASSERT(setting.destfile.IsOk()); // burp if file name is broke
// Make sure the (final) file name is unique within the set of exports
FileNames::MakeNameUnique(otherNames, setting.destfile);
@ -715,8 +720,9 @@ int ExportMultiple::ExportMultipleByLabel(bool byName,
setting.filetags.SetTag(TAG_TITLE, title);
setting.filetags.SetTag(TAG_TRACK, l+1);
// let the user have a crack at editing it, exit if cancelled
if (!setting.filetags.ShowEditDialog(mProject,_("Edit Metadata Tags"), tagsPrompt))
if( !setting.filetags.ShowEditDialog(mProject, _("Edit Metadata Tags"), tagsPrompt) )
return false;
}
/* add the settings to the array of settings to be used for export */
exportSettings.Add(setting);
@ -732,6 +738,9 @@ int ExportMultiple::ExportMultipleByLabel(bool byName,
for (count = 0; count < numFiles; count++) {
/* get the settings to use for the export from the array */
activeSetting = exportSettings[count];
// Bug 1440 fix.
if( activeSetting.destfile.GetName().IsEmpty() )
continue;
// Export it
ok = DoExport(channels, activeSetting.destfile, false, activeSetting.t0, activeSetting.t1, activeSetting.filetags);
@ -838,11 +847,15 @@ int ExportMultiple::ExportMultipleByTrack(bool byName,
setting.destfile.SetName(MakeFileName(name));
if (setting.destfile.GetName().IsEmpty())
{ // user cancelled dialogue, or deleted everything in feild.
// either way, cancel
return false;
{ // user cancelled dialogue, or deleted everything in field.
// So we ignore this one and keep going.
}
wxASSERT(setting.destfile.IsOk()); // scream if file name is broke
else
{
// FIXME: TRAP_ERR User could have given an illegal track name.
// in that case we should tell them, not fail silently.
wxASSERT(setting.destfile.IsOk()); // burp if file name is broke
// Make sure the (final) file name is unique within the set of exports
FileNames::MakeNameUnique(otherNames, setting.destfile);
@ -856,7 +869,7 @@ int ExportMultiple::ExportMultipleByTrack(bool byName,
// let the user have a crack at editing it, exit if cancelled
if (!setting.filetags.ShowEditDialog(mProject,_("Edit Metadata Tags"), tagsPrompt))
return false;
}
/* add the settings to the array of settings to be used for export */
exportSettings.Add(setting);
@ -873,6 +886,13 @@ int ExportMultiple::ExportMultipleByTrack(bool byName,
continue;
}
/* get the settings to use for the export from the array */
activeSetting = exportSettings[count];
if( activeSetting.destfile.GetName().IsEmpty() ){
count++;
continue;
}
/* Select the track */
tr->SetSelected(true);
@ -886,8 +906,6 @@ int ExportMultiple::ExportMultipleByTrack(bool byName,
}
}
/* get the settings to use for the export from the array */
activeSetting = exportSettings[count];
// Export the data. "channels" are per track.
ok = DoExport(activeSetting.channels, activeSetting.destfile, true, activeSetting.t0, activeSetting.t1, activeSetting.filetags);
@ -911,7 +929,7 @@ int ExportMultiple::ExportMultipleByTrack(bool byName,
selected[i]->SetSelected(true);
}
return ok;
return ok ;
}
int ExportMultiple::DoExport(int channels,