1
0
mirror of https://github.com/cookiengineer/audacity synced 2026-04-10 00:07:40 +02:00

Detect failure to reconnect to temp project when first saving it

This commit is contained in:
Paul Licameli
2020-12-06 22:14:54 -05:00
parent 41eb66fccf
commit aa0b33dc8f
5 changed files with 62 additions and 15 deletions

View File

@@ -44,6 +44,7 @@ Paul Licameli split from AudacityProject.cpp
wxDEFINE_EVENT(EVT_PROJECT_TITLE_CHANGE, wxCommandEvent);
wxDEFINE_EVENT( EVT_CHECKPOINT_FAILURE, wxCommandEvent);
wxDEFINE_EVENT( EVT_RECONNECTION_FAILURE, wxCommandEvent);
static const int ProjectFileID = ('A' << 24 | 'U' << 16 | 'D' << 8 | 'Y');
static const int ProjectFileVersion = 1;
@@ -263,6 +264,12 @@ ProjectFileIO::~ProjectFileIO()
{
}
bool ProjectFileIO::HasConnection() const
{
auto &connectionPtr = ConnectionPtr::Get( mProject );
return connectionPtr.mpConnection != nullptr;
}
DBConnection &ProjectFileIO::GetConnection()
{
auto &curConn = CurrConn();
@@ -2045,20 +2052,38 @@ bool ProjectFileIO::SaveProject(
FilePath savedName = mFileName;
if (CloseConnection())
{
if (MoveProject(savedName, fileName))
bool reopened = false;
bool moved = false;
if (true == (moved = MoveProject(savedName, fileName)))
{
if (!OpenConnection(fileName))
{
if (OpenConnection(fileName))
reopened = true;
else {
MoveProject(fileName, savedName);
OpenConnection(savedName);
reopened = OpenConnection(savedName);
}
}
else {
// Rename can fail -- if it's to a different device, requiring
// real copy of contents, which might exhaust space
OpenConnection(savedName);
return false;
reopened = OpenConnection(savedName);
}
if (!reopened)
wxTheApp->CallAfter([this]{
ShowErrorDialog(nullptr,
XO("Warning"),
XO(
"The project's database failed to reopen, "
"possibly because of limited space on the storage device."),
"Error:_Disk_full_or_not_writable"
);
wxCommandEvent evt{ EVT_RECONNECTION_FAILURE };
mProject.ProcessEvent(evt);
});
if (!moved)
return false;
}
}