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