From bb8e49d3e4a63cceaa9a68ef62229d87c1792535 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Sun, 15 Oct 2023 19:53:52 +0300 Subject: =?UTF-8?q?fixes=20#3738=20(CrashDumper:=20=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B1=D0=BE=D1=87=D0=BD=D1=8B=D0=B9=20=D0=BF=D0=BE=D0=BA=D0=B0?= =?UTF-8?q?=D0=B7=20=D0=B0=D0=BA=D1=82=D0=B8=D0=B2=D0=BD=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=B6=D1=83=D1=80=D0=BD=D0=B0=D0=BB=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/m_srmm_int.h | 20 +++++++++++++++++++ libs/win32/mir_app.lib | Bin 271936 -> 272382 bytes libs/win64/mir_app.lib | Bin 271108 -> 271564 bytes plugins/CrashDumper/src/dumper.cpp | 6 ++++-- plugins/CrashDumper/src/stdafx.h | 1 + src/mir_app/src/chat.h | 2 -- src/mir_app/src/mir_app.def | 1 + src/mir_app/src/mir_app64.def | 1 + src/mir_app/src/srmm_base.cpp | 13 ++++++++----- src/mir_app/src/srmm_log.cpp | 38 +++++++++++++------------------------ 10 files changed, 48 insertions(+), 34 deletions(-) diff --git a/include/m_srmm_int.h b/include/m_srmm_int.h index 5e11a4b95a..4be18ba906 100644 --- a/include/m_srmm_int.h +++ b/include/m_srmm_int.h @@ -153,6 +153,26 @@ MIR_APP_DLL(void) UnregisterSrmmLog(HANDLE); MIR_APP_DLL(bool) Srmm_IsCustomLogUsed(); +///////////////////////////////////////////////////////////////////////////////////////// +// SRMM log window class + +struct SrmmLogWindowClass +{ + SrmmLogWindowClass(CMPlugin *p1, const char *p2, const wchar_t *p3, pfnSrmmLogCreator p4) : + pPlugin(p1), + szShortName(mir_strdup(p2)), + wszScreenName(mir_wstrdup(p3)), + pfnBuilder(p4) + {} + + CMPlugin *pPlugin; + ptrA szShortName; + ptrW wszScreenName; + pfnSrmmLogCreator pfnBuilder; +}; + +MIR_APP_DLL(SrmmLogWindowClass *) Srmm_GetWindowClass(CMsgDialog *pDlg); + ///////////////////////////////////////////////////////////////////////////////////////// // Simple single-event based logger diff --git a/libs/win32/mir_app.lib b/libs/win32/mir_app.lib index b5d4a97c1e..d625caaa61 100644 Binary files a/libs/win32/mir_app.lib and b/libs/win32/mir_app.lib differ diff --git a/libs/win64/mir_app.lib b/libs/win64/mir_app.lib index ed1f24f383..66a8412127 100644 Binary files a/libs/win64/mir_app.lib and b/libs/win64/mir_app.lib differ diff --git a/plugins/CrashDumper/src/dumper.cpp b/plugins/CrashDumper/src/dumper.cpp index a7797da086..86bf2ebf47 100644 --- a/plugins/CrashDumper/src/dumper.cpp +++ b/plugins/CrashDumper/src/dumper.cpp @@ -142,8 +142,10 @@ static void GetPluginsString(CMStringW &buffer, unsigned &flags) { buffer.AppendFormat(L"Service Mode: %s\r\n", g_plugin.bServiceMode ? L"Yes" : L"No"); - CMStringW szViewerName(db_get_wsm(0, "SRMM", "Logger", L"built-in")); - buffer.AppendFormat(L"SRMM Log Viewer: %s\r\n", szViewerName.c_str()); + if (auto *pLogClass = Srmm_GetWindowClass(0)) + buffer.AppendFormat(L"SRMM Log Viewer: %s\r\n", _A2T(pLogClass->szShortName).get()); + else + buffer.AppendFormat(L"SRMM Log Viewer: %s\r\n", L"missing"); wchar_t path[MAX_PATH]; GetModuleFileName(nullptr, path, MAX_PATH); diff --git a/plugins/CrashDumper/src/stdafx.h b/plugins/CrashDumper/src/stdafx.h index dfe9421cb0..72c153afed 100644 --- a/plugins/CrashDumper/src/stdafx.h +++ b/plugins/CrashDumper/src/stdafx.h @@ -37,6 +37,7 @@ along with this program. If not, see . #include #include #include +#include #include #include "m_folders.h" diff --git a/src/mir_app/src/chat.h b/src/mir_app/src/chat.h index 6ba50be865..3f4fcc8dda 100644 --- a/src/mir_app/src/chat.h +++ b/src/mir_app/src/chat.h @@ -129,8 +129,6 @@ BOOL DoTrayIcon(SESSION_INFO *si, GCEVENT *gce); BOOL DoPopup(SESSION_INFO *si, GCEVENT *gce); int ShowPopup(MCONTACT hContact, SESSION_INFO *si, HICON hIcon, char* pszProtoName, wchar_t* pszRoomName, COLORREF crBkg, const wchar_t* fmt, ...); -CSrmmLogWindow *Srmm_GetLogWindow(CMsgDialog *pDlg); - void Chat_EventToGC(SESSION_INFO *si, MEVENT hDbEvent); void Chat_RemoveContact(MCONTACT hContact); diff --git a/src/mir_app/src/mir_app.def b/src/mir_app/src/mir_app.def index 8359cb841b..fb83d97f00 100644 --- a/src/mir_app/src/mir_app.def +++ b/src/mir_app/src/mir_app.def @@ -907,3 +907,4 @@ Clist_GroupSaveExpanded @1003 NONAME ?GetInput@CSrmmBaseDialog@@QBEPAUHWND__@@XZ @1024 NONAME ?Srmm_ApplyOptions@@YGXXZ @1025 NONAME ?OnOptionsApplied@CSrmmBaseDialog@@UAEXXZ @1026 NONAME +?Srmm_GetWindowClass@@YGPAUSrmmLogWindowClass@@PAVCMsgDialog@@@Z @1027 NONAME diff --git a/src/mir_app/src/mir_app64.def b/src/mir_app/src/mir_app64.def index 7cedefa3d5..d977ff1183 100644 --- a/src/mir_app/src/mir_app64.def +++ b/src/mir_app/src/mir_app64.def @@ -907,3 +907,4 @@ Clist_GroupSaveExpanded @1003 NONAME ?GetInput@CSrmmBaseDialog@@QEBAPEAUHWND__@@XZ @1024 NONAME ?Srmm_ApplyOptions@@YAXXZ @1025 NONAME ?OnOptionsApplied@CSrmmBaseDialog@@UEAAXXZ @1026 NONAME +?Srmm_GetWindowClass@@YAPEAUSrmmLogWindowClass@@PEAVCMsgDialog@@@Z @1027 NONAME diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp index 6176b753d1..d8572c2700 100644 --- a/src/mir_app/src/srmm_base.cpp +++ b/src/mir_app/src/srmm_base.cpp @@ -519,11 +519,14 @@ bool CSrmmBaseDialog::OnInitDialog() WindowList_Add(g_hWindowList, m_hwnd, m_hContact); SetWindowLongPtr(m_hwnd, GWLP_USERDATA, (LONG_PTR)this); - m_pLog = Srmm_GetLogWindow((CMsgDialog*)this); - m_pLog->Attach(); - if (m_pLog->GetType() != 0) { // custom log type - DestroyWindow(GetDlgItem(m_hwnd, IDC_SRMM_LOG)); - SetWindowLong(m_pLog->GetHwnd(), GWLP_ID, IDC_SRMM_LOG); + auto *pDlg = (CMsgDialog *)this; + if (auto *pLogWindowClass = Srmm_GetWindowClass(pDlg)) { + m_pLog = pLogWindowClass->pfnBuilder(*pDlg); + m_pLog->Attach(); + if (m_pLog->GetType() != 0) { // custom log type + DestroyWindow(GetDlgItem(m_hwnd, IDC_SRMM_LOG)); + SetWindowLong(m_pLog->GetHwnd(), GWLP_ID, IDC_SRMM_LOG); + } } SetWindowLongPtr(m_message.GetHwnd(), GWLP_USERDATA, LPARAM(this)); diff --git a/src/mir_app/src/srmm_log.cpp b/src/mir_app/src/srmm_log.cpp index b91204a59c..647304eb86 100644 --- a/src/mir_app/src/srmm_log.cpp +++ b/src/mir_app/src/srmm_log.cpp @@ -27,22 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "stdafx.h" #include "chat.h" -struct LoggerClass -{ - LoggerClass(CMPlugin *p1, const char *p2, const wchar_t *p3, pfnSrmmLogCreator p4) : - pPlugin(p1), - szShortName(mir_strdup(p2)), - wszScreenName(mir_wstrdup(p3)), - pfnBuilder(p4) - {} - - CMPlugin *pPlugin; - ptrA szShortName; - ptrW wszScreenName; - pfnSrmmLogCreator pfnBuilder; -}; - -static OBJLIST g_arLogClasses(1, PtrKeySortT); +static OBJLIST g_arLogClasses(1, PtrKeySortT); static CMOption g_logger(SRMM_MODULE, "Logger", "built-in"); @@ -51,7 +36,7 @@ static CMOption g_logger(SRMM_MODULE, "Logger", "built-in"); static bool sttEnableCustomLogs(CMsgDialog *pDlg) { // always enable custom log viewers for private chats - if (!pDlg->isChat()) + if (!pDlg || !pDlg->isChat()) return true; // if custom log viewers are disable, use build-in one @@ -79,21 +64,23 @@ static bool sttEnableCustomLogs(CMsgDialog *pDlg) return true; } -CSrmmLogWindow* Srmm_GetLogWindow(CMsgDialog *pDlg) +MIR_APP_DLL(SrmmLogWindowClass *) Srmm_GetWindowClass(CMsgDialog *pDlg) { if (sttEnableCustomLogs(pDlg)) { - CMStringA szViewerName(db_get_sm(pDlg->m_hContact, SRMSGMOD, "Logger")); + CMStringA szViewerName; + if (pDlg != nullptr) + szViewerName = db_get_sm(pDlg->m_hContact, SRMSGMOD, "Logger"); if (szViewerName.IsEmpty()) szViewerName = g_logger; for (auto &it : g_arLogClasses) if (szViewerName == it->szShortName) - return it->pfnBuilder(*pDlg); + return it; } for (auto &it : g_arLogClasses) if (!mir_strcmp(it->szShortName, "built-in")) - return it->pfnBuilder(*pDlg); + return it; return nullptr; // shall never happen } @@ -141,9 +128,10 @@ public: { pDialog = this; + auto *pClass = Srmm_GetWindowClass(0); for (auto &it : g_arLogClasses) { int idx = m_list.AddString(TranslateW_LP(it->wszScreenName, it->pPlugin), LPARAM(it)); - if (!mir_strcmp(g_logger, it->szShortName)) + if (it == pClass) m_list.SetCurSel(idx); } @@ -156,7 +144,7 @@ public: if (idx == -1) return false; - if (auto *pLogger = (LoggerClass *)m_list.GetItemData(idx)) + if (auto *pLogger = (SrmmLogWindowClass *)m_list.GetItemData(idx)) g_logger = pLogger->szShortName; PostMessage(m_hwndParent, WM_CLOSE, 1, 0); @@ -199,7 +187,7 @@ MIR_APP_DLL(HANDLE) RegisterSrmmLog(CMPlugin *pPlugin, const char *pszShortName, if (!pszShortName || !pwszScreenName || !fnBuilder) return nullptr; - auto *p = new LoggerClass(pPlugin, pszShortName, pwszScreenName, fnBuilder); + auto *p = new SrmmLogWindowClass(pPlugin, pszShortName, pwszScreenName, fnBuilder); g_arLogClasses.insert(p); if (pDialog) @@ -209,7 +197,7 @@ MIR_APP_DLL(HANDLE) RegisterSrmmLog(CMPlugin *pPlugin, const char *pszShortName, MIR_APP_DLL(void) UnregisterSrmmLog(HANDLE pLogger) { - g_arLogClasses.remove((LoggerClass *)pLogger); + g_arLogClasses.remove((SrmmLogWindowClass *)pLogger); if (pDialog) pDialog->Rebuild(); -- cgit v1.2.3