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 --- src/mir_app/mir_app.vcxproj | 1 + src/mir_app/mir_app.vcxproj.filters | 3 ++ src/mir_app/src/db_upgrade.cpp | 70 +++++++++++++++++++++++++++++++++++++ src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + 5 files changed, 76 insertions(+) create mode 100644 src/mir_app/src/db_upgrade.cpp (limited to 'src/mir_app') 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 @@ + 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 @@ Source Files + + Source Files + 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 -- cgit v1.2.3