Bug2529: don't lose data when closing without saving on small drive (#650)
This commit is contained in:
parent
29f3361746
commit
1bb34e703e
|
@ -1885,6 +1885,24 @@ bool ProjectFileIO::LoadProject(const FilePath &fileName)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ProjectFileIO::UpdateSaved(
|
||||
const std::shared_ptr<TrackList> &tracks)
|
||||
{
|
||||
ProjectSerializer doc;
|
||||
WriteXMLHeader(doc);
|
||||
WriteXML(doc, false, tracks);
|
||||
|
||||
if (!WriteDoc("project", doc))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Autosave no longer needed
|
||||
AutoSaveDelete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectFileIO::SaveProject(const FilePath &fileName, const std::shared_ptr<TrackList> &lastSaved)
|
||||
{
|
||||
// In the case where we're saving a temporary project to a permanent project,
|
||||
|
@ -1986,17 +2004,8 @@ bool ProjectFileIO::SaveProject(const FilePath &fileName, const std::shared_ptr<
|
|||
}
|
||||
else
|
||||
{
|
||||
ProjectSerializer doc;
|
||||
WriteXMLHeader(doc);
|
||||
WriteXML(doc);
|
||||
|
||||
if (!WriteDoc("project", doc))
|
||||
{
|
||||
if ( !UpdateSaved( nullptr ) )
|
||||
return false;
|
||||
}
|
||||
|
||||
// Autosave no longer needed
|
||||
AutoSaveDelete();
|
||||
}
|
||||
|
||||
// Reaching this point defines success and all the rest are no-fail
|
||||
|
|
|
@ -84,6 +84,7 @@ public:
|
|||
|
||||
bool ImportProject(const FilePath &fileName);
|
||||
bool LoadProject(const FilePath &fileName);
|
||||
bool UpdateSaved(const std::shared_ptr<TrackList> &tracks = nullptr);
|
||||
bool SaveProject(const FilePath &fileName, const std::shared_ptr<TrackList> &lastSaved);
|
||||
bool SaveCopy(const FilePath& fileName);
|
||||
|
||||
|
|
|
@ -654,7 +654,7 @@ bool ProjectFileManager::SaveFromTimerRecording(wxFileName fnFile)
|
|||
return success;
|
||||
}
|
||||
|
||||
void ProjectFileManager::CompactProject()
|
||||
void ProjectFileManager::CompactProjectOnClose()
|
||||
{
|
||||
auto &project = mProject;
|
||||
auto &projectFileIO = ProjectFileIO::Get(project);
|
||||
|
@ -671,6 +671,15 @@ void ProjectFileManager::CompactProject()
|
|||
|
||||
// Attempt to compact the project
|
||||
projectFileIO.Compact(mLastSavedTracks);
|
||||
|
||||
if ( !projectFileIO.WasCompacted() &&
|
||||
UndoManager::Get( project ).UnsavedChanges() ) {
|
||||
// If compaction failed, we must do some work in case of close
|
||||
// without save. Don't leave the document blob from the last
|
||||
// push of undo history, when that undo state may get purged
|
||||
// with deletion of some new sample blocks.
|
||||
projectFileIO.UpdateSaved( mLastSavedTracks );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -689,7 +698,7 @@ void ProjectFileManager::CloseProject()
|
|||
|
||||
projectFileIO.CloseProject();
|
||||
|
||||
// Blocks were locked in CompactProject, so DELETE the data structure so that
|
||||
// Blocks were locked in CompactProjectOnClose, so DELETE the data structure so that
|
||||
// there's no memory leak.
|
||||
if (mLastSavedTracks)
|
||||
{
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
bool OpenProject();
|
||||
void CloseProject();
|
||||
|
||||
void CompactProject();
|
||||
void CompactProjectOnClose();
|
||||
|
||||
bool Save();
|
||||
bool SaveAs();
|
||||
|
|
|
@ -733,7 +733,7 @@ void ProjectManager::OnCloseWindow(wxCloseEvent & event)
|
|||
// SetMenuBar(NULL);
|
||||
|
||||
// Compact the project.
|
||||
projectFileManager.CompactProject();
|
||||
projectFileManager.CompactProjectOnClose();
|
||||
|
||||
// Set (or not) the bypass flag to indicate that deletes that would happen during
|
||||
// the UndoManager::ClearStates() below are not necessary.
|
||||
|
|
Loading…
Reference in New Issue