MCPcopy Create free account
hub / github.com/audacity/audacity / XMLFileWriter

Method XMLFileWriter

libraries/lib-xml/XMLWriter.cpp:297–327  ·  view source on GitHub ↗

XMLFileWriter class

Source from the content-addressed store, hash-verified

295/// XMLFileWriter class
296///
297XMLFileWriter::XMLFileWriter(
298 const FilePath &outputPath, const TranslatableString &caption, bool keepBackup )
299 : mOutputPath{ outputPath }
300 , mCaption{ caption }
301 , mKeepBackup{ keepBackup }
302// may throw
303{
304 auto tempPath = wxFileName::CreateTempFileName( outputPath );
305 if (!wxFFile::Open(tempPath, wxT("wb")) || !IsOpened())
306 ThrowException( outputPath, mCaption );
307
308 if (mKeepBackup) {
309 int index = 0;
310 wxString backupName;
311
312 do {
313 wxFileName outputFn{ mOutputPath };
314 index++;
315 mBackupName =
316 outputFn.GetPath() + wxFILE_SEP_PATH +
317 outputFn.GetName() + wxT("_bak") +
318 wxString::Format(wxT("%d"), index) + wxT(".") +
319 outputFn.GetExt();
320 } while( ::wxFileExists( mBackupName ) );
321
322 // Open the backup file to be sure we can write it and reserve it
323 // until committing
324 if (! mBackupFile.Open( mBackupName, "wb" ) || ! mBackupFile.IsOpened() )
325 ThrowException( mBackupName, mCaption );
326 }
327}
328
329
330XMLFileWriter::~XMLFileWriter()

Callers

nothing calls this directly

Calls 4

IsOpenedMethod · 0.80
GetPathMethod · 0.45
GetNameMethod · 0.45
OpenMethod · 0.45

Tested by

no test coverage detected