From cbe4e96467fe7ef3c3e7147526f55d1de9564f2b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 8 Jan 2021 20:50:42 +0300 Subject: database options dialog also went into the core --- src/mir_app/res/resource.rc | 13 ++++++++ src/mir_app/src/MDatabaseCommonCrypt.cpp | 56 ++++++++++++++++++++++++++++++++ src/mir_app/src/MDatabaseReadonly.cpp | 5 +++ src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/resource.h | 3 ++ 6 files changed, 79 insertions(+) (limited to 'src') diff --git a/src/mir_app/res/resource.rc b/src/mir_app/res/resource.rc index bc6d0d9d75..cd5f6037e3 100644 --- a/src/mir_app/res/resource.rc +++ b/src/mir_app/res/resource.rc @@ -939,6 +939,19 @@ BEGIN LTEXT "Old password",IDC_STATIC,11,31,140,10,0,WS_EX_TRANSPARENT END +IDD_OPT_DATABASE DIALOGEX 0, 0, 318, 176 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + GROUPBOX "Database encryption mode",IDC_STATIC,6,22,305,125 + CONTROL "Standard",IDC_STANDARD,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,12,38,292,12 + CONTROL "Total",IDC_TOTAL,"Button",BS_AUTORADIOBUTTON | WS_TABSTOP,12,95,292,12 + LTEXT "Only critical data are encrypted (passwords, security tokens, etc). All other settings and history remains unencrypted. Fast and effective, suitable for the most cases",IDC_STATIC,22,54,284,37 + LTEXT "All string settings and all events in histories are encrypted. It also makes Miranda much slower and creates a risk of losing everything you've stored in a database in case of losing password. Recommended only for paranoid users",IDC_STATIC,22,110,284,33 + PUSHBUTTON "Set password",IDC_USERPASS1,200,153,111,17 +END + ///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO diff --git a/src/mir_app/src/MDatabaseCommonCrypt.cpp b/src/mir_app/src/MDatabaseCommonCrypt.cpp index 6418f46c24..9f98445219 100644 --- a/src/mir_app/src/MDatabaseCommonCrypt.cpp +++ b/src/mir_app/src/MDatabaseCommonCrypt.cpp @@ -259,12 +259,68 @@ static INT_PTR ChangePassword(void* obj, WPARAM, LPARAM) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// +// Options + +class CDatabaseOptionsDialog : public CDlgBase +{ + CCtrlCheck m_chkStandart, m_chkTotal; + CCtrlButton m_btnChangePass; + MDatabaseCommon *m_db; + +public: + CDatabaseOptionsDialog(MDatabaseCommon *db) : + CDlgBase(g_plugin, IDD_OPT_DATABASE), + m_db(db), + m_chkTotal(this, IDC_TOTAL), + m_chkStandart(this, IDC_STANDARD), + m_btnChangePass(this, IDC_USERPASS1) + { + m_btnChangePass.OnClick = Callback(this, &CDatabaseOptionsDialog::onClick_ChangePass); + } + + bool OnInitDialog() override + { + m_chkStandart.SetState(!m_db->isEncrypted()); + m_chkTotal.SetState(m_db->isEncrypted()); + return true; + } + + bool OnApply() override + { + SetCursor(LoadCursor(nullptr, IDC_WAIT)); + m_db->EnableEncryption(m_chkTotal.GetState() != 0); + SetCursor(LoadCursor(nullptr, IDC_ARROW)); + m_chkStandart.SetState(!m_db->isEncrypted()); + m_chkTotal.SetState(m_db->isEncrypted()); + return true; + } + + void onClick_ChangePass(CCtrlButton *) + { + ChangePassword(m_db, 0, 0); + } +}; + +static int OnOptionsInit(PVOID obj, WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; + odp.position = -790000000; + odp.flags = ODPF_BOLDGROUPS; + odp.szTitle.a = LPGEN("Database"); + odp.pDialog = new CDatabaseOptionsDialog((MDatabaseCommon*)obj); + g_plugin.addOptions(wParam, &odp); + return 0; +} + ///////////////////////////////////////////////////////////////////////////////////////// static int OnModulesLoaded(PVOID obj, WPARAM, LPARAM) { MDatabaseCommon *db = (MDatabaseCommon *)obj; + HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, obj); + // main menu item CMenuItem mi(&g_plugin); mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Database"), 500000000, g_plugin.getIconHandle(IDI_DATABASE)); diff --git a/src/mir_app/src/MDatabaseReadonly.cpp b/src/mir_app/src/MDatabaseReadonly.cpp index a1fef48769..e19c09e4aa 100644 --- a/src/mir_app/src/MDatabaseReadonly.cpp +++ b/src/mir_app/src/MDatabaseReadonly.cpp @@ -64,6 +64,11 @@ STDMETHODIMP_(BOOL) MDatabaseReadonly::StoreProvider(CRYPTO_PROVIDER *) return FALSE; } +STDMETHODIMP_(BOOL) MDatabaseReadonly::EnableEncryption(BOOL) +{ + return FALSE; +} + STDMETHODIMP_(BOOL) MDatabaseReadonly::ReadEncryption() { return FALSE; diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 7d9719b261..25c60a0135 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -768,3 +768,4 @@ _Netlib_GetTlsUnique@8 @831 NONAME ?StoreCryptoKey@MDatabaseReadonly@@UAGHXZ @856 NONAME ?usesPassword@MDatabaseCommon@@QBE_NXZ @857 NONAME ?SetPassword@MDatabaseCommon@@QAEXPB_W@Z @858 NONAME +?EnableEncryption@MDatabaseReadonly@@UAGHH@Z @859 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 3d5b36d584..f347c13879 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -768,3 +768,4 @@ Netlib_GetTlsUnique @831 NONAME ?StoreCryptoKey@MDatabaseReadonly@@UEAAHXZ @856 NONAME ?usesPassword@MDatabaseCommon@@QEBA_NXZ @857 NONAME ?SetPassword@MDatabaseCommon@@QEAAXPEB_W@Z @858 NONAME +?EnableEncryption@MDatabaseReadonly@@UEAAHH@Z @859 NONAME diff --git a/src/mir_app/src/resource.h b/src/mir_app/src/resource.h index ec6bc9f321..196878cf94 100644 --- a/src/mir_app/src/resource.h +++ b/src/mir_app/src/resource.h @@ -32,6 +32,7 @@ #define IDD_LOGIN 123 #define IDI_DATABASE 124 #define IDD_DETAILS 125 +#define IDD_OPT_DATABASE 126 #define IDD_HISTORY 127 #define IDI_AWAY 128 #define IDI_FREE4CHAT 129 @@ -529,6 +530,8 @@ #define IDC_PLUGINURL 1682 #define IDC_PLUGINPID 1683 #define IDC_IDLESPIN 1687 +#define IDC_STANDARD 1688 +#define IDC_TOTAL 1689 #define IDC_NODBDRIVERS 1690 #define IDC_IDLESTATUSLOCK 1691 #define IDC_RESTART 1692 -- cgit v1.2.3