mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-25 15:53:52 +02:00
Exception safety in: general exporting routines
This commit is contained in:
@@ -827,7 +827,22 @@ bool Exporter::ExportTracks()
|
||||
::wxRenameFile(mActualName.GetFullPath(), mFilename.GetFullPath());
|
||||
}
|
||||
|
||||
auto success = mPlugins[mFormat]->Export(mProject,
|
||||
bool success = false;
|
||||
|
||||
auto cleanup = finally( [&] {
|
||||
if (mActualName != mFilename) {
|
||||
// Remove backup
|
||||
if ( success )
|
||||
::wxRemoveFile(mFilename.GetFullPath());
|
||||
else {
|
||||
// Restore original, if needed
|
||||
::wxRemoveFile(mActualName.GetFullPath());
|
||||
::wxRenameFile(mFilename.GetFullPath(), mActualName.GetFullPath());
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
auto result = mPlugins[mFormat]->Export(mProject,
|
||||
mChannels,
|
||||
mActualName.GetFullPath(),
|
||||
mSelectedOnly,
|
||||
@@ -837,19 +852,10 @@ bool Exporter::ExportTracks()
|
||||
NULL,
|
||||
mSubFormat);
|
||||
|
||||
if (mActualName != mFilename) {
|
||||
// Remove backup
|
||||
if (success == ProgressResult::Success || success == ProgressResult::Stopped) {
|
||||
::wxRemoveFile(mFilename.GetFullPath());
|
||||
}
|
||||
else {
|
||||
// Restore original, if needed
|
||||
::wxRemoveFile(mActualName.GetFullPath());
|
||||
::wxRenameFile(mFilename.GetFullPath(), mActualName.GetFullPath());
|
||||
}
|
||||
}
|
||||
success =
|
||||
result == ProgressResult::Success || result == ProgressResult::Stopped;
|
||||
|
||||
return (success == ProgressResult::Success || success == ProgressResult::Stopped);
|
||||
return success;
|
||||
}
|
||||
|
||||
void Exporter::CreateUserPaneCallback(wxWindow *parent, wxUIntPtr userdata)
|
||||
|
||||
@@ -566,21 +566,11 @@ void ExportMultiple::OnExport(wxCommandEvent& WXUNUSED(event))
|
||||
}
|
||||
|
||||
// bool overwrite = mOverwrite->GetValue();
|
||||
ProgressResult ok;
|
||||
ProgressResult ok = ProgressResult::Failed;
|
||||
mExported.Empty();
|
||||
|
||||
if (mLabel->GetValue()) {
|
||||
ok = ExportMultipleByLabel(mByName->GetValue() || mByNumberAndName->GetValue(),
|
||||
mPrefix->GetValue(),
|
||||
mByNumberAndName->GetValue());
|
||||
}
|
||||
else {
|
||||
ok = ExportMultipleByTrack(mByName->GetValue() || mByNumberAndName->GetValue(),
|
||||
mPrefix->GetValue(),
|
||||
mByNumberAndName->GetValue());
|
||||
}
|
||||
|
||||
// Give 'em the result
|
||||
auto cleanup = finally( [&]
|
||||
{
|
||||
wxString msg;
|
||||
msg.Printf(
|
||||
@@ -598,12 +588,26 @@ void ExportMultiple::OnExport(wxCommandEvent& WXUNUSED(event))
|
||||
FileList += mExported[i];
|
||||
FileList += '\n';
|
||||
}
|
||||
// This results dialog is a child of this dialog.
|
||||
HelpSystem::ShowInfoDialog( this,
|
||||
_("Export Multiple"),
|
||||
msg,
|
||||
FileList,
|
||||
450,400);
|
||||
|
||||
CallAfter( [=] {
|
||||
// This results dialog is a child of this dialog.
|
||||
HelpSystem::ShowInfoDialog( this,
|
||||
_("Export Multiple"),
|
||||
msg,
|
||||
FileList,
|
||||
450,400);
|
||||
} );
|
||||
} );
|
||||
|
||||
if (mLabel->GetValue()) {
|
||||
ok = ExportMultipleByLabel(mByName->GetValue() || mByNumberAndName->GetValue(),
|
||||
mPrefix->GetValue(),
|
||||
mByNumberAndName->GetValue());
|
||||
}
|
||||
else {
|
||||
ok = ExportMultipleByTrack(mByName->GetValue() || mByNumberAndName->GetValue(),
|
||||
mPrefix->GetValue(),
|
||||
mByNumberAndName->GetValue());
|
||||
}
|
||||
|
||||
if (ok == ProgressResult::Success || ok == ProgressResult::Stopped) {
|
||||
@@ -797,6 +801,12 @@ ProgressResult ExportMultiple::ExportMultipleByTrack(bool byName,
|
||||
}
|
||||
}
|
||||
|
||||
auto cleanup = finally( [&] {
|
||||
// Restore the selection states
|
||||
for (auto pTrack : selected)
|
||||
pTrack->SetSelected(true);
|
||||
} );
|
||||
|
||||
/* Examine all tracks in turn, collecting export information */
|
||||
for (tr = iter.First(mTracks); tr != NULL; tr = iter.Next()) {
|
||||
|
||||
@@ -932,10 +942,6 @@ ProgressResult ExportMultiple::ExportMultipleByTrack(bool byName,
|
||||
|
||||
}
|
||||
|
||||
// Restore the selection states
|
||||
for (auto pTrack : selected)
|
||||
pTrack->SetSelected(true);
|
||||
|
||||
return ok ;
|
||||
}
|
||||
|
||||
@@ -950,8 +956,10 @@ ProgressResult ExportMultiple::DoExport(unsigned channels,
|
||||
|
||||
wxLogDebug(wxT("Doing multiple Export: File name \"%s\""), (inName.GetFullName()).c_str());
|
||||
wxLogDebug(wxT("Channels: %i, Start: %lf, End: %lf "), channels, t0, t1);
|
||||
if (selectedOnly) wxLogDebug(wxT("Selected Region Only"));
|
||||
else wxLogDebug(wxT("Whole Project"));
|
||||
if (selectedOnly)
|
||||
wxLogDebug(wxT("Selected Region Only"));
|
||||
else
|
||||
wxLogDebug(wxT("Whole Project"));
|
||||
|
||||
if (mOverwrite->GetValue()) {
|
||||
// Make sure we don't overwrite (corrupt) alias files
|
||||
|
||||
Reference in New Issue
Block a user