Audacity  3.0.3
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 163 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 1270 of file ProjectFileIO.cpp.

1272 {
1273  auto safety = SafetyFileName(path);
1274  if (!projectFileIO.MoveProject(path, safety))
1275  return;
1276 
1277  mPath = path;
1278  mSafety = safety;
1279 }

References ProjectFileIO::MoveProject(), 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 1290 of file ProjectFileIO.cpp.

1291 {
1292  if (!mPath.empty()) {
1293  if (!mSafety.empty()) {
1294  // Failed; restore from safety files
1295  auto suffixes = AuxiliaryFileSuffixes();
1296  suffixes.push_back({});
1297  for (const auto &suffix : suffixes) {
1298  auto path = mPath + suffix;
1299  if (wxFileExists(path))
1300  wxRemoveFile(path);
1301  wxRenameFile(mSafety + suffix, mPath + suffix);
1302  }
1303  }
1304  }
1305 }

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

1282 {
1283  if (!mPath.empty()) {
1284  // Succeeded; don't need the safety files
1286  mSafety.clear();
1287  }
1288 }

References ProjectFileIO::RemoveProject().

Referenced by ProjectFileManager::DoSave().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsOk()

bool ProjectFileIO::BackupProject::IsOk ( )
inline

Returns false if the renaming in the constructor failed.

Definition at line 168 of file ProjectFileIO.h.

168 { return !mPath.empty(); }

Referenced by ProjectFileManager::DoSave().

Here is the caller graph for this function:

Member Data Documentation

◆ mPath

FilePath ProjectFileIO::BackupProject::mPath
private

Definition at line 174 of file ProjectFileIO.h.

◆ mSafety

FilePath ProjectFileIO::BackupProject::mSafety
private

Definition at line 174 of file ProjectFileIO.h.


The documentation for this class was generated from the following files:
ProjectFileIO::AuxiliaryFileSuffixes
static const std::vector< wxString > & AuxiliaryFileSuffixes()
Definition: ProjectFileIO.cpp:1132
ProjectFileIO::RemoveProject
static bool RemoveProject(const FilePath &filename)
Remove any files associated with a project at given path; return true if successful.
Definition: ProjectFileIO.cpp:1255
ProjectFileIO::SafetyFileName
static FilePath SafetyFileName(const FilePath &src)
Generate a name for short-lived backup project files from an existing project.
Definition: ProjectFileIO.cpp:1143
ProjectFileIO::BackupProject::mPath
FilePath mPath
Definition: ProjectFileIO.h:174
ProjectFileIO::BackupProject::mSafety
FilePath mSafety
Definition: ProjectFileIO.h:174
ProjectFileIO::MoveProject
bool MoveProject(const FilePath &src, const FilePath &dst)
Definition: ProjectFileIO.cpp:1218