summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2021-03-23 21:39:45 +0300
committerGeorge Hazan <ghazan@miranda.im>2021-03-23 21:39:45 +0300
commit42143e9cf3719630ab370e9369764cdaac892821 (patch)
tree0a7a1fb5f81b5baca71a7a44d04eab13b37a586a /plugins
parent607caf0454cda589ce0b84eb8d2c8e6b5613aec0 (diff)
fixes #2771 (Implement mdbx → sqlite converter)
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Db3x_mmap/src/init.cpp47
-rw-r--r--plugins/Dbx_mdbx/src/init.cpp6
2 files changed, 8 insertions, 45 deletions
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<CDb3Mmap> 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<CDbxMDBX> db(new CDbxMDBX(profile, (bReadOnly) ? DBMODE_READONLY : 0));
if (db->Map() != ERROR_SUCCESS)
return nullptr;