mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-17 16:40:07 +02:00
Function for repeated check whether it is safe to overwrite project
This commit is contained in:
parent
1bed51ac80
commit
97cf411dd5
@ -813,24 +813,8 @@ bool AudacityApp::MRUOpen(const FilePath &fullPathStr) {
|
|||||||
if (ProjectFileManager::IsAlreadyOpen(fullPathStr))
|
if (ProjectFileManager::IsAlreadyOpen(fullPathStr))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// DMM: If the project is dirty, that means it's been touched at
|
if (proj && !ProjectManager::SafeToOpenProjectInto(*proj))
|
||||||
// all, and it's not safe to open a NEW project directly in its
|
|
||||||
// place. Only if the project is brand-NEW clean and the user
|
|
||||||
// hasn't done any action at all is it safe for Open to take place
|
|
||||||
// inside the current project.
|
|
||||||
//
|
|
||||||
// If you try to Open a NEW project inside the current window when
|
|
||||||
// there are no tracks, but there's an Undo history, etc, then
|
|
||||||
// bad things can happen, including data files moving to the NEW
|
|
||||||
// project directory, etc.
|
|
||||||
if (proj && (
|
|
||||||
ProjectHistory::Get( *proj ).GetDirty() ||
|
|
||||||
!TrackList::Get( *proj ).empty()
|
|
||||||
) )
|
|
||||||
proj = nullptr;
|
proj = nullptr;
|
||||||
// This project is clean; it's never been touched. Therefore
|
|
||||||
// all relevant member variables are in their initial state,
|
|
||||||
// and it's okay to open a NEW project inside this window.
|
|
||||||
( void ) ProjectManager::OpenProject( proj, fullPathStr );
|
( void ) ProjectManager::OpenProject( proj, fullPathStr );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -871,27 +871,33 @@ void ProjectManager::OpenFiles(AudacityProject *proj)
|
|||||||
if (ProjectFileManager::IsAlreadyOpen(fileName))
|
if (ProjectFileManager::IsAlreadyOpen(fileName))
|
||||||
continue; // Skip ones that are already open.
|
continue; // Skip ones that are already open.
|
||||||
|
|
||||||
|
if (proj && !SafeToOpenProjectInto(*proj))
|
||||||
|
proj = nullptr;
|
||||||
|
proj = OpenProject( proj, fileName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ProjectManager::SafeToOpenProjectInto(AudacityProject &proj)
|
||||||
|
{
|
||||||
// DMM: If the project is dirty, that means it's been touched at
|
// DMM: If the project is dirty, that means it's been touched at
|
||||||
// all, and it's not safe to open a NEW project directly in its
|
// all, and it's not safe to open a fresh project directly in its
|
||||||
// place. Only if the project is brand-NEW clean and the user
|
// place. Only if the project is brandnew clean and the user
|
||||||
// hasn't done any action at all is it safe for Open to take place
|
// hasn't done any action at all is it safe for Open to take place
|
||||||
// inside the current project.
|
// inside the current project.
|
||||||
//
|
//
|
||||||
// If you try to Open a NEW project inside the current window when
|
// If you try to Open a fresh project inside the current window when
|
||||||
// there are no tracks, but there's an Undo history, etc, then
|
// there are no tracks, but there's an Undo history, etc, then
|
||||||
// bad things can happen, including data files moving to the NEW
|
// bad things can happen, including orphan blocks, or tracks
|
||||||
// project directory, etc.
|
// referring to non-existent blocks
|
||||||
if ( proj && (
|
if (
|
||||||
ProjectHistory::Get( *proj ).GetDirty() ||
|
ProjectHistory::Get( proj ).GetDirty() ||
|
||||||
!TrackList::Get( *proj ).empty()
|
!TrackList::Get( proj ).empty()
|
||||||
) )
|
)
|
||||||
proj = nullptr;
|
return false;
|
||||||
|
|
||||||
// This project is clean; it's never been touched. Therefore
|
// This project is clean; it's never been touched. Therefore
|
||||||
// all relevant member variables are in their initial state,
|
// all relevant member variables are in their initial state,
|
||||||
// and it's okay to open a NEW project inside this window.
|
// and it's okay to open a NEW project inside its window.
|
||||||
proj = OpenProject( proj, fileName );
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AudacityProject *ProjectManager::OpenProject(
|
AudacityProject *ProjectManager::OpenProject(
|
||||||
|
@ -45,6 +45,9 @@ public:
|
|||||||
// reason remains in this class, not in ProjectFileManager
|
// reason remains in this class, not in ProjectFileManager
|
||||||
static void OpenFiles(AudacityProject *proj);
|
static void OpenFiles(AudacityProject *proj);
|
||||||
|
|
||||||
|
//! False when it is unsafe to overwrite proj with contents of an .aup3 file
|
||||||
|
static bool SafeToOpenProjectInto(AudacityProject &proj);
|
||||||
|
|
||||||
// Return the given project if that is not NULL, else create a project.
|
// Return the given project if that is not NULL, else create a project.
|
||||||
// Then open the given project path.
|
// Then open the given project path.
|
||||||
// But if an exception escapes this function, create no NEW project.
|
// But if an exception escapes this function, create no NEW project.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user