From 90ac4c689e1322b48f6ca53a0c8fff81daf73c9c Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 10 Apr 2023 18:50:46 +0300 Subject: code cleaning --- plugins/AutoShutdown/src/watcher.cpp | 5 ++-- plugins/AvatarHistory/src/AvatarDlg.cpp | 5 ++-- plugins/Boltun/src/boltun.cpp | 4 +--- plugins/ContactsPlus/src/receive.cpp | 4 +--- plugins/DbChecker/src/worker.cpp | 6 ++--- plugins/HistoryLinkListPlus/src/linklist.cpp | 5 +--- plugins/HistoryLinkListPlus/src/linklist_fct.cpp | 19 +++++----------- plugins/IEView/src/HTMLBuilder.cpp | 5 ++-- plugins/MirandaG15/src/CAppletManager.cpp | 29 ++++++++++++------------ plugins/Msg_Export/src/utils.cpp | 5 ++-- plugins/NewEventNotify/src/popup.cpp | 5 +--- plugins/NewStory/src/history.cpp | 5 ++-- plugins/Scriver/src/msgdialog.cpp | 5 ++-- plugins/Scriver/src/msglog.cpp | 5 ++-- plugins/StopSpamMod/src/stopspam.cpp | 5 ++-- plugins/StopSpamPlus/src/events.cpp | 5 ++-- plugins/Variables/src/parse_miranda.cpp | 8 ++----- plugins/YARelay/src/main.cpp | 4 +--- plugins/wbOSD/src/events.cpp | 5 ++-- 19 files changed, 49 insertions(+), 85 deletions(-) (limited to 'plugins') diff --git a/plugins/AutoShutdown/src/watcher.cpp b/plugins/AutoShutdown/src/watcher.cpp index 17ced0e11a..271e619180 100644 --- a/plugins/AutoShutdown/src/watcher.cpp +++ b/plugins/AutoShutdown/src/watcher.cpp @@ -64,9 +64,8 @@ static void __inline ShutdownAndStopWatcher(void) static int MsgEventAdded(WPARAM, LPARAM hDbEvent) { if (currentWatcherType & SDWTF_MESSAGE) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return 0; if (dbei.eventType == EVENTTYPE_MESSAGE && !(dbei.flags & DBEF_SENT)) { diff --git a/plugins/AvatarHistory/src/AvatarDlg.cpp b/plugins/AvatarHistory/src/AvatarDlg.cpp index 8a76311ffa..11da22cfb6 100644 --- a/plugins/AvatarHistory/src/AvatarDlg.cpp +++ b/plugins/AvatarHistory/src/AvatarDlg.cpp @@ -412,9 +412,8 @@ int FillAvatarListFromDB(HWND list, MCONTACT hContact) int max_pos = 0; DB::ECPTR pCursor(DB::Events(hContact)); while (MEVENT hDbEvent = pCursor.FetchNext()) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) continue; if (dbei.eventType != EVENTTYPE_AVATAR_CHANGE) continue; diff --git a/plugins/Boltun/src/boltun.cpp b/plugins/Boltun/src/boltun.cpp index 95de2e9443..beaee86406 100644 --- a/plugins/Boltun/src/boltun.cpp +++ b/plugins/Boltun/src/boltun.cpp @@ -195,9 +195,7 @@ static int MessageEventAdded(WPARAM hContact, LPARAM hDbEvent) if (!BoltunAutoChat(hContact)) return 0; - DB::EventInfo dbei; - dbei.cbBlob = -1; - db_event_get(hDbEvent, &dbei); + DB::EventInfo dbei(hDbEvent); if (dbei.flags & DBEF_SENT || dbei.flags & DBEF_READ || dbei.eventType != EVENTTYPE_MESSAGE) return 0; diff --git a/plugins/ContactsPlus/src/receive.cpp b/plugins/ContactsPlus/src/receive.cpp index f3b0f2355b..2c122ea09c 100644 --- a/plugins/ContactsPlus/src/receive.cpp +++ b/plugins/ContactsPlus/src/receive.cpp @@ -196,9 +196,7 @@ INT_PTR CALLBACK RecvDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPara RebuildGroupCombo(hwndDlg); { // fill listview with received contacts - DB::EventInfo dbe; - dbe.cbBlob = -1; - db_event_get(wndData->mhDbEvent, &dbe); + DB::EventInfo dbe(wndData->mhDbEvent); char* pcBlob = (char*)dbe.pBlob; char* pcEnd = (char*)dbe.pBlob + dbe.cbBlob; diff --git a/plugins/DbChecker/src/worker.cpp b/plugins/DbChecker/src/worker.cpp index e5590bb127..c2e458a921 100644 --- a/plugins/DbChecker/src/worker.cpp +++ b/plugins/DbChecker/src/worker.cpp @@ -90,10 +90,8 @@ void __cdecl WorkerThread(DbToolOptions *opts) DB::ECPTR pCursor(DB::Events(cc)); DBEVENTINFO dboldev = {}; while (MEVENT hEvent = pCursor.FetchNext()) { - DB::EventInfo dbei; - if (opts->bCheckUtf || opts->bCheckDups) // read also event's body - dbei.cbBlob = -1; - if (db_event_get(hEvent, &dbei)) + DB::EventInfo dbei(hEvent, opts->bCheckUtf || opts->bCheckDups); + if (!dbei) continue; if (opts->bMarkRead && !dbei.markedRead()) { diff --git a/plugins/HistoryLinkListPlus/src/linklist.cpp b/plugins/HistoryLinkListPlus/src/linklist.cpp index 016724e8fe..69cd060b33 100644 --- a/plugins/HistoryLinkListPlus/src/linklist.cpp +++ b/plugins/HistoryLinkListPlus/src/linklist.cpp @@ -90,10 +90,7 @@ static INT_PTR LinkList_Main(WPARAM hContact, LPARAM) memset(listStart, 0, sizeof(LISTELEMENT)); do { - DB::EventInfo dbe; - dbe.cbBlob = -1; - db_event_get(hEvent, &dbe); - + DB::EventInfo dbe(hEvent); if (dbe.eventType == EVENTTYPE_MESSAGE) { // Call function to find URIs if (ExtractURI(&dbe, hEvent, listStart) < 0) { diff --git a/plugins/HistoryLinkListPlus/src/linklist_fct.cpp b/plugins/HistoryLinkListPlus/src/linklist_fct.cpp index 406ce734be..4b4736ea53 100644 --- a/plugins/HistoryLinkListPlus/src/linklist_fct.cpp +++ b/plugins/HistoryLinkListPlus/src/linklist_fct.cpp @@ -380,9 +380,7 @@ void WriteLinkList(HWND hDlg, uint8_t params, LISTELEMENT *listStart, LPCTSTR se // Perform deep scan if (actualElement->hEvent != NULL) { - DB::EventInfo dbe; - dbe.cbBlob = -1; - db_event_get(actualElement->hEvent, &dbe); + DB::EventInfo dbe(actualElement->hEvent); ptrW msg(DbEvent_GetTextW(&dbe, CP_ACP)); if (wcsstr(msg, searchString)) @@ -610,11 +608,9 @@ void WriteMessage(HWND hDlg, LISTELEMENT *listStart, int actLinePos) if (actualElement->linePos == actLinePos) { MEVENT hEvent = actualElement->hEvent; if (hEvent != NULL) { - DB::EventInfo dbe; - dbe.cbBlob = -1; - db_event_get(hEvent, &dbe); - SetDlgItemTextW(hDlg, IDC_MESSAGE, L""); + + DB::EventInfo dbe(hEvent); SendDlgItemMessage(hDlg, IDC_MESSAGE, EM_REPLACESEL, FALSE, ptrW(DbEvent_GetTextW(&dbe, CP_ACP))); } break; @@ -763,9 +759,7 @@ void GetListInfo(uint8_t params, LISTELEMENT *listStart, LPCTSTR searchString, s // Perform deep scan if (actualElement->hEvent != NULL) { - DB::EventInfo dbe; - dbe.cbBlob = -1; - db_event_get(actualElement->hEvent, &dbe); + DB::EventInfo dbe(actualElement->hEvent); if (wcsstr((LPTSTR)dbe.pBlob, searchString)) filter3 = 1; @@ -1165,9 +1159,8 @@ int DBUpdate(WPARAM wParam, LPARAM hEvent) return 0; if (hDlg) { - DB::EventInfo dbe; - dbe.cbBlob = -1; - if (db_event_get(hEvent, &dbe)) + DB::EventInfo dbe(hEvent); + if (!dbe) return 0; if (dbe.eventType == EVENTTYPE_MESSAGE) { diff --git a/plugins/IEView/src/HTMLBuilder.cpp b/plugins/IEView/src/HTMLBuilder.cpp index e61573164e..c853a9b97e 100644 --- a/plugins/IEView/src/HTMLBuilder.cpp +++ b/plugins/IEView/src/HTMLBuilder.cpp @@ -198,9 +198,8 @@ void HTMLBuilder::appendEventOld(IEView *view, IEVIEWEVENT *event) newEvent.hwnd = event->hwnd; for (int eventIdx = 0; hDbEvent != NULL && (eventIdx < event->count || event->count == -1); eventIdx++) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) { + DB::EventInfo dbei(hDbEvent); + if (!dbei) { hDbEvent = db_event_next(event->hContact, hDbEvent); continue; } diff --git a/plugins/MirandaG15/src/CAppletManager.cpp b/plugins/MirandaG15/src/CAppletManager.cpp index 62bd9e5ab9..61135eac38 100644 --- a/plugins/MirandaG15/src/CAppletManager.cpp +++ b/plugins/MirandaG15/src/CAppletManager.cpp @@ -791,41 +791,40 @@ void CAppletManager::MarkMessageAsRead(MCONTACT hContact, MEVENT hEvent) //************************************************************************ bool CAppletManager::TranslateDBEvent(CEvent *pEvent, WPARAM hContact, LPARAM hdbevent) { - // Create struct for dbevent - DB::EventInfo dbevent; - dbevent.cbBlob = -1; - if (db_event_get(hdbevent, &dbevent) != 0) + // Create struct for event + DB::EventInfo dbei(hdbevent); + if (!dbei) return false; - pEvent->dwFlags = dbevent.flags; + pEvent->dwFlags = dbei.flags; pEvent->hContact = hContact; pEvent->hValue = hdbevent; - time_t timestamp = (time_t)dbevent.timestamp; + time_t timestamp = (time_t)dbei.timestamp; localtime_s(&pEvent->Time, ×tamp); pEvent->bTime = true; // Skip events from the user except for messages - if (dbevent.eventType != EVENTTYPE_MESSAGE && (dbevent.flags & DBEF_SENT)) + if (dbei.eventType != EVENTTYPE_MESSAGE && (dbei.flags & DBEF_SENT)) return false; int msglen = 0; tstring strName = CAppletManager::GetContactDisplayname(hContact, true); - switch (dbevent.eventType) { + switch (dbei.eventType) { case EVENTTYPE_MESSAGE: - msglen = (int)mir_strlen((char *)dbevent.pBlob) + 1; - if (dbevent.flags & DBEF_UTF) { - pEvent->strValue = Utf8_Decode((char*)dbevent.pBlob); + msglen = (int)mir_strlen((char *)dbei.pBlob) + 1; + if (dbei.flags & DBEF_UTF) { + pEvent->strValue = Utf8_Decode((char*)dbei.pBlob); } - else if ((int)dbevent.cbBlob == msglen * 3) { - pEvent->strValue = (wchar_t *)& dbevent.pBlob[msglen]; + else if ((int)dbei.cbBlob == msglen * 3) { + pEvent->strValue = (wchar_t *)& dbei.pBlob[msglen]; } else { - pEvent->strValue = toTstring((char*)dbevent.pBlob); + pEvent->strValue = toTstring((char*)dbei.pBlob); } - pEvent->eType = (dbevent.flags & DBEF_SENT) ? EVENT_MSG_SENT : EVENT_MSG_RECEIVED; + pEvent->eType = (dbei.flags & DBEF_SENT) ? EVENT_MSG_SENT : EVENT_MSG_RECEIVED; if (pEvent->eType == EVENT_MSG_RECEIVED) { pEvent->dwFlags = MSG_UNREAD; if (CConfig::GetBoolSetting(NOTIFY_MESSAGES)) diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index 75c751a47c..6efee874e7 100644 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -975,9 +975,8 @@ bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, const wstrin { bool result = true; - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (!db_event_get(hDbEvent, &dbei)) { + DB::EventInfo dbei(hDbEvent); + if (dbei) { if (db_mc_isMeta(hContact)) hContact = db_event_getContact(hDbEvent); diff --git a/plugins/NewEventNotify/src/popup.cpp b/plugins/NewEventNotify/src/popup.cpp index 4da66331b7..535e981af9 100644 --- a/plugins/NewEventNotify/src/popup.cpp +++ b/plugins/NewEventNotify/src/popup.cpp @@ -435,10 +435,7 @@ int PopupUpdate(PLUGIN_DATA &pdata, MEVENT hEvent) wszText.AppendChar('\n'); // get DBEVENTINFO with pBlob if preview is needed (when is test then is off) - DB::EventInfo dbe; - if (g_plugin.bPreview) - dbe.cbBlob = -1; - db_event_get(pdata.events[i], &dbe); + DB::EventInfo dbe(pdata.events[i], g_plugin.bPreview); CMStringW wszFormat; if (g_plugin.bShowDate) diff --git a/plugins/NewStory/src/history.cpp b/plugins/NewStory/src/history.cpp index 040f67e2c4..54fd1092e7 100644 --- a/plugins/NewStory/src/history.cpp +++ b/plugins/NewStory/src/history.cpp @@ -709,9 +709,8 @@ public: bool bAppendOnly = false; DB::ECPTR pCursor(DB::Events(m_hContact)); while (MEVENT hDbEvent = pCursor.FetchNext()) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (!db_event_get(hDbEvent, &dbei)) { + DB::EventInfo dbei(hDbEvent); + if (dbei) { if (bAppendOnly) { SetFilePointer(hFile, -3, nullptr, FILE_END); WriteFile(hFile, ",", 1, &dwBytesWritten, nullptr); diff --git a/plugins/Scriver/src/msgdialog.cpp b/plugins/Scriver/src/msgdialog.cpp index 4f65a5cd52..4c6c1f9af0 100644 --- a/plugins/Scriver/src/msgdialog.cpp +++ b/plugins/Scriver/src/msgdialog.cpp @@ -430,9 +430,8 @@ void CMsgDialog::onClick_Quote(CCtrlButton*) mir_free(buffer); } else { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(m_hDbEventLast, &dbei)) + DB::EventInfo dbei(m_hDbEventLast); + if (!dbei) return; if (DbEventIsMessageOrCustom(&dbei)) { diff --git a/plugins/Scriver/src/msglog.cpp b/plugins/Scriver/src/msglog.cpp index ea8dbd2747..f191432ba4 100644 --- a/plugins/Scriver/src/msglog.cpp +++ b/plugins/Scriver/src/msglog.cpp @@ -78,9 +78,8 @@ bool DbEventIsShown(const DBEVENTINFO &dbei) EventData* CMsgDialog::GetEventFromDB(MCONTACT hContact, MEVENT hDbEvent) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return nullptr; if (!DbEventIsShown(dbei)) diff --git a/plugins/StopSpamMod/src/stopspam.cpp b/plugins/StopSpamMod/src/stopspam.cpp index 25a25506a3..4b52c0b6e5 100644 --- a/plugins/StopSpamMod/src/stopspam.cpp +++ b/plugins/StopSpamMod/src/stopspam.cpp @@ -19,9 +19,8 @@ int OnDbEventAdded(WPARAM hContact, LPARAM hDbEvent) { - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return 0; // if event is in protocol that is not despammed diff --git a/plugins/StopSpamPlus/src/events.cpp b/plugins/StopSpamPlus/src/events.cpp index 08da0fbf42..fcea573c55 100644 --- a/plugins/StopSpamPlus/src/events.cpp +++ b/plugins/StopSpamPlus/src/events.cpp @@ -4,9 +4,8 @@ int OnDbEventAdded(WPARAM, LPARAM lParam) { MEVENT hDbEvent = (MEVENT)lParam; - DB::EventInfo dbei; - dbei.cbBlob = -1; - if (db_event_get(hDbEvent, &dbei)) + DB::EventInfo dbei(hDbEvent); + if (!dbei) return 0; // if event is in protocol that is not despammed diff --git a/plugins/Variables/src/parse_miranda.cpp b/plugins/Variables/src/parse_miranda.cpp index 72cf34604e..8996cbbc46 100644 --- a/plugins/Variables/src/parse_miranda.cpp +++ b/plugins/Variables/src/parse_miranda.cpp @@ -564,12 +564,8 @@ static wchar_t* parseDbEvent(ARGUMENTSINFO *ai) if (hDbEvent == NULL) return nullptr; - DB::EventInfo dbe; - dbe.cbBlob = -1; - if (db_event_get(hDbEvent, &dbe)) - return nullptr; - - return DbEvent_GetTextW(&dbe, CP_ACP); + DB::EventInfo dbe(hDbEvent); + return (dbe) ? DbEvent_GetTextW(&dbe, CP_ACP) : nullptr; } static wchar_t* parseTranslate(ARGUMENTSINFO *ai) diff --git a/plugins/YARelay/src/main.cpp b/plugins/YARelay/src/main.cpp index 7f2f1f607f..472f3e17d8 100644 --- a/plugins/YARelay/src/main.cpp +++ b/plugins/YARelay/src/main.cpp @@ -113,9 +113,7 @@ static int MessageEventAdded(WPARAM hContact, LPARAM hDBEvent) return 0; // receive message from DB - DB::EventInfo dbei; - dbei.cbBlob = -1; - db_event_get(hDBEvent, &dbei); + DB::EventInfo dbei(hDBEvent); if (dbei.flags & DBEF_SENT || dbei.flags & DBEF_READ || (dbei.eventType != EVENTTYPE_MESSAGE)) return 0; diff --git a/plugins/wbOSD/src/events.cpp b/plugins/wbOSD/src/events.cpp index 993ece3475..f456b4aab1 100644 --- a/plugins/wbOSD/src/events.cpp +++ b/plugins/wbOSD/src/events.cpp @@ -129,9 +129,8 @@ int ContactStatusChanged(WPARAM wParam, LPARAM lParam) int HookedNewEvent(WPARAM wParam, LPARAM hDBEvent) { logmsg("HookedNewEvent1"); - DB::EventInfo dbe; - dbe.cbBlob = -1; - if (db_event_get(hDBEvent, &dbe)) + DB::EventInfo dbe(hDBEvent); + if (!dbe) return 0; if (dbe.flags & DBEF_SENT) -- cgit v1.2.3