summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-12-26 20:17:40 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-12-26 20:17:40 +0300
commit7827d06f9cd6d8e0dffa2c500e32c1ff0737dbfa (patch)
treedc981b584d76427c7fcfae58bee35392d9a4a9af
parent7a135968ad505c9ac82d56e27773a33ea77ccfdc (diff)
fixes #4077 (Сообщения в формате RTF показываются как исходники)
-rw-r--r--plugins/DbChecker/res/resource.rc6
-rw-r--r--plugins/DbChecker/src/options.cpp3
-rw-r--r--plugins/DbChecker/src/progress.cpp2
-rw-r--r--plugins/DbChecker/src/resource.h2
-rw-r--r--plugins/DbChecker/src/stdafx.h5
-rw-r--r--plugins/DbChecker/src/version.h2
-rw-r--r--plugins/DbChecker/src/worker.cpp77
7 files changed, 86 insertions, 11 deletions
diff --git a/plugins/DbChecker/res/resource.rc b/plugins/DbChecker/res/resource.rc
index 9ab6352bf7..24fed02d75 100644
--- a/plugins/DbChecker/res/resource.rc
+++ b/plugins/DbChecker/res/resource.rc
@@ -48,8 +48,9 @@ BEGIN
PUSHBUTTON "...",IDC_OPENFILE,243,49,15,13
CONTROL "Mark all events as read",IDC_MARKREAD,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,69,248,10
CONTROL "Fix UTF-8 encoding in old events",IDC_FIX_UTF8,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,83,248,10
- CONTROL "Remove duplicate events",IDC_REMOVE_DUPS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,97,248,10
- CONTROL "Fix server event IDs",IDC_FIX_SERVER_IDS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,111,248,10
+ CONTROL "Fix RTF text in old events",IDC_FIX_RTF,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,97,248,10
+ CONTROL "Remove duplicate events",IDC_REMOVE_DUPS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,111,248,10
+ CONTROL "Fix server event IDs",IDC_FIX_SERVER_IDS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,125,248,10
END
IDD_OPENERROR DIALOGEX 0, 0, 262, 143
@@ -76,6 +77,7 @@ BEGIN
LTEXT "Working...",IDC_STATIC,11,6,250,8,WS_BORDER
LTEXT "Please wait while the requested operations are being performed.",IDC_STATIC,20,14,240,16
CONTROL "",IDC_SPLITTER,"Static",SS_ETCHEDHORZ,-1,32,264,1
+ CONTROL "",IDC_MEMO,"RICHEDIT50W",NOT WS_VISIBLE,20,38,222,11
CONTROL "Progress1",IDC_PROGRESS,"msctls_progress32",PBS_SMOOTH | WS_BORDER,20,38,222,11
LISTBOX IDC_STATUS,20,52,222,84,NOT LBS_NOTIFY | LBS_OWNERDRAWFIXED | LBS_HASSTRINGS | LBS_DISABLENOSCROLL | LBS_NOSEL | WS_VSCROLL | WS_TABSTOP
END
diff --git a/plugins/DbChecker/src/options.cpp b/plugins/DbChecker/src/options.cpp
index 70569d587e..8c00990f17 100644
--- a/plugins/DbChecker/src/options.cpp
+++ b/plugins/DbChecker/src/options.cpp
@@ -21,6 +21,7 @@ COptionsPageDlg::COptionsPageDlg() :
CSuper(IDD_OPTPAGE),
edtFile(this, IDC_FILENAME),
btnFile(this, IDC_OPENFILE),
+ chkFixRtf(this, IDC_FIX_RTF),
chkFixUtf(this, IDC_FIX_UTF8),
chkMarkRead(this, IDC_MARKREAD),
chkRemoveDups(this, IDC_REMOVE_DUPS),
@@ -35,6 +36,7 @@ bool COptionsPageDlg::OnInitDialog()
auto *opts = getOpts();
edtFile.SetText(opts->filename);
+ chkFixRtf.SetState(opts->bCheckRtf);
chkFixUtf.SetState(opts->bCheckUtf);
chkMarkRead.SetState(opts->bMarkRead);
chkRemoveDups.SetState(opts->bCheckDups);
@@ -93,6 +95,7 @@ LBL_Error:
opts->db = pDb;
}
+ opts->bCheckRtf = chkFixRtf.IsChecked();
opts->bCheckUtf = chkFixUtf.IsChecked();
opts->bMarkRead = chkMarkRead.IsChecked();
opts->bCheckDups = chkRemoveDups.IsChecked();
diff --git a/plugins/DbChecker/src/progress.cpp b/plugins/DbChecker/src/progress.cpp
index b3458cadc9..237b43092c 100644
--- a/plugins/DbChecker/src/progress.cpp
+++ b/plugins/DbChecker/src/progress.cpp
@@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void __cdecl WorkerThread(DbToolOptions *opts);
static HWND hwndStatus, hdlgProgress, hwndBar;
+HWND hwndRichEdit;
int errorCount;
extern HFONT hBoldFont;
@@ -75,6 +76,7 @@ bool CProgressPageDlg::OnInitDialog()
EnableWindow(GetDlgItem(m_hwndParent, IDOK), FALSE);
hdlgProgress = m_hwnd;
hwndStatus = GetDlgItem(m_hwnd, IDC_STATUS);
+ hwndRichEdit = GetDlgItem(m_hwnd, IDC_MEMO);
errorCount = 0;
hwndBar = GetDlgItem(m_hwnd, IDC_PROGRESS);
SendMessage(hwndBar, PBM_SETRANGE, 0, MAKELPARAM(0, 1000));
diff --git a/plugins/DbChecker/src/resource.h b/plugins/DbChecker/src/resource.h
index 1309916af9..c5b2657a14 100644
--- a/plugins/DbChecker/src/resource.h
+++ b/plugins/DbChecker/src/resource.h
@@ -16,6 +16,8 @@
#define IDC_FILE 1004
#define IDC_ERRORTEXT 1006
#define IDC_INUSE 1007
+#define IDC_FIX_RTF 1008
+#define IDC_MEMO 1009
#define IDC_PROGRESS 1011
#define IDC_STATUS 1012
#define IDC_MARKREAD 1013
diff --git a/plugins/DbChecker/src/stdafx.h b/plugins/DbChecker/src/stdafx.h
index 7e2c07fc30..4ab8712469 100644
--- a/plugins/DbChecker/src/stdafx.h
+++ b/plugins/DbChecker/src/stdafx.h
@@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <process.h>
#include <malloc.h>
#include <commctrl.h>
+#include <Richedit.h>
#include <time.h>
#include <newpluginapi.h>
@@ -64,7 +65,7 @@ struct DbToolOptions : public MZeroedObject
MIDatabaseChecker *dbChecker;
uint32_t error;
HANDLE hEventRun, hEventAbort;
- bool bFinished, bAutoExit, bOwnsDb, bMarkRead, bCheckUtf, bCheckDups, bCheckServerIds;
+ bool bFinished, bAutoExit, bOwnsDb, bMarkRead, bCheckUtf, bCheckRtf, bCheckDups, bCheckServerIds;
wchar_t filename[MAX_PATH];
};
@@ -113,7 +114,7 @@ class COptionsPageDlg : public CWizardPageDlg
CCtrlEdit edtFile;
CCtrlButton btnFile;
- CCtrlCheck chkMarkRead, chkFixUtf, chkRemoveDups, chkFixServerIds;
+ CCtrlCheck chkMarkRead, chkFixUtf, chkFixRtf, chkRemoveDups, chkFixServerIds;
public:
COptionsPageDlg();
diff --git a/plugins/DbChecker/src/version.h b/plugins/DbChecker/src/version.h
index bbd30292c8..0a9757afd1 100644
--- a/plugins/DbChecker/src/version.h
+++ b/plugins/DbChecker/src/version.h
@@ -1,6 +1,6 @@
#define __MAJOR_VERSION 0
#define __MINOR_VERSION 96
-#define __RELEASE_NUM 3
+#define __RELEASE_NUM 4
#define __BUILD_NUM 1
#include <stdver.h>
diff --git a/plugins/DbChecker/src/worker.cpp b/plugins/DbChecker/src/worker.cpp
index 40de977360..7aab01c392 100644
--- a/plugins/DbChecker/src/worker.cpp
+++ b/plugins/DbChecker/src/worker.cpp
@@ -21,6 +21,63 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void ProcessingDone(void);
+/////////////////////////////////////////////////////////////////////////////////////////
+
+extern HWND hwndRichEdit;
+
+struct StringBuf
+{
+ char *str;
+ size_t size, streamOffset;
+};
+
+DWORD CALLBACK sttStreamInCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
+{
+ StringBuf *buf = (StringBuf *)dwCookie;
+
+ if (buf->streamOffset < buf->size) {
+ size_t cbLen = min(size_t(cb), buf->size - buf->streamOffset);
+ memcpy(pbBuff, buf->str + buf->streamOffset, cbLen);
+ buf->streamOffset += cbLen;
+ *pcb = (LONG)cbLen;
+ }
+ else *pcb = 0;
+
+ return 0;
+}
+
+static bool ConvertRtfEvent(DBEVENTINFO &dbei)
+{
+ if (mir_strncmp(dbei.pBlob, "{\\rtf1", 6))
+ return false;
+
+ StringBuf buf = {};
+ buf.str = dbei.pBlob;
+ buf.size = dbei.cbBlob;
+
+ EDITSTREAM es = {};
+ es.dwCookie = (DWORD_PTR)&buf;
+ es.pfnCallback = sttStreamInCallback;
+ SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+
+ GETTEXTLENGTHEX param = { GTL_NUMBYTES, CP_UTF8 };
+ int iLength = SendMessage(hwndRichEdit, EM_GETTEXTLENGTHEX, WPARAM(&param), 0);
+
+ BOOL bFlag;
+ char *utf8str = (char *)mir_alloc(iLength + 1);
+ GETTEXTEX param2 = { (DWORD)iLength, GT_USECRLF, CP_UTF8, "?", &bFlag };
+ SendMessage(hwndRichEdit, EM_GETTEXTEX, WPARAM(&param2), LPARAM(utf8str));
+
+ mir_free(dbei.pBlob);
+
+ dbei.flags |= DBEF_UTF;
+ dbei.cbBlob = (uint32_t)mir_strlen(utf8str);
+ dbei.pBlob = utf8str;
+ return true;
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
static bool ConvertOldEvent(DBEVENTINFO &dbei)
{
if (dbei.flags & DBEF_UTF)
@@ -31,7 +88,7 @@ static bool ConvertOldEvent(DBEVENTINFO &dbei)
return true;
}
- int msglen = (int)mir_strlen((char *)dbei.pBlob) + 1, msglenW = 0;
+ int msglen = (int)mir_strlen(dbei.pBlob) + 1, msglenW = 0;
if (msglen != (int)dbei.cbBlob) {
int count = ((dbei.cbBlob - msglen) / sizeof(wchar_t));
wchar_t *p = (wchar_t *)&dbei.pBlob[msglen];
@@ -83,14 +140,14 @@ void __cdecl WorkerThread(DbToolOptions *opts)
uint32_t sp = 0;
- if (opts->bMarkRead || opts->bCheckUtf || opts->bCheckDups || opts->bCheckServerIds) {
- int nCount = 0, nUtfCount = 0, nDups = 0, nIds = 0;
+ if (opts->bMarkRead || opts->bCheckRtf || opts->bCheckUtf || opts->bCheckDups || opts->bCheckServerIds) {
+ int nCount = 0, nUtfCount = 0, nRtfCount = 0, nDups = 0, nIds = 0;
for (auto &cc : Contacts()) {
DB::ECPTR pCursor(DB::Events(cc));
DBEVENTINFO dboldev = {};
while (MEVENT hEvent = pCursor.FetchNext()) {
- DB::EventInfo dbei(hEvent, opts->bCheckUtf || opts->bCheckDups || opts->bCheckServerIds);
+ DB::EventInfo dbei(hEvent, opts->bCheckUtf || opts->bCheckRtf || opts->bCheckDups || opts->bCheckServerIds);
if (!dbei)
continue;
@@ -100,12 +157,17 @@ void __cdecl WorkerThread(DbToolOptions *opts)
}
if (dbei.eventType == EVENTTYPE_MESSAGE) {
- if (opts->bCheckUtf) {
+ if (opts->bCheckUtf)
if (ConvertOldEvent(dbei)) {
db_event_edit(hEvent, &dbei);
nUtfCount++;
}
- }
+
+ if (opts->bCheckRtf)
+ if (ConvertRtfEvent(dbei)) {
+ db_event_edit(hEvent, &dbei);
+ nRtfCount++;
+ }
if (opts->bCheckServerIds) {
// if a blob is longer than its text part, there's a nessage id after text
@@ -144,6 +206,9 @@ void __cdecl WorkerThread(DbToolOptions *opts)
if (nUtfCount)
AddToStatus(STATUS_MESSAGE, TranslateT("UTF-8 encoding fixed in %d events"), nUtfCount);
+ if (nRtfCount)
+ AddToStatus(STATUS_MESSAGE, TranslateT("RTF format fixed in %d events"), nRtfCount);
+
if (nDups)
AddToStatus(STATUS_MESSAGE, TranslateT("%d duplicate events removed"), nDups);