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

1261 {
1262  auto safety = SafetyFileName(path);
1263  if (!projectFileIO.MoveProject(path, safety))
1264  return;
1265 
1266  mPath = path;
1267  mSafety = safety;
1268 }

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

1280 {
1281  if (!mPath.empty()) {
1282  if (!mSafety.empty()) {
1283  // Failed; restore from safety files
1284  auto suffixes = AuxiliaryFileSuffixes();
1285  suffixes.push_back({});
1286  for (const auto &suffix : suffixes) {
1287  auto path = mPath + suffix;
1288  if (wxFileExists(path))
1289  wxRemoveFile(path);
1290  wxRenameFile(mSafety + suffix, mPath + suffix);
1291  }
1292  }
1293  }
1294 }

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

1271 {
1272  if (!mPath.empty()) {
1273  // Succeeded; don't need the safety files
1275  mSafety.clear();
1276  }
1277 }

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 166 of file ProjectFileIO.h.

166 { 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 172 of file ProjectFileIO.h.

Referenced by BackupProject().

◆ mSafety

FilePath ProjectFileIO::BackupProject::mSafety
private

Definition at line 172 of file ProjectFileIO.h.

Referenced by BackupProject().


The documentation for this class was generated from the following files:
ProjectFileIO::AuxiliaryFileSuffixes
static const std::vector< wxString > & AuxiliaryFileSuffixes()
Definition: ProjectFileIO.cpp:1117
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:1244
ProjectFileIO::SafetyFileName
static FilePath SafetyFileName(const FilePath &src)
Generate a name for short-lived backup project files from an existing project.
Definition: ProjectFileIO.cpp:1128
ProjectFileIO::BackupProject::mPath
FilePath mPath
Definition: ProjectFileIO.h:172
ProjectFileIO::BackupProject::mSafety
FilePath mSafety
Definition: ProjectFileIO.h:172
ProjectFileIO::MoveProject
bool MoveProject(const FilePath &src, const FilePath &dst)
Definition: ProjectFileIO.cpp:1207