diff options
author | George Hazan <ghazan@miranda.im> | 2021-03-23 21:39:45 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2021-03-23 21:39:45 +0300 |
commit | 42143e9cf3719630ab370e9369764cdaac892821 (patch) | |
tree | 0a7a1fb5f81b5baca71a7a44d04eab13b37a586a | |
parent | 607caf0454cda589ce0b84eb8d2c8e6b5613aec0 (diff) |
fixes #2771 (Implement mdbx → sqlite converter)
-rw-r--r-- | include/m_db_int.h | 8 | ||||
-rw-r--r-- | libs/win32/mir_app.lib | bin | 219414 -> 219744 bytes | |||
-rw-r--r-- | libs/win64/mir_app.lib | bin | 215246 -> 215586 bytes | |||
-rw-r--r-- | plugins/Db3x_mmap/src/init.cpp | 47 | ||||
-rw-r--r-- | plugins/Dbx_mdbx/src/init.cpp | 6 | ||||
-rw-r--r-- | src/mir_app/mir_app.vcxproj | 1 | ||||
-rw-r--r-- | src/mir_app/mir_app.vcxproj.filters | 3 | ||||
-rw-r--r-- | src/mir_app/src/db_upgrade.cpp | 70 | ||||
-rw-r--r-- | src/mir_app/src/mir_app.def | 1 | ||||
-rw-r--r-- | src/mir_app/src/mir_app64.def | 1 |
10 files changed, 92 insertions, 45 deletions
diff --git a/include/m_db_int.h b/include/m_db_int.h index 71adc82826..aadd36998d 100644 --- a/include/m_db_int.h +++ b/include/m_db_int.h @@ -394,4 +394,12 @@ EXTERN_C MIR_APP_DLL(DATABASELINK*) GetDatabasePlugin(const char *pszDriverName) // returns DATABASELINK* of the required plugin or nullptr on error
EXTERN_C MIR_APP_DLL(DATABASELINK*) FindDatabasePlugin(const wchar_t *ptszFileName);
+/////////////////////////////////////////////////////////////////////////////////////////
+// database upgrader
+
+namespace DB
+{
+ MIR_APP_DLL(MDatabaseCommon *) Upgrade(const wchar_t *profile);
+}
+
#endif // M_DB_INT_H__
diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib Binary files differindex ecc006eed5..b699bc461f 100644 --- a/libs/win32/mir_app.lib +++ b/libs/win32/mir_app.lib diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib Binary files differindex bccf85997a..aa4a40118e 100644 --- a/libs/win64/mir_app.lib +++ b/libs/win64/mir_app.lib 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;
diff --git a/src/mir_app/mir_app.vcxproj b/src/mir_app/mir_app.vcxproj index e1281e19e6..4af6e20925 100644 --- a/src/mir_app/mir_app.vcxproj +++ b/src/mir_app/mir_app.vcxproj @@ -60,6 +60,7 @@ <ClCompile Include="src\db_events.cpp" />
<ClCompile Include="src\db_ini.cpp" />
<ClCompile Include="src\db_intf.cpp" />
+ <ClCompile Include="src\db_upgrade.cpp" />
<ClCompile Include="src\db_util.cpp" />
<ClCompile Include="src\descbutton.cpp" />
<ClCompile Include="src\dll_sniffer.cpp" />
diff --git a/src/mir_app/mir_app.vcxproj.filters b/src/mir_app/mir_app.vcxproj.filters index 49ad63544f..8c239e56a1 100644 --- a/src/mir_app/mir_app.vcxproj.filters +++ b/src/mir_app/mir_app.vcxproj.filters @@ -392,6 +392,9 @@ <ClCompile Include="src\MDatabaseCommonCrypt.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\db_upgrade.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\chat.h">
diff --git a/src/mir_app/src/db_upgrade.cpp b/src/mir_app/src/db_upgrade.cpp new file mode 100644 index 0000000000..f221bd20a9 --- /dev/null +++ b/src/mir_app/src/db_upgrade.cpp @@ -0,0 +1,70 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (C) 2012-21 Miranda NG team, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "stdafx.h" + +#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_sqlite 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") + +///////////////////////////////////////////////////////////////////////////////////////// + +MIR_APP_DLL(MDatabaseCommon*) DB::Upgrade(const wchar_t *profile) +{ + DATABASELINK *pLink = GetDatabasePlugin("dbx_sqlite"); + if (pLink == nullptr) { + if (IDYES == MessageBoxW(nullptr, TranslateT(MISSING_DB_MSG), L"Miranda NG", MB_YESNO)) + Utils_OpenUrl("https://miranda-ng.org/p/Dbx_sqlite"); + 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); +} diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 4b96d291ad..89f5e022ce 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -774,3 +774,4 @@ _Netlib_GetTlsUnique@8 @831 NONAME ?Flush@MDatabaseCommon@@UAGHXZ @862 NONAME
?getIcon@CHAT_MANAGER@@QBGPAUHICON__@@H@Z @863 NONAME
?getSoundName@GCSessionInfoBase@@QBEPBDH@Z @864 NONAME
+?Upgrade@DB@@YGPAVMDatabaseCommon@@PB_W@Z @865 NONAME
diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index bc23f0f01b..91e38bbdfc 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -774,3 +774,4 @@ Netlib_GetTlsUnique @831 NONAME ?Flush@MDatabaseCommon@@UEAAHXZ @862 NONAME
?getIcon@CHAT_MANAGER@@QEBAPEAUHICON__@@H@Z @863 NONAME
?getSoundName@GCSessionInfoBase@@QEBAPEBDH@Z @864 NONAME
+?Upgrade@DB@@YAPEAVMDatabaseCommon@@PEB_W@Z @865 NONAME
|