mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-23 15:41:09 +02:00
Exception safety in: general exporting routines
This commit is contained in:
parent
464828d88f
commit
48459404a5
@ -3914,6 +3914,23 @@ bool AudacityProject::Save(bool overwrite /* = true */ ,
|
||||
pWaveTrack = (WaveTrack*)pTrack;
|
||||
pSavedTrackList.Add(mTrackFactory->DuplicateWaveTrack(*pWaveTrack));
|
||||
}
|
||||
auto cleanup = finally( [&] {
|
||||
// Restore the saved track states and clean up.
|
||||
TrackListIterator savedTrackIter(&pSavedTrackList);
|
||||
Track *pSavedTrack;
|
||||
for (pTrack = iter.First(), pSavedTrack = savedTrackIter.First();
|
||||
((pTrack != NULL) && (pSavedTrack != NULL));
|
||||
pTrack = iter.Next(), pSavedTrack = savedTrackIter.Next())
|
||||
{
|
||||
pWaveTrack = (WaveTrack*)pTrack;
|
||||
pWaveTrack->SetSelected(pSavedTrack->GetSelected());
|
||||
pWaveTrack->SetMute(pSavedTrack->GetMute());
|
||||
pWaveTrack->SetSolo(pSavedTrack->GetSolo());
|
||||
|
||||
pWaveTrack->SetGain(((WaveTrack*)pSavedTrack)->GetGain());
|
||||
pWaveTrack->SetPan(((WaveTrack*)pSavedTrack)->GetPan());
|
||||
}
|
||||
} );
|
||||
|
||||
if (numWaveTracks == 0)
|
||||
// Nothing to save compressed => success. Delete the copies and go.
|
||||
@ -3923,6 +3940,7 @@ bool AudacityProject::Save(bool overwrite /* = true */ ,
|
||||
for (pTrack = iter.First(); pTrack != NULL; pTrack = iter.Next())
|
||||
{
|
||||
pWaveTrack = (WaveTrack*)pTrack;
|
||||
|
||||
pWaveTrack->SetSelected(false);
|
||||
pWaveTrack->SetMute(false);
|
||||
pWaveTrack->SetSolo(false);
|
||||
@ -3968,22 +3986,6 @@ bool AudacityProject::Save(bool overwrite /* = true */ ,
|
||||
}
|
||||
}
|
||||
|
||||
// Restore the saved track states and clean up.
|
||||
TrackListIterator savedTrackIter(&pSavedTrackList);
|
||||
Track *pSavedTrack;
|
||||
for (pTrack = iter.First(), pSavedTrack = savedTrackIter.First();
|
||||
((pTrack != NULL) && (pSavedTrack != NULL));
|
||||
pTrack = iter.Next(), pSavedTrack = savedTrackIter.Next())
|
||||
{
|
||||
pWaveTrack = (WaveTrack*)pTrack;
|
||||
pWaveTrack->SetSelected(pSavedTrack->GetSelected());
|
||||
pWaveTrack->SetMute(pSavedTrack->GetMute());
|
||||
pWaveTrack->SetSolo(pSavedTrack->GetSolo());
|
||||
|
||||
pWaveTrack->SetGain(((WaveTrack*)pSavedTrack)->GetGain());
|
||||
pWaveTrack->SetPan(((WaveTrack*)pSavedTrack)->GetPan());
|
||||
}
|
||||
|
||||
return bSuccess;
|
||||
}
|
||||
#endif
|
||||
|
@ -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';
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user