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 165 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 1439 of file ProjectFileIO.cpp.

1441{
1442 auto safety = SafetyFileName(path);
1443 if (!projectFileIO.MoveProject(path, safety))
1444 return;
1445
1446 mPath = path;
1447 mSafety = safety;
1448}
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 1459 of file ProjectFileIO.cpp.

1460{
1461 if (!mPath.empty()) {
1462 if (!mSafety.empty()) {
1463 // Failed; restore from safety files
1464 auto suffixes = AuxiliaryFileSuffixes();
1465 suffixes.push_back({});
1466 for (const auto &suffix : suffixes) {
1467 auto path = mPath + suffix;
1468 if (wxFileExists(path))
1469 wxRemoveFile(path);
1470 wxRenameFile(mSafety + suffix, mPath + suffix);
1471 }
1472 }
1473 }
1474}
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 1450 of file ProjectFileIO.cpp.

1451{
1452 if (!mPath.empty()) {
1453 // Succeeded; don't need the safety files
1455 mSafety.clear();
1456 }
1457}
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 170 of file ProjectFileIO.h.

170{ return !mPath.empty(); }

Member Data Documentation

◆ mPath

FilePath ProjectFileIO::BackupProject::mPath
private

Definition at line 176 of file ProjectFileIO.h.

Referenced by BackupProject().

◆ mSafety

FilePath ProjectFileIO::BackupProject::mSafety
private

Definition at line 176 of file ProjectFileIO.h.

Referenced by BackupProject().


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