\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&)
{
wchar_t *id = isMe ? L"out" : L"inc";
wchar_t* ev = (isMe ? L"1" : L"0");
wchar_t* ev1 = ev;
bool isUrl = false;
std::wstring mes = ReplaceSmileys(isMe, message, isUrl);
if (isUrl)
ev = L"2";
EXP_FILE << L"
\n";
EXP_FILE << L"
" << L"
\n";
EXP_FILE << L"
" << (Options::instance->exportHtml2ShowDate ? longDate : shortDate) << L"
\n";
EXP_FILE << L"
" << MakeTextHtmled(user) << L"
\n";
EXP_FILE << L"
\n";
EXP_FILE << mes;
EXP_FILE << L"\n
\n";
EXP_FILE << L"
\n";
}
std::wstring RichHtmlExport::ReplaceSmileys(bool isMe, const std::wstring &msg, bool &isUrl)
{
if (!Options::instance->exportHtml2UseSmileys || !g_SmileyAddAvail)
return UrlHighlightHtml(MakeTextHtmled(msg), isUrl);
wchar_t* msgbuf = new wchar_t[msg.length() + 1];
memcpy_s(msgbuf, (msg.length() + 1) * sizeof(wchar_t), msg.c_str(), (msg.length() + 1) * sizeof(wchar_t));
SMADD_BATCHPARSE2 sp = { 0 };
SMADD_BATCHPARSERES *spr;
sp.cbSize = sizeof(sp);
sp.Protocolname = baseProto.length() == 0 ? nullptr : 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 == nullptr || (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 != nullptr) { // 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 + L"\\" + smileyName).c_str(), FALSE);
}
std::wstring smileyText = newMsg.substr(startChar, size);
smileyMsg += L"";
}
// 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);
}