mirror of
https://github.com/cookiengineer/audacity
synced 2025-07-12 14:47:43 +02:00
Bug2596: Error dialogs opening unreadable project should not be blank
This commit is contained in:
parent
54359fbefd
commit
5ebfe4670c
@ -38,8 +38,11 @@ static const char *FastConfig =
|
||||
"PRAGMA <schema>.synchronous = OFF;"
|
||||
"PRAGMA <schema>.journal_mode = OFF;";
|
||||
|
||||
DBConnection::DBConnection(const std::weak_ptr<AudacityProject> &pProject)
|
||||
DBConnection::DBConnection(
|
||||
const std::weak_ptr<AudacityProject> &pProject,
|
||||
const std::shared_ptr<DBConnectionErrors> &pErrors)
|
||||
: mpProject{ pProject }
|
||||
, mpErrors{ pErrors }
|
||||
{
|
||||
mDB = nullptr;
|
||||
mBypass = false;
|
||||
@ -63,21 +66,21 @@ bool DBConnection::ShouldBypass()
|
||||
void DBConnection::SetError(
|
||||
const TranslatableString &msg, const TranslatableString &libraryError)
|
||||
{
|
||||
mLastError = msg;
|
||||
mLibraryError = libraryError;
|
||||
mpErrors->mLastError = msg;
|
||||
mpErrors->mLibraryError = libraryError;
|
||||
}
|
||||
|
||||
void DBConnection::SetDBError(
|
||||
const TranslatableString &msg, const TranslatableString &libraryError)
|
||||
{
|
||||
mLastError = msg;
|
||||
wxLogDebug(wxT("SQLite error: %s"), mLastError.Debug());
|
||||
printf(" Lib error: %s", mLastError.Debug().mb_str().data());
|
||||
mpErrors->mLastError = msg;
|
||||
wxLogDebug(wxT("SQLite error: %s"), mpErrors->mLastError.Debug());
|
||||
printf(" Lib error: %s", mpErrors->mLastError.Debug().mb_str().data());
|
||||
|
||||
mLibraryError = libraryError.empty()
|
||||
mpErrors->mLibraryError = libraryError.empty()
|
||||
? Verbatim(sqlite3_errmsg(DB())) : libraryError;
|
||||
wxLogDebug(wxT(" Lib error: %s"), mLibraryError.Debug());
|
||||
printf(" Lib error: %s", mLibraryError.Debug().mb_str().data());
|
||||
wxLogDebug(wxT(" Lib error: %s"), mpErrors->mLibraryError.Debug());
|
||||
printf(" Lib error: %s", mpErrors->mLibraryError.Debug().mb_str().data());
|
||||
|
||||
wxASSERT(false);
|
||||
}
|
||||
|
@ -26,11 +26,19 @@ struct sqlite3_stmt;
|
||||
class wxString;
|
||||
class AudacityProject;
|
||||
|
||||
struct DBConnectionErrors
|
||||
{
|
||||
TranslatableString mLastError;
|
||||
TranslatableString mLibraryError;
|
||||
};
|
||||
|
||||
class DBConnection
|
||||
{
|
||||
public:
|
||||
explicit
|
||||
DBConnection(const std::weak_ptr<AudacityProject> &pProject);
|
||||
|
||||
DBConnection(
|
||||
const std::weak_ptr<AudacityProject> &pProject,
|
||||
const std::shared_ptr<DBConnectionErrors> &pErrors);
|
||||
~DBConnection();
|
||||
|
||||
bool Open(const char *fileName);
|
||||
@ -79,11 +87,6 @@ public:
|
||||
const TranslatableString &msg,
|
||||
const TranslatableString &libraryError = {} );
|
||||
|
||||
const TranslatableString &GetLastError() const
|
||||
{ return mLastError; }
|
||||
const TranslatableString &GetLibraryError() const
|
||||
{ return mLibraryError; }
|
||||
|
||||
private:
|
||||
bool ModeConfig(sqlite3 *db, const char *schema, const char *config);
|
||||
|
||||
@ -103,8 +106,7 @@ private:
|
||||
|
||||
std::map<enum StatementID, sqlite3_stmt *> mStatements;
|
||||
|
||||
TranslatableString mLastError;
|
||||
TranslatableString mLibraryError;
|
||||
std::shared_ptr<DBConnectionErrors> mpErrors;
|
||||
|
||||
// Bypass transactions if database will be deleted after close
|
||||
bool mBypass;
|
||||
|
@ -247,6 +247,7 @@ const ProjectFileIO &ProjectFileIO::Get( const AudacityProject &project )
|
||||
|
||||
ProjectFileIO::ProjectFileIO(AudacityProject &project)
|
||||
: mProject{ project }
|
||||
, mpErrors{ std::make_shared<DBConnectionErrors>() }
|
||||
{
|
||||
mPrevConn = nullptr;
|
||||
|
||||
@ -318,7 +319,8 @@ bool ProjectFileIO::OpenConnection(FilePath fileName /* = {} */)
|
||||
}
|
||||
|
||||
// Pass weak_ptr to project into DBConnection constructor
|
||||
curConn = std::make_unique<DBConnection>(mProject.shared_from_this());
|
||||
curConn = std::make_unique<DBConnection>(
|
||||
mProject.shared_from_this(), mpErrors);
|
||||
if (!curConn->Open(fileName))
|
||||
{
|
||||
curConn.reset();
|
||||
@ -2049,7 +2051,8 @@ bool ProjectFileIO::SaveProject(
|
||||
}
|
||||
|
||||
// Open the newly created database
|
||||
Connection newConn = std::make_unique<DBConnection>(mProject.shared_from_this());
|
||||
Connection newConn = std::make_unique<DBConnection>(
|
||||
mProject.shared_from_this(), mpErrors);
|
||||
|
||||
// NOTE: There is a noticeable delay here when dealing with large multi-hour
|
||||
// projects that we just created. The delay occurs in Open() when it
|
||||
@ -2270,14 +2273,12 @@ wxLongLong ProjectFileIO::GetFreeDiskSpace() const
|
||||
|
||||
const TranslatableString &ProjectFileIO::GetLastError()
|
||||
{
|
||||
auto &currConn = CurrConn();
|
||||
return currConn->GetLastError();
|
||||
return mpErrors->mLastError;
|
||||
}
|
||||
|
||||
const TranslatableString &ProjectFileIO::GetLibraryError()
|
||||
{
|
||||
auto &currConn = CurrConn();
|
||||
return currConn->GetLibraryError();
|
||||
return mpErrors->mLibraryError;
|
||||
}
|
||||
|
||||
void ProjectFileIO::SetError(
|
||||
|
@ -25,6 +25,7 @@ struct sqlite3_value;
|
||||
|
||||
class AudacityProject;
|
||||
class DBConnection;
|
||||
struct DBConnectionErrors;
|
||||
class ProjectSerializer;
|
||||
class SqliteSampleBlock;
|
||||
class TrackList;
|
||||
@ -253,6 +254,8 @@ private:
|
||||
// non-static data members
|
||||
AudacityProject &mProject;
|
||||
|
||||
std::shared_ptr<DBConnectionErrors> mpErrors;
|
||||
|
||||
// The project's file path
|
||||
FilePath mFileName;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user