Audacity 3.2.0
Public Member Functions | Private Attributes | List of all members
ProjectFileIO::BackupProject Class Reference

#include <ProjectFileIO.h>

Public Member Functions

 BackupProject (ProjectFileIO &projectFileIO, const FilePath &path)
 Rename project file at path, and any auxiliary files, to backup path names. More...
 
bool IsOk ()
 Returns false if the renaming in the constructor failed. More...
 
void Discard ()
 if !IsOk() do nothing; else remove backup files More...
 
 ~BackupProject ()
 if !IsOk() do nothing; else if Discard() was not called, undo the renaming More...
 

Private Attributes

FilePath mPath
 
FilePath mSafety
 

Detailed Description

Definition at line 190 of file ProjectFileIO.h.

Constructor & Destructor Documentation

◆ BackupProject()

ProjectFileIO::BackupProject::BackupProject ( ProjectFileIO projectFileIO,
const FilePath path 
)

Rename project file at path, and any auxiliary files, to backup path names.

Definition at line 1371 of file ProjectFileIO.cpp.

1373{
1374 auto safety = SafetyFileName(path);
1375 if (!projectFileIO.MoveProject(path, safety))
1376 return;
1377
1378 mPath = path;
1379 mSafety = safety;
1380}
bool MoveProject(const FilePath &src, const FilePath &dst)
static FilePath SafetyFileName(const FilePath &src)
Generate a name for short-lived backup project files from an existing project.

References ProjectFileIO::MoveProject(), mPath, mSafety, and ProjectFileIO::SafetyFileName().

Here is the call graph for this function:

◆ ~BackupProject()

ProjectFileIO::BackupProject::~BackupProject ( )

if !IsOk() do nothing; else if Discard() was not called, undo the renaming

Definition at line 1391 of file ProjectFileIO.cpp.

1392{
1393 if (!mPath.empty()) {
1394 if (!mSafety.empty()) {
1395 // Failed; restore from safety files
1396 auto suffixes = AuxiliaryFileSuffixes();
1397 suffixes.push_back({});
1398 for (const auto &suffix : suffixes) {
1399 auto path = mPath + suffix;
1400 if (wxFileExists(path))
1401 wxRemoveFile(path);
1402 wxRenameFile(mSafety + suffix, mPath + suffix);
1403 }
1404 }
1405 }
1406}
static const std::vector< wxString > & AuxiliaryFileSuffixes()

References ProjectFileIO::AuxiliaryFileSuffixes().

Here is the call graph for this function:

Member Function Documentation

◆ Discard()

void ProjectFileIO::BackupProject::Discard ( )

if !IsOk() do nothing; else remove backup files

Definition at line 1382 of file ProjectFileIO.cpp.

1383{
1384 if (!mPath.empty()) {
1385 // Succeeded; don't need the safety files
1387 mSafety.clear();
1388 }
1389}
static bool RemoveProject(const FilePath &filename)
Remove any files associated with a project at given path; return true if successful.

References ProjectFileIO::RemoveProject().

Here is the call graph for this function:

◆ IsOk()

bool ProjectFileIO::BackupProject::IsOk ( )
inline

Returns false if the renaming in the constructor failed.

Definition at line 195 of file ProjectFileIO.h.

195{ return !mPath.empty(); }

Member Data Documentation

◆ mPath

FilePath ProjectFileIO::BackupProject::mPath
private

Definition at line 201 of file ProjectFileIO.h.

Referenced by BackupProject().

◆ mSafety

FilePath ProjectFileIO::BackupProject::mSafety
private

Definition at line 201 of file ProjectFileIO.h.

Referenced by BackupProject().


The documentation for this class was generated from the following files: