From f4d17396db574acd6f1fff5ab7997924c01ba1bc Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 22 Mar 2018 22:24:06 +0300 Subject: end of dbx_mmap plugin: any attempt to open such a database not in read-only mode causes automatic import into mdbx format --- plugins/Db3x_mmap/src/init.cpp | 52 ++++++++++++++++++++++++++++++++++++------ plugins/Db3x_mmap/src/stdafx.h | 2 ++ 2 files changed, 47 insertions(+), 7 deletions(-) (limited to 'plugins/Db3x_mmap') diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp index 57b5c8fd52..c02e4bcd19 100644 --- a/plugins/Db3x_mmap/src/init.cpp +++ b/plugins/Db3x_mmap/src/init.cpp @@ -23,6 +23,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" +EXTERN_C MIR_CORE_DLL(void) db_setCurrent(MIDatabase* _db); + int hLangpack; static PLUGININFOEX pluginInfo = @@ -46,13 +48,9 @@ LIST g_Dbs(1, HandleKeySortT); ///////////////////////////////////////////////////////////////////////////////////////// // returns 0 if the profile is created, EMKPRF* -static int makeDatabase(const wchar_t *profile) +static int makeDatabase(const wchar_t*) { - std::auto_ptr db(new CDb3Mmap(profile, 0)); - if (db->Create() != ERROR_SUCCESS) - return EMKPRF_CREATEFAILED; - - return db->CreateDbHeaders(dbSignatureU); + return EMKPRF_CREATEFAILED; } // returns 0 if the given profile has a valid header @@ -66,12 +64,52 @@ static int grokHeader(const wchar_t *profile) } // 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. Install it using Plugin Updater") +#define MISSING_PLUG_MSG LPGEN("To open this database you need to install the Import plugin. Install it using Plugin Updater") + static MDatabaseCommon* LoadDatabase(const wchar_t *profile, BOOL bReadOnly) { // set the memory, lists & UTF8 manager mir_getLP(&pluginInfo); - std::auto_ptr db(new CDb3Mmap(profile, (bReadOnly) ? DBMODE_READONLY : 0)); + //////////////////////////////////////////////////////////////////////////////////////// + // if not read only, convert the old profile to libmdbx + if (!bReadOnly) { + DATABASELINK *pLink = GetDatabasePlugin("dbx_mdbx"); + if (pLink == nullptr) { + MessageBoxW(nullptr, TranslateT(MISSING_DB_MSG), L"Miranda NG", MB_OK); + return nullptr; + } + + if (IDYES != MessageBoxW(nullptr, TranslateT(CONVERT_MSG), L"Miranda NG", MB_YESNOCANCEL)) + return nullptr; + + int errorCode; + CMStringW wszBackupName(profile); + wszBackupName.Append(L".bak"); + if (!MoveFileExW(profile, wszBackupName, MOVEFILE_WRITE_THROUGH | MOVEFILE_REPLACE_EXISTING)) { + Netlib_LogfW(nullptr, L"Cannot move old profile '%s' to '%s': error %d", profile, wszBackupName.c_str(), GetLastError()); + return nullptr; + } + + if ((errorCode = pLink->makeDatabase(profile)) != 0) { + Netlib_LogfW(nullptr, L"Database creation '%s' failed with error code %d", profile, errorCode); +LBL_Error: + DeleteFileW(profile); + MoveFileW(wszBackupName, profile); + return nullptr; + } + + if (SetServiceModePlugin(L"import") != SERVICE_ONLYDB) { + MessageBoxW(nullptr, TranslateT(MISSING_PLUG_MSG), L"Miranda NG", MB_OK); + goto LBL_Error; + } + + return pLink->Load(profile, false); + } + + std::auto_ptr db(new CDb3Mmap(profile, DBMODE_READONLY)); if (db->Load(false) != ERROR_SUCCESS) return nullptr; diff --git a/plugins/Db3x_mmap/src/stdafx.h b/plugins/Db3x_mmap/src/stdafx.h index c8e69d0601..83f98baddd 100644 --- a/plugins/Db3x_mmap/src/stdafx.h +++ b/plugins/Db3x_mmap/src/stdafx.h @@ -45,6 +45,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include +#include +#include #include "database.h" #include "dbintf.h" -- cgit v1.2.3