1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-03-29 10:35:45 +02:00

Strong exception safety in all uses of XMLFileWriter...

... Strong, meaning that the file at the specified path is created or modified
only if all write operations complete without exceptions, barring one very
unlikely possibility that a final file rename fails, but even in that case the
output is successfully written to some path.

This commit does not add throws, but changes the type thrown to a subclass of
AudacityException, so that GuardedCall will cause the user to see an error
dialog in all cases.

Duplicated logic for making temporary files and backups is now all in one
place, the class XMLWriter.

There may be more new GuardedCalls than necessary -- the catch-all for the
event loop, AudacityApp::OnExceptionInMainLoop, might be trusted instead in
some cases --  but they are sufficient.
This commit is contained in:
Paul Licameli
2016-12-01 20:40:05 -05:00
parent b81cdee7e3
commit 3bb04245c5
12 changed files with 323 additions and 425 deletions

View File

@@ -491,12 +491,15 @@ FFmpegPresets::FFmpegPresets()
FFmpegPresets::~FFmpegPresets()
{
XMLFileWriter writer;
// FIXME: TRAP_ERR Catch XMLFileWriterException
wxFileName xmlFileName(FileNames::DataDir(), wxT("ffmpeg_presets.xml"));
writer.Open(xmlFileName.GetFullPath(),wxT("wb"));
WriteXMLHeader(writer);
WriteXML(writer);
// We're in a destructor! Don't let exceptions out!
GuardedCall< void >( [&] {
wxFileName xmlFileName{ FileNames::DataDir(), wxT("ffmpeg_presets.xml") };
XMLFileWriter writer{
xmlFileName.GetFullPath(), _("Error Saving FFmpeg Presets") };
WriteXMLHeader(writer);
WriteXML(writer);
writer.Commit();
} );
}
void FFmpegPresets::ImportPresets(wxString &filename)
@@ -515,11 +518,12 @@ void FFmpegPresets::ImportPresets(wxString &filename)
void FFmpegPresets::ExportPresets(wxString &filename)
{
XMLFileWriter writer;
// FIXME: TRAP_ERR Catch XMLFileWriterException
writer.Open(filename,wxT("wb"));
WriteXMLHeader(writer);
WriteXML(writer);
GuardedCall< void >( [&] {
XMLFileWriter writer{ filename, _("Error Saving FFmpeg Presets") };
WriteXMLHeader(writer);
WriteXML(writer);
writer.Commit();
} );
}
void FFmpegPresets::GetPresetList(wxArrayString &list)