From 42143e9cf3719630ab370e9369764cdaac892821 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 23 Mar 2021 21:39:45 +0300 Subject: =?UTF-8?q?fixes=20#2771=20(Implement=20mdbx=20=E2=86=92=20sqlite?= =?UTF-8?q?=20converter)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/Db3x_mmap/src/init.cpp | 47 +++--------------------------------------- plugins/Dbx_mdbx/src/init.cpp | 6 +++++- 2 files changed, 8 insertions(+), 45 deletions(-) (limited to 'plugins') diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp index 5523236de0..f677d02a28 100644 --- a/plugins/Db3x_mmap/src/init.cpp +++ b/plugins/Db3x_mmap/src/init.cpp @@ -68,53 +68,12 @@ static int grokHeader(const wchar_t *profile) return db->CheckDbHeaders(false); } -// returns 0 if all the APIs are injected otherwise, 1 -#define CONVERT_MSG LPGEN("This database is in old format that isn't supported anymore. Press Yes to convert it to the new format or No to return back") -#define MISSING_DB_MSG LPGEN("To open this database you need to install the dbx_mdbx plugin. Click Yes to download it from Miranda NG's site or No to return back") -#define MISSING_PLUG_MSG LPGEN("To open this database you need to install the Import plugin. Click Yes to download it from Miranda NG's site or No to return back") - +// returns a pointer to a database instance if all the APIs are injected, otherwise NULL static MDatabaseCommon* LoadDatabase(const wchar_t *profile, BOOL bReadOnly) { - //////////////////////////////////////////////////////////////////////////////////////// // if not read only, convert the old profile to libmdbx - if (!bReadOnly) { - DATABASELINK *pLink = GetDatabasePlugin("dbx_mdbx"); - if (pLink == nullptr) { - if (IDYES == MessageBoxW(nullptr, TranslateT(MISSING_DB_MSG), L"Miranda NG", MB_YESNO)) - Utils_OpenUrl("https://miranda-ng.org/p/Dbx_mdbx"); - return nullptr; - } - - if (!Profile_GetSettingInt(L"Database/SilentUpgrade")) - if (IDYES != MessageBoxW(nullptr, TranslateT(CONVERT_MSG), L"Miranda NG", MB_YESNO)) - return nullptr; - - int errorCode; - CMStringW wszBackupName(profile); - wszBackupName.Append(L".bak"); - if (!MoveFileW(profile, wszBackupName)) { - DWORD dwError = GetLastError(); - CMStringW wszError(FORMAT, TranslateT("Cannot move old profile '%s' to '%s': error %d"), profile, wszBackupName.c_str(), dwError); - MessageBoxW(nullptr, wszError, L"Miranda NG", MB_ICONERROR | MB_OK); - return nullptr; - } - - if ((errorCode = pLink->makeDatabase(profile)) != 0) { - MessageBoxW(nullptr, CMStringW(FORMAT, TranslateT("Attempt to create database '%s' failed with error code %d"), profile, errorCode), L"Miranda NG", MB_ICONERROR | MB_OK); -LBL_Error: - DeleteFileW(profile); - MoveFileW(wszBackupName, profile); - return nullptr; - } - - if (SetServiceModePlugin(L"import", 1) != ERROR_SUCCESS) { - if (IDYES == MessageBoxW(nullptr, TranslateT(MISSING_PLUG_MSG), L"Miranda NG", MB_YESNO)) - Utils_OpenUrl("https://miranda-ng.org/p/Import"); - goto LBL_Error; - } - - return pLink->Load(profile, false); - } + if (!bReadOnly) + return DB::Upgrade(profile); std::unique_ptr db(new CDb3Mmap(profile, DBMODE_READONLY)); if (db->Load(false) != ERROR_SUCCESS) diff --git a/plugins/Dbx_mdbx/src/init.cpp b/plugins/Dbx_mdbx/src/init.cpp index 2741fe2341..cc9c47f265 100644 --- a/plugins/Dbx_mdbx/src/init.cpp +++ b/plugins/Dbx_mdbx/src/init.cpp @@ -74,9 +74,13 @@ static int grokHeader(const wchar_t *profile) return db->Check(); } -// returns 0 if all the APIs are injected otherwise, 1 +// returns a pointer to a database instance if all the APIs are injected, otherwise NULL static MDatabaseCommon* loadDatabase(const wchar_t *profile, BOOL bReadOnly) { + // if not read only, convert the old profile to SQLITE + if (!bReadOnly) + return DB::Upgrade(profile); + std::unique_ptr db(new CDbxMDBX(profile, (bReadOnly) ? DBMODE_READONLY : 0)); if (db->Map() != ERROR_SUCCESS) return nullptr; -- cgit v1.2.3