mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-05 22:28:57 +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:
parent
68285298ed
commit
7c7fc55bc2
@ -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
|
||||
exportSettings.Alloc(numFiles); // Allocate some guessed space to use.
|
||||
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++;
|
||||
}
|
||||
@ -646,7 +646,7 @@ int ExportMultiple::ExportMultipleByLabel(bool byName,
|
||||
int channels = mTracks->GetNumExportChannels(false);
|
||||
|
||||
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
|
||||
setting.destfile.SetPath(mDir->GetValue());
|
||||
setting.destfile.SetExt(mPlugins[mPluginIndex]->GetExtension(mSubFormatIndex));
|
||||
@ -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,21 +699,30 @@ int ExportMultiple::ExportMultipleByLabel(bool byName,
|
||||
|
||||
// store sanitised and user checked name in object
|
||||
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
|
||||
FileNames::MakeNameUnique(otherNames, setting.destfile);
|
||||
|
||||
/* 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;
|
||||
/* 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 */
|
||||
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,25 +847,29 @@ 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;
|
||||
}
|
||||
wxASSERT(setting.destfile.IsOk()); // scream if file name is broke
|
||||
{ // user cancelled dialogue, or deleted everything in field.
|
||||
// So we ignore this one and keep going.
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// Make sure the (final) file name is unique within the set of exports
|
||||
FileNames::MakeNameUnique(otherNames, setting.destfile);
|
||||
// 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
|
||||
|
||||
/* 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;
|
||||
// Make sure the (final) file name is unique within the set of exports
|
||||
FileNames::MakeNameUnique(otherNames, setting.destfile);
|
||||
|
||||
/* 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 */
|
||||
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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user