\n");
++groupId;
}
void RichHtmlExport::WriteMessage(bool isMe, const std::wstring &longDate, const std::wstring &shortDate, const std::wstring &user, const std::wstring &message, const DBEVENTINFO& dbei)
{
TCHAR *id = isMe ? _T("out") : _T("inc");
TCHAR* ev = (isMe ? _T("1") : _T("0"));
TCHAR* ev1 = ev;
bool isUrl = false;
std::wstring& mes = ReplaceSmileys(isMe, message, isUrl);
if (isUrl)
ev = _T("2");
EXP_FILE << _T("
\n");
EXP_FILE << _T("
") << _T("
\n");
EXP_FILE << _T("
") << (Options::instance->exportHtml2ShowDate ? longDate : shortDate) << _T("
\n");
EXP_FILE << _T("
") << MakeTextHtmled(user) << _T("
\n");
EXP_FILE << _T("
\n");
EXP_FILE << mes;
EXP_FILE << _T("\n
\n");
EXP_FILE << _T("
\n");
}
std::wstring RichHtmlExport::ReplaceSmileys(bool isMe, const std::wstring &msg, bool &isUrl)
{
if (!Options::instance->exportHtml2UseSmileys || !g_SmileyAddAvail)
return UrlHighlightHtml(MakeTextHtmled(msg), isUrl);
TCHAR* msgbuf = new TCHAR[msg.length() + 1];
memcpy_s(msgbuf, (msg.length() + 1) * sizeof(TCHAR), msg.c_str(), (msg.length() + 1) * sizeof(TCHAR));
SMADD_BATCHPARSE2 sp = {0};
SMADD_BATCHPARSERES *spr;
sp.cbSize = sizeof(sp);
sp.Protocolname = baseProto.length() == 0 ? NULL : baseProto.c_str();
sp.str = msgbuf;
sp.flag = SAFL_TCHAR | SAFL_PATH | (isMe ? SAFL_OUTGOING : 0);
spr = (SMADD_BATCHPARSERES*)CallService(MS_SMILEYADD_BATCHPARSE, 0, (LPARAM)&sp);
delete[] msgbuf;
// Did not find a simley
if (spr == NULL || (INT_PTR)spr == CALLSERVICE_NOTFOUND)
return UrlHighlightHtml(MakeTextHtmled(msg), isUrl);
std::queue
> positionMap;
std::wstring newMsg = MakeTextHtmled(msg, &positionMap);
std::wstring smileyMsg;
size_t last_pos=0;
std::pair pos(0, 0);
size_t currentAdd = 0;
if (!positionMap.empty()) {
pos = positionMap.front();
positionMap.pop();
}
for (unsigned i = 0; i < sp.numSmileys; ++i) {
size_t startChar = spr[i].startChar + currentAdd;
while(startChar >= pos.first && pos.second) {
startChar += pos.second;
currentAdd += pos.second;
if (!positionMap.empty()) {
pos = positionMap.front();
positionMap.pop();
}
else pos = std::pair(0, 0);
}
size_t endChar = spr[i].startChar + spr[i].size + currentAdd;
while(endChar >= pos.first && pos.second) {
endChar += pos.second;
currentAdd += pos.second;
if (!positionMap.empty()) {
pos = positionMap.front();
positionMap.pop();
}
else pos = std::pair(0, 0);
}
size_t size = endChar - startChar;
if (spr[i].filepath != NULL) { // For deffective smileypacks
// Add text
if (startChar - last_pos > 0) {
smileyMsg += newMsg.substr(last_pos, startChar - last_pos);
}
std::wstring smileyName = GetName(spr[i].filepath);
if (smileys.find(smileyName) == smileys.end()) {
smileys.insert(smileyName);
CopyFile(spr[i].filepath, (folder + _T("\\") + smileyName).c_str(), FALSE);
}
std::wstring smileyText = newMsg.substr(startChar, size);
smileyMsg += _T("");
}
// Get next
last_pos = endChar;
}
// Add rest of text
if (last_pos < newMsg.length())
smileyMsg += newMsg.substr(last_pos);
CallService(MS_SMILEYADD_BATCHFREE, 0, (LPARAM)spr);
return UrlHighlightHtml(smileyMsg, isUrl);
}