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 --- plugins/Dbx_mdbx/src/dbcrypt.cpp | 11 ++++----- plugins/Dbx_mdbx/src/dbintf.h | 12 +++++----- plugins/Dbx_mdbx/src/ui.cpp | 52 ++-------------------------------------- 3 files changed, 13 insertions(+), 62 deletions(-) (limited to 'plugins/Dbx_mdbx/src') diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp index 9f41b534e5..fc2803eadd 100644 --- a/plugins/Dbx_mdbx/src/dbcrypt.cpp +++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp @@ -94,17 +94,16 @@ STDMETHODIMP_(BOOL) CDbxMDBX::StoreProvider(CRYPTO_PROVIDER *pProv) ///////////////////////////////////////////////////////////////////////////////////////// -int CDbxMDBX::EnableEncryption(bool bEncrypted) +STDMETHODIMP_(BOOL) CDbxMDBX::EnableEncryption(BOOL bEncrypted) { if (m_bEncrypted == bEncrypted) - return 0; + return TRUE; std::vector lstEvents; MDBX_stat st; mdbx_dbi_stat(StartTran(), m_dbEvents, &st, sizeof(st)); lstEvents.reserve(st.ms_entries); - { MDBX_val key, data; cursor_ptr pCursor(StartTran(), m_dbEvents); @@ -157,7 +156,7 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted) memcpy(pNewDBEvent + 1, pNewBlob, nNewBlob); if (mdbx_put(trnlck, m_dbEvents, &key, &data, MDBX_UPSERT) != MDBX_SUCCESS) - return 1; + return FALSE; } } @@ -169,10 +168,10 @@ int CDbxMDBX::EnableEncryption(bool bEncrypted) txn_ptr trnlck(this); MDBX_val key = { DBKey_Crypto_IsEncrypted, sizeof(DBKey_Crypto_IsEncrypted) }, value = { &bEncrypted, sizeof(bool) }; if (mdbx_put(trnlck, m_dbCrypto, &key, &value, MDBX_UPSERT) != MDBX_SUCCESS) - return 1; + return FALSE; } DBFlush(); m_bEncrypted = bEncrypted; - return 0; + return TRUE; } diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index 502b126ff4..ce7ecda46e 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -231,7 +231,6 @@ public: int Check(void); void DBFlush(bool bForce = false); - int EnableEncryption(bool bEnable); int Load(); int Map(); @@ -273,13 +272,14 @@ public: STDMETHODIMP_(BOOL) MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) override; STDMETHODIMP_(BOOL) MetaRemoveSubHistory(DBCachedContact *ccSub) override; - STDMETHODIMP_(CRYPTO_PROVIDER*) ReadProvider(void); - STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*); + STDMETHODIMP_(CRYPTO_PROVIDER*) ReadProvider(void) override; + STDMETHODIMP_(BOOL) StoreProvider(CRYPTO_PROVIDER*) override; - STDMETHODIMP_(BOOL) ReadEncryption(void); + STDMETHODIMP_(BOOL) EnableEncryption(BOOL) override; + STDMETHODIMP_(BOOL) ReadEncryption(void) override; - STDMETHODIMP_(BOOL) ReadCryptoKey(MBinBuffer&); - STDMETHODIMP_(BOOL) StoreCryptoKey(void); + STDMETHODIMP_(BOOL) ReadCryptoKey(MBinBuffer&) override; + STDMETHODIMP_(BOOL) StoreCryptoKey(void) override; STDMETHODIMP_(BOOL) Compact(); STDMETHODIMP_(BOOL) Backup(const wchar_t*); diff --git a/plugins/Dbx_mdbx/src/ui.cpp b/plugins/Dbx_mdbx/src/ui.cpp index e32df8d296..ced24c801d 100644 --- a/plugins/Dbx_mdbx/src/ui.cpp +++ b/plugins/Dbx_mdbx/src/ui.cpp @@ -37,63 +37,15 @@ static INT_PTR CompactMe(void* obj, WPARAM, LPARAM) ///////////////////////////////////////////////////////////////////////////////////////// -class COptionsDialog : public CDlgBase -{ - CCtrlCheck m_chkStandart; - CCtrlCheck m_chkTotal; - CDbxMDBX *m_db; - - 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; - } - -public: - COptionsDialog(CDbxMDBX *db) : - CDlgBase(g_plugin, IDD_OPTIONS), - m_chkStandart(this, IDC_STANDARD), - m_chkTotal(this, IDC_TOTAL), - m_db(db) - { - } -}; - -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 COptionsDialog((CDbxMDBX*)obj); - g_plugin.addOptions(wParam, &odp); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - static IconItem iconList[] = { { LPGEN("Compact"), "compact", IDI_COMPACT } }; -static int OnModulesLoaded(PVOID obj, WPARAM, LPARAM) +static int OnModulesLoaded(WPARAM, LPARAM) { g_plugin.registerIcon(LPGEN("Database"), iconList, "mdbx"); - HookEventObj(ME_OPT_INITIALISE, OnOptionsInit, obj); - // main menu item CMenuItem mi(&g_plugin); mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Database"), 500000000, 0); @@ -113,5 +65,5 @@ void CDbxMDBX::InitDialogs() { hService[0] = CreateServiceFunctionObj(MS_DB_COMPACT, CompactMe, this); - hHook = HookEventObj(ME_SYSTEM_MODULESLOADED, OnModulesLoaded, this); + hHook = HookEvent(ME_SYSTEM_MODULESLOADED, OnModulesLoaded); } -- cgit v1.2.3