From 3ca5d1f7ab3f9f9159b57ea930dd6f7a343af68d Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 15 Nov 2020 13:36:09 +0300 Subject: Dbx_mdbx: code cleaning --- plugins/Dbx_mdbx/src/dbcrypt.cpp | 7 ++++--- plugins/Dbx_mdbx/src/dbintf.cpp | 21 +++++++++------------ plugins/Dbx_mdbx/src/dbintf.h | 27 ++++++++++++++------------- plugins/Dbx_mdbx/src/init.cpp | 6 +++--- plugins/Dbx_mdbx/src/ui.cpp | 8 ++++---- 5 files changed, 34 insertions(+), 35 deletions(-) diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp index 77aa233ff8..61a7b13dd1 100644 --- a/plugins/Dbx_mdbx/src/dbcrypt.cpp +++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp @@ -122,15 +122,16 @@ CRYPTO_PROVIDER* CDbxMDBX::SelectProvider() class CEnterPasswordDialog : public CDlgBase { + friend class CDbxMDBX; + CTimer m_timer; CCtrlData m_header; CCtrlData m_language; CCtrlEdit m_passwordEdit; - friend class CDbxMDBX; + int m_wrongPass = 0; + wchar_t m_newPass[100]; CDbxMDBX *m_db; - TCHAR m_newPass[100]; - unsigned short m_wrongPass = 0; void OnTimer(CTimer*) { diff --git a/plugins/Dbx_mdbx/src/dbintf.cpp b/plugins/Dbx_mdbx/src/dbintf.cpp index 6626204834..8631d6f4bd 100644 --- a/plugins/Dbx_mdbx/src/dbintf.cpp +++ b/plugins/Dbx_mdbx/src/dbintf.cpp @@ -26,16 +26,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ///////////////////////////////////////////////////////////////////////////////////////// // constructor & destructor -CDbxMDBX::CDbxMDBX(const TCHAR *tszFileName, int iMode) : +CDbxMDBX::CDbxMDBX(const wchar_t *tszFileName, int iMode) : m_safetyMode(true), m_bReadOnly((iMode & DBMODE_READONLY) != 0), m_bShared((iMode & DBMODE_SHARED) != 0), m_maxContactId(0), + m_pwszProfileName(mir_wstrdup(tszFileName)), m_impl(*this) { m_ccDummy.nSubs = -1; - - m_tszProfileName = mir_wstrdup(tszFileName); } CDbxMDBX::~CDbxMDBX() @@ -51,8 +50,6 @@ CDbxMDBX::~CDbxMDBX() if (m_crypto) m_crypto->destroy(); - - mir_free(m_tszProfileName); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -138,7 +135,7 @@ BYTE bDefHeader[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; int CDbxMDBX::Check(void) { - FILE *pFile = _wfopen(m_tszProfileName, L"rb"); + FILE *pFile = _wfopen(m_pwszProfileName, L"rb"); if (pFile == nullptr) return EGROKPRF_CANTREAD; @@ -156,7 +153,7 @@ int CDbxMDBX::Check(void) BOOL CDbxMDBX::Compact() { - CMStringW wszTmpFile(FORMAT, L"%s.tmp", m_tszProfileName); + CMStringW wszTmpFile(FORMAT, L"%s.tmp", m_pwszProfileName.get()); mir_cslock lck(m_csDbAccess); int res = Backup(wszTmpFile); @@ -165,8 +162,8 @@ BOOL CDbxMDBX::Compact() mdbx_env_close(m_env); - DeleteFileW(m_tszProfileName); - MoveFileW(wszTmpFile, m_tszProfileName); + DeleteFileW(m_pwszProfileName); + MoveFileW(wszTmpFile, m_pwszProfileName); Map(); Load(); @@ -229,7 +226,7 @@ static void assert_func(const MDBX_env*, const char *msg, const char *function, int CDbxMDBX::Map() { - if (!LockName(m_tszProfileName)) + if (!LockName(m_pwszProfileName)) return EGROKPRF_CANTREAD; mdbx_env_create(&m_env); @@ -259,7 +256,7 @@ int CDbxMDBX::Map() if (m_bReadOnly) mode |= MDBX_RDONLY; - if (mdbx_env_open(m_env, _T2A(m_tszProfileName), mode, 0664) != MDBX_SUCCESS) + if (mdbx_env_open(m_env, _T2A(m_pwszProfileName), mode, 0664) != MDBX_SUCCESS) return EGROKPRF_CANTREAD; return EGROKPRF_NOERROR; @@ -275,7 +272,7 @@ void CDbxMDBX::TouchFile() FILETIME ft; SystemTimeToFileTime(&st, &ft); - HANDLE hFile = CreateFileW(m_tszProfileName, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); + HANDLE hFile = CreateFileW(m_pwszProfileName, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (hFile != INVALID_HANDLE_VALUE) { SetFileTime(hFile, nullptr, &ft, &ft); CloseHandle(hFile); diff --git a/plugins/Dbx_mdbx/src/dbintf.h b/plugins/Dbx_mdbx/src/dbintf.h index 9dadb8a8fc..b5adf457f9 100644 --- a/plugins/Dbx_mdbx/src/dbintf.h +++ b/plugins/Dbx_mdbx/src/dbintf.h @@ -139,6 +139,7 @@ struct EventItem class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroedObject { friend class CMdbxEventCursor; + typedef std::map TModuleMap; struct Impl { CDbxMDBX &pro; @@ -177,15 +178,15 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe //////////////////////////////////////////////////////////////////////////// // database stuff - TCHAR* m_tszProfileName; - bool m_safetyMode, m_bReadOnly, m_bShared, m_bEncrypted, m_bUsesPassword; + ptrW m_pwszProfileName; + bool m_safetyMode, m_bReadOnly, m_bShared, m_bEncrypted, m_bUsesPassword; MDBX_env *m_env; CMDBX_txn_ro m_txn_ro; int m_dbError; - MDBX_dbi m_dbGlobal; - DBHeader m_header; + MDBX_dbi m_dbGlobal; + DBHeader m_header; DBCachedContact m_ccDummy; // dummy contact to serve a cache item for MCONTACT = 0 @@ -195,7 +196,7 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe MDBX_dbi m_dbSettings; MDBX_cursor *m_curSettings; - HANDLE hService[2], hHook; + HANDLE hService[2], hHook; //////////////////////////////////////////////////////////////////////////// // contacts @@ -203,9 +204,9 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe MDBX_dbi m_dbContacts; MDBX_cursor *m_curContacts; - MCONTACT m_maxContactId; + MCONTACT m_maxContactId; - void GatherContactHistory(MCONTACT hContact, OBJLIST &items); + void GatherContactHistory(MCONTACT hContact, OBJLIST &items); //////////////////////////////////////////////////////////////////////////// // events @@ -214,7 +215,7 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe MDBX_cursor *m_curEvents, *m_curEventsSort, *m_curEventIds; MEVENT m_dwMaxEventId; - void FindNextUnread(const txn_ptr &_txn, DBCachedContact *cc, DBEventSortingKey &key2); + void FindNextUnread(const txn_ptr &_txn, DBCachedContact *cc, DBEventSortingKey &key2); //////////////////////////////////////////////////////////////////////////// // modules @@ -222,12 +223,12 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe MDBX_dbi m_dbModules; MDBX_cursor *m_curModules; - std::map m_Modules; + TModuleMap m_Modules; - int InitModules(); + int InitModules(); - uint32_t GetModuleID(const char *szName); - char* GetModuleName(uint32_t dwId); + uint32_t GetModuleID(const char *szName); + char* GetModuleName(uint32_t dwId); //////////////////////////////////////////////////////////////////////////// // encryption @@ -240,7 +241,7 @@ class CDbxMDBX : public MDatabaseCommon, public MIDatabaseChecker, public MZeroe void InitDialogs(); public: - CDbxMDBX(const TCHAR *tszFileName, int mode); + CDbxMDBX(const wchar_t *tszFileName, int mode); virtual ~CDbxMDBX(); int Check(void); diff --git a/plugins/Dbx_mdbx/src/init.cpp b/plugins/Dbx_mdbx/src/init.cpp index c91130f57f..266eb2b0fb 100644 --- a/plugins/Dbx_mdbx/src/init.cpp +++ b/plugins/Dbx_mdbx/src/init.cpp @@ -61,21 +61,21 @@ static void logger(MDBX_log_level_t type, const char *function, int line, const ///////////////////////////////////////////////////////////////////////////////////////// // returns 0 if the profile is created, EMKPRF* -static int makeDatabase(const TCHAR *profile) +static int makeDatabase(const wchar_t *profile) { std::unique_ptr db(new CDbxMDBX(profile, 0)); return db->Map(); } // returns 0 if the given profile has a valid header -static int grokHeader(const TCHAR *profile) +static int grokHeader(const wchar_t *profile) { std::unique_ptr db(new CDbxMDBX(profile, DBMODE_SHARED | DBMODE_READONLY)); return db->Check(); } // returns 0 if all the APIs are injected otherwise, 1 -static MDatabaseCommon* loadDatabase(const TCHAR *profile, BOOL bReadOnly) +static MDatabaseCommon* loadDatabase(const wchar_t *profile, BOOL bReadOnly) { std::unique_ptr db(new CDbxMDBX(profile, (bReadOnly) ? DBMODE_READONLY : 0)); if (db->Map() != ERROR_SUCCESS) diff --git a/plugins/Dbx_mdbx/src/ui.cpp b/plugins/Dbx_mdbx/src/ui.cpp index 81dee5f127..c788d5b0ec 100644 --- a/plugins/Dbx_mdbx/src/ui.cpp +++ b/plugins/Dbx_mdbx/src/ui.cpp @@ -45,7 +45,7 @@ static bool CheckOldPassword(HWND hwndDlg, CDbxMDBX *db) { if (db->usesPassword()) { - TCHAR buf[100]; + wchar_t buf[100]; GetDlgItemText(hwndDlg, IDC_OLDPASS, buf, _countof(buf)); pass_ptrA oldPass(mir_utf8encodeW(buf)); if (!db->m_crypto->checkPassword(oldPass)) @@ -60,14 +60,14 @@ static bool CheckOldPassword(HWND hwndDlg, CDbxMDBX *db) struct DlgChangePassParam { CDbxMDBX *db; - TCHAR newPass[100]; + wchar_t newPass[100]; unsigned short wrongPass; }; static INT_PTR CALLBACK sttChangePassword(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { DlgChangePassParam *param = (DlgChangePassParam*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - TCHAR buf[100]; + wchar_t buf[100]; switch (uMsg) { case WM_INITDIALOG: @@ -112,7 +112,7 @@ static INT_PTR CALLBACK sttChangePassword(HWND hwndDlg, UINT uMsg, WPARAM wParam break; case IDOK: - TCHAR buf2[100]; + wchar_t buf2[100]; GetDlgItemText(hwndDlg, IDC_USERPASS1, buf2, _countof(buf2)); if (wcslen(buf2) < 3) { SetDlgItemText(hwndDlg, IDC_HEADERBAR, TranslateT("Password is too short!")); -- cgit v1.2.3