summaryrefslogtreecommitdiff
path: root/src/mir_app
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 /src/mir_app
parent607caf0454cda589ce0b84eb8d2c8e6b5613aec0 (diff)
fixes #2771 (Implement mdbx → sqlite converter)
Diffstat (limited to 'src/mir_app')
-rw-r--r--src/mir_app/mir_app.vcxproj1
-rw-r--r--src/mir_app/mir_app.vcxproj.filters3
-rw-r--r--src/mir_app/src/db_upgrade.cpp70
-rw-r--r--src/mir_app/src/mir_app.def1
-rw-r--r--src/mir_app/src/mir_app64.def1
5 files changed, 76 insertions, 0 deletions
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