mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
AUP3: Make sure original file gets closed
When doing a Save As, make sure autosave doc is removed from the original project and the original project is properly closed. (The original project does NOT get compacted.)
This commit is contained in:
parent
1bbd7b3b52
commit
a4554d3631
@ -724,6 +724,7 @@ bool ProjectFileIO::DeleteBlocks(const BlockIDs &blockids, bool complement)
|
|||||||
|
|
||||||
Connection ProjectFileIO::CopyTo(const FilePath &destpath,
|
Connection ProjectFileIO::CopyTo(const FilePath &destpath,
|
||||||
const TranslatableString &msg,
|
const TranslatableString &msg,
|
||||||
|
bool isTemporary,
|
||||||
bool prune /* = false */,
|
bool prune /* = false */,
|
||||||
const std::shared_ptr<TrackList> &tracks /* = nullptr */)
|
const std::shared_ptr<TrackList> &tracks /* = nullptr */)
|
||||||
{
|
{
|
||||||
@ -903,7 +904,7 @@ Connection ProjectFileIO::CopyTo(const FilePath &destpath,
|
|||||||
// If we're compacting a temporary project (user initiated from the File
|
// If we're compacting a temporary project (user initiated from the File
|
||||||
// menu), then write the doc to the "autosave" table since temporary
|
// menu), then write the doc to the "autosave" table since temporary
|
||||||
// projects do not have a "project" doc.
|
// projects do not have a "project" doc.
|
||||||
if (!WriteDoc(mTemporary ? "autosave" : "project", doc, "outbound"))
|
if (!WriteDoc(isTemporary ? "autosave" : "project", doc, "outbound"))
|
||||||
{
|
{
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -1067,7 +1068,11 @@ void ProjectFileIO::Vacuum(const std::shared_ptr<TrackList> &tracks, bool force
|
|||||||
UseConnection(std::move(tempConn), tempName);
|
UseConnection(std::move(tempConn), tempName);
|
||||||
|
|
||||||
// Copy the original database to a new database while pruning unused sample blocks
|
// Copy the original database to a new database while pruning unused sample blocks
|
||||||
Connection newConn = CopyTo(origName, XO("Compacting project"), true, tracks);
|
Connection newConn = CopyTo(origName,
|
||||||
|
XO("Compacting project"),
|
||||||
|
mTemporary,
|
||||||
|
true,
|
||||||
|
tracks);
|
||||||
|
|
||||||
// Close connection referencing the original database via it's temporary name
|
// Close connection referencing the original database via it's temporary name
|
||||||
CloseConnection();
|
CloseConnection();
|
||||||
@ -1910,59 +1915,30 @@ bool ProjectFileIO::LoadProject(const FilePath &fileName)
|
|||||||
|
|
||||||
bool ProjectFileIO::SaveProject(const FilePath &fileName)
|
bool ProjectFileIO::SaveProject(const FilePath &fileName)
|
||||||
{
|
{
|
||||||
wxString origName;
|
|
||||||
bool wasTemp = false;
|
|
||||||
bool success = false;
|
|
||||||
Connection newConn = nullptr;
|
|
||||||
|
|
||||||
// If we're saving to a different file than the current one, then copy the
|
// If we're saving to a different file than the current one, then copy the
|
||||||
// current to the new file and make it the active file.
|
// current to the new file and make it the active file.
|
||||||
if (mFileName != fileName)
|
if (mFileName != fileName)
|
||||||
{
|
{
|
||||||
// Do NOT prune here since we need to retain the Undo history
|
// Do NOT prune here since we need to retain the Undo history
|
||||||
// after we switch to the new file.
|
// after we switch to the new file.
|
||||||
newConn = CopyTo(fileName, XO("Saving project"));
|
Connection newConn = CopyTo(fileName, XO("Saving project"), false);
|
||||||
if (!newConn)
|
if (!newConn)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remember the original project filename and temporary status.
|
// Autosave no longer needed in original project file
|
||||||
origName = mFileName;
|
AutoSaveDelete();
|
||||||
wasTemp = mTemporary;
|
|
||||||
|
|
||||||
// Save the original database connection and try to switch to a new one
|
// Save the original database connection and try to switch to a new one
|
||||||
// (also ensuring closing of one of the connections, with the cooperation
|
|
||||||
// of the finally below)
|
|
||||||
SaveConnection();
|
SaveConnection();
|
||||||
}
|
|
||||||
|
|
||||||
auto restore = finally([&]
|
|
||||||
{
|
|
||||||
if (!origName.empty())
|
|
||||||
{
|
|
||||||
if (success)
|
|
||||||
{
|
|
||||||
// The Save was successful, so now it is safe to abandon the
|
|
||||||
// original connection
|
|
||||||
DiscardConnection();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Close the new database and go back to using the original
|
|
||||||
// connection
|
|
||||||
RestoreConnection();
|
|
||||||
|
|
||||||
// And delete the new database
|
|
||||||
wxRemoveFile(fileName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!origName.empty())
|
|
||||||
{
|
|
||||||
// And make it the active project file
|
// And make it the active project file
|
||||||
UseConnection(std::move(newConn), fileName);
|
UseConnection(std::move(newConn), fileName);
|
||||||
|
|
||||||
|
// The Save was successful, so now it is safe to abandon the
|
||||||
|
// original connection
|
||||||
|
DiscardConnection();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -1994,15 +1970,12 @@ bool ProjectFileIO::SaveProject(const FilePath &fileName)
|
|||||||
// Adjust the title
|
// Adjust the title
|
||||||
SetProjectTitle();
|
SetProjectTitle();
|
||||||
|
|
||||||
// Tell the finally block to behave
|
|
||||||
success = true;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProjectFileIO::SaveCopy(const FilePath& fileName)
|
bool ProjectFileIO::SaveCopy(const FilePath& fileName)
|
||||||
{
|
{
|
||||||
Connection db = CopyTo(fileName, XO("Backing up project"), true);
|
Connection db = CopyTo(fileName, XO("Backing up project"), false, true);
|
||||||
if (!db)
|
if (!db)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -179,9 +179,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
// Return a database connection if successful, which caller must close
|
// Return a database connection if successful, which caller must close
|
||||||
Connection CopyTo(const FilePath &destpath,
|
Connection CopyTo(const FilePath &destpath,
|
||||||
const TranslatableString &msg,
|
const TranslatableString &msg,
|
||||||
bool prune = false,
|
bool isTemporary,
|
||||||
const std::shared_ptr<TrackList> &tracks = nullptr);
|
bool prune = false,
|
||||||
|
const std::shared_ptr<TrackList> &tracks = nullptr);
|
||||||
|
|
||||||
void SetError(const TranslatableString & msg);
|
void SetError(const TranslatableString & msg);
|
||||||
void SetDBError(const TranslatableString & msg);
|
void SetDBError(const TranslatableString & msg);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user