diff options
author | George Hazan <george.hazan@gmail.com> | 2016-08-31 12:19:31 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2016-08-31 12:19:31 +0000 |
commit | ca942b88c295830544e03804666229e0e955f64b (patch) | |
tree | e19134219dae9befdf0b5cb1764873830058d5ad /plugins/BasicHistory/src/RichHtmlExport.cpp | |
parent | 75a38acd5c2a1e0abd08d3458d36a452dfd0879a (diff) |
- memory leak fixed;
- code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@17226 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/BasicHistory/src/RichHtmlExport.cpp')
-rw-r--r-- | plugins/BasicHistory/src/RichHtmlExport.cpp | 200 |
1 files changed, 100 insertions, 100 deletions
diff --git a/plugins/BasicHistory/src/RichHtmlExport.cpp b/plugins/BasicHistory/src/RichHtmlExport.cpp index c1a639267e..3191ac18f8 100644 --- a/plugins/BasicHistory/src/RichHtmlExport.cpp +++ b/plugins/BasicHistory/src/RichHtmlExport.cpp @@ -36,9 +36,9 @@ std::wstring MakeTextHtmled(const std::wstring& message, std::queue<std::pair<si size_t start = 0;
size_t find;
size_t currentAdd = 0;
- while((find = message.find_first_of(search, start)) < message.length()) {
+ while ((find = message.find_first_of(search, start)) < message.length()) {
ret += message.substr(start, find - start);
- switch(message[find]) {
+ switch (message[find]) {
case '&':
ret += L"&";
break;
@@ -65,7 +65,7 @@ std::wstring MakeTextHtmled(const std::wstring& message, std::queue<std::pair<si }
}
}
-
+
ret += message.substr(start, message.length() - start);
return ret;
}
@@ -77,14 +77,14 @@ std::wstring UrlHighlightHtml(const std::wstring& message, bool& isUrl) std::wstring search = L"://";
size_t start = 0;
size_t find;
- while((find = message.find(search, start)) < message.length()) {
+ while ((find = message.find(search, start)) < message.length()) {
size_t urlStart = message.find_last_of(htmlStop, find);
size_t urlEnd = message.find_first_of(htmlStop, find + 3);
if (urlStart >= message.length())
urlStart = -1;
if (urlEnd >= message.length())
urlEnd = message.length();
- if (((int)urlEnd -3 - (int)find > 0) && ((int)find - (int)urlStart -1 > 0)) {
+ if (((int)urlEnd - 3 - (int)find > 0) && ((int)find - (int)urlStart - 1 > 0)) {
ret += message.substr(start, (urlStart + 1) - start);
std::wstring url = message.substr(urlStart + 1, urlEnd - urlStart - 1);
start = urlEnd;
@@ -144,39 +144,40 @@ void ExtractFile(short int iRes, const std::wstring &fileName) #pragma pack(push, 2)
typedef struct
{
- BYTE bWidth; // Width, in pixels, of the image
- BYTE bHeight; // Height, in pixels, of the image
- BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
- BYTE bReserved; // Reserved ( must be 0)
- WORD wPlanes; // Color Planes
- WORD wBitCount; // Bits per pixel
- DWORD dwBytesInRes; // How many bytes in this resource?
- DWORD dwImageOffset; // Where in the file is this image?
+ BYTE bWidth; // Width, in pixels, of the image
+ BYTE bHeight; // Height, in pixels, of the image
+ BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
+ BYTE bReserved; // Reserved ( must be 0)
+ WORD wPlanes; // Color Planes
+ WORD wBitCount; // Bits per pixel
+ DWORD dwBytesInRes; // How many bytes in this resource?
+ DWORD dwImageOffset; // Where in the file is this image?
} ICONDIRENTRY, *LPICONDIRENTRY;
typedef struct
{
- WORD idReserved; // Reserved (must be 0)
- WORD idType; // Resource Type (1 for icons)
- WORD idCount; // How many images?
- //ICONDIRENTRY idEntries; // An entry for each image (idCount of 'em)
+ WORD idReserved; // Reserved (must be 0)
+ WORD idType; // Resource Type (1 for icons)
+ WORD idCount; // How many images?
+ //ICONDIRENTRY idEntries; // An entry for each image (idCount of 'em)
} ICONDIR, *LPICONDIR;
#pragma pack(pop)
-typedef struct tagMyBITMAPINFO {
- BITMAPINFOHEADER bmiHeader;
- RGBQUAD bmiColors[256];
+typedef struct tagMyBITMAPINFO
+{
+ BITMAPINFOHEADER bmiHeader;
+ RGBQUAD bmiColors[256];
} MYBITMAPINFO;
void IcoSave(const std::wstring &fileName, HICON hicon)
{
- std::ofstream store (fileName.c_str(), std::ios_base::binary);
+ std::ofstream store(fileName.c_str(), std::ios_base::binary);
if (!store.is_open())
return;
ICONINFO ii;
- if ( !GetIconInfo(hicon, &ii)) {
+ if (!GetIconInfo(hicon, &ii)) {
store.close();
return;
}
@@ -185,100 +186,99 @@ void IcoSave(const std::wstring &fileName, HICON hicon) HBITMAP hbmColor = ii.hbmColor;
BITMAP bmiMask;
BITMAP bmiColor;
- if (GetObject(hbmColor,sizeof(bmiColor),&bmiColor) &&
- GetObject(hbmMask,sizeof(bmiMask),&bmiMask) &&
- (bmiColor.bmWidth==bmiMask.bmWidth) &&
- (bmiColor.bmHeight==bmiMask.bmHeight) &&
+ if (GetObject(hbmColor, sizeof(bmiColor), &bmiColor) &&
+ GetObject(hbmMask, sizeof(bmiMask), &bmiMask) &&
+ (bmiColor.bmWidth == bmiMask.bmWidth) &&
+ (bmiColor.bmHeight == bmiMask.bmHeight) &&
(bmiMask.bmHeight) > 0 &&
- (bmiMask.bmWidth) > 0)
- {
- BITMAPINFOHEADER icobmi = {0};
- MYBITMAPINFO info1 = {0};
- MYBITMAPINFO info2 = {0};
-
+ (bmiMask.bmWidth) > 0) {
+ BITMAPINFOHEADER icobmi = { 0 };
+ MYBITMAPINFO info1 = { 0 };
+ MYBITMAPINFO info2 = { 0 };
+
HDC hDC = CreateCompatibleDC(NULL);
info1.bmiHeader.biSize = sizeof(info1.bmiHeader);
- info1.bmiHeader.biWidth = bmiColor.bmWidth;
- info1.bmiHeader.biHeight = bmiColor.bmHeight;
- info1.bmiHeader.biPlanes = 1;
- info1.bmiHeader.biBitCount = bmiColor.bmBitsPixel;
- unsigned int size = GetDIBits(hDC,hbmColor,0,info1.bmiHeader.biHeight,NULL,(BITMAPINFO*)&info1,DIB_RGB_COLORS);
+ info1.bmiHeader.biWidth = bmiColor.bmWidth;
+ info1.bmiHeader.biHeight = bmiColor.bmHeight;
+ info1.bmiHeader.biPlanes = 1;
+ info1.bmiHeader.biBitCount = bmiColor.bmBitsPixel;
+ unsigned int size = GetDIBits(hDC, hbmColor, 0, info1.bmiHeader.biHeight, NULL, (BITMAPINFO*)&info1, DIB_RGB_COLORS);
char* bits1 = new char[info1.bmiHeader.biSizeImage];
- size = GetDIBits(hDC,hbmColor,0,info1.bmiHeader.biHeight,bits1,(BITMAPINFO*)&info1,DIB_RGB_COLORS);
+ size = GetDIBits(hDC, hbmColor, 0, info1.bmiHeader.biHeight, bits1, (BITMAPINFO*)&info1, DIB_RGB_COLORS);
info2.bmiHeader.biSize = sizeof(info2.bmiHeader);
- info2.bmiHeader.biWidth = bmiMask.bmWidth;
- info2.bmiHeader.biHeight = bmiMask.bmHeight;
- info2.bmiHeader.biPlanes = 1;
- info2.bmiHeader.biBitCount = bmiMask.bmBitsPixel;
- size = GetDIBits(hDC,hbmColor,0,info1.bmiHeader.biHeight,NULL,(BITMAPINFO*)&info2,DIB_RGB_COLORS);
+ info2.bmiHeader.biWidth = bmiMask.bmWidth;
+ info2.bmiHeader.biHeight = bmiMask.bmHeight;
+ info2.bmiHeader.biPlanes = 1;
+ info2.bmiHeader.biBitCount = bmiMask.bmBitsPixel;
+ size = GetDIBits(hDC, hbmColor, 0, info1.bmiHeader.biHeight, NULL, (BITMAPINFO*)&info2, DIB_RGB_COLORS);
char* bits2 = new char[info2.bmiHeader.biSizeImage];
- size = GetDIBits(hDC,hbmMask,0,info2.bmiHeader.biHeight,bits2,(BITMAPINFO*)&info2,DIB_RGB_COLORS);
+ size = GetDIBits(hDC, hbmMask, 0, info2.bmiHeader.biHeight, bits2, (BITMAPINFO*)&info2, DIB_RGB_COLORS);
ICONDIR icodir;
ICONDIRENTRY icoent;
icodir.idReserved = 0;
- icodir.idType = 1;
- icodir.idCount = 1;
-
- icoent.bWidth = (unsigned char)bmiColor.bmWidth;
- icoent.bHeight = (unsigned char)bmiColor.bmHeight;
- icoent.bColorCount = 8<=bmiColor.bmBitsPixel?0:1<<bmiColor.bmBitsPixel;
- icoent.bReserved = 0;
- icoent.wPlanes = bmiColor.bmPlanes;
- icoent.wBitCount = bmiColor.bmBitsPixel;
- icoent.dwBytesInRes = sizeof(BITMAPINFOHEADER) + info1.bmiHeader.biSizeImage + info2.bmiHeader.biSizeImage;
+ icodir.idType = 1;
+ icodir.idCount = 1;
+
+ icoent.bWidth = (unsigned char)bmiColor.bmWidth;
+ icoent.bHeight = (unsigned char)bmiColor.bmHeight;
+ icoent.bColorCount = 8 <= bmiColor.bmBitsPixel ? 0 : 1 << bmiColor.bmBitsPixel;
+ icoent.bReserved = 0;
+ icoent.wPlanes = bmiColor.bmPlanes;
+ icoent.wBitCount = bmiColor.bmBitsPixel;
+ icoent.dwBytesInRes = sizeof(BITMAPINFOHEADER) + info1.bmiHeader.biSizeImage + info2.bmiHeader.biSizeImage;
icoent.dwImageOffset = sizeof(icodir) + sizeof(icoent);
-
- store.write((char*)&icodir,sizeof(icodir));
- store.write((char*)&icoent,sizeof(icoent));
-
- icobmi.biSize = sizeof(icobmi);
- icobmi.biWidth = bmiColor.bmWidth;
- icobmi.biHeight = bmiColor.bmHeight + bmiMask.bmHeight;
- icobmi.biPlanes = info1.bmiHeader.biPlanes;
- icobmi.biBitCount = bmiColor.bmBitsPixel;
+
+ store.write((char*)&icodir, sizeof(icodir));
+ store.write((char*)&icoent, sizeof(icoent));
+
+ icobmi.biSize = sizeof(icobmi);
+ icobmi.biWidth = bmiColor.bmWidth;
+ icobmi.biHeight = bmiColor.bmHeight + bmiMask.bmHeight;
+ icobmi.biPlanes = info1.bmiHeader.biPlanes;
+ icobmi.biBitCount = bmiColor.bmBitsPixel;
icobmi.biSizeImage = 0;
-
- store.write((char*)&icobmi,sizeof(icobmi));
+
+ store.write((char*)&icobmi, sizeof(icobmi));
store.write(bits1, info1.bmiHeader.biSizeImage);
store.write(bits2, info2.bmiHeader.biSizeImage);
DeleteDC(hDC);
- delete [] bits1;
- delete [] bits2;
+ delete[] bits1;
+ delete[] bits2;
}
-
+
store.close();
if (ii.hbmColor) DeleteObject(ii.hbmColor);
- if (ii.hbmMask ) DeleteObject(ii.hbmMask );
+ if (ii.hbmMask) DeleteObject(ii.hbmMask);
}
bool DeleteDirectory(LPCTSTR lpszDir, bool noRecycleBin = true)
{
- size_t len = mir_wstrlen(lpszDir);
- wchar_t *pszFrom = new wchar_t[len+2];
- wcscpy_s(pszFrom, len+2, lpszDir);
- pszFrom[len] = 0;
- pszFrom[len+1] = 0;
-
- SHFILEOPSTRUCT fileop;
- fileop.hwnd = NULL; // no status display
- fileop.wFunc = FO_DELETE; // delete operation
- fileop.pFrom = pszFrom; // source file name as double null terminated string
- fileop.pTo = NULL; // no destination needed
- fileop.fFlags = FOF_NOCONFIRMATION|FOF_SILENT; // do not prompt the user
-
- if (!noRecycleBin)
- fileop.fFlags |= FOF_ALLOWUNDO;
-
- fileop.fAnyOperationsAborted = FALSE;
- fileop.lpszProgressTitle = NULL;
- fileop.hNameMappings = NULL;
-
- int ret = SHFileOperation(&fileop);
- delete [] pszFrom;
- return (ret == 0);
+ size_t len = mir_wstrlen(lpszDir);
+ wchar_t *pszFrom = new wchar_t[len + 2];
+ wcscpy_s(pszFrom, len + 2, lpszDir);
+ pszFrom[len] = 0;
+ pszFrom[len + 1] = 0;
+
+ SHFILEOPSTRUCT fileop;
+ fileop.hwnd = NULL; // no status display
+ fileop.wFunc = FO_DELETE; // delete operation
+ fileop.pFrom = pszFrom; // source file name as double null terminated string
+ fileop.pTo = NULL; // no destination needed
+ fileop.fFlags = FOF_NOCONFIRMATION | FOF_SILENT; // do not prompt the user
+
+ if (!noRecycleBin)
+ fileop.fFlags |= FOF_ALLOWUNDO;
+
+ fileop.fAnyOperationsAborted = FALSE;
+ fileop.lpszProgressTitle = NULL;
+ fileop.hNameMappings = NULL;
+
+ int ret = SHFileOperation(&fileop);
+ delete[] pszFrom;
+ return (ret == 0);
}
void RichHtmlExport::WriteHeader(const std::wstring &fileName, const std::wstring &filterName, const std::wstring &myName, const std::wstring &myId, const std::wstring &name1, const std::wstring &proto1, const std::wstring &id1, const std::string& baseProto1, const std::wstring& encoding)
@@ -288,7 +288,7 @@ void RichHtmlExport::WriteHeader(const std::wstring &fileName, const std::wstrin folderName = GetName(folder);
DeleteDirectory(folder.c_str());
CreateDirectory(folder.c_str(), NULL);
- std::wstring css = folder + L"\\history.css";
+ std::wstring css = folder + L"\\history.css";
BOOL cssCopied = FALSE;
if (!Options::instance->extCssHtml2.empty())
cssCopied = CopyFile(Options::instance->extCssHtml2.c_str(), css.c_str(), FALSE);
@@ -369,7 +369,7 @@ void RichHtmlExport::WriteGroup(bool isMe, const std::wstring &time, const std:: wchar_t* ev = (isMe ? L"1" : L"0");
if (groupId > 0)
EXP_FILE << L"</div>\n";
-
+
bool isUrl = false;
std::wstring mes = ReplaceSmileys(isMe, eventText, isUrl);
EXP_FILE << L"<div class=mes id=session>\n";
@@ -391,7 +391,7 @@ void RichHtmlExport::WriteMessage(bool isMe, const std::wstring &longDate, const if (isUrl)
ev = L"2";
EXP_FILE << L"<div class=mes id=event" << ev << L">\n";
- EXP_FILE << L"<div class=eventimg id=" << id << L">" << L"<img src=\"" << folderName << L"\\event" << ev1 << L".ico\" class=sessionimage width=\"16\" height=\"16\"/></div>\n";
+ EXP_FILE << L"<div class=eventimg id=" << id << L">" << L"<img src=\"" << folderName << L"\\event" << ev1 << L".ico\" class=sessionimage width=\"16\" height=\"16\"/></div>\n";
EXP_FILE << L"<div class=date id=" << id << L">" << (Options::instance->exportHtml2ShowDate ? longDate : shortDate) << L"</div>\n";
EXP_FILE << L"<div class=nick id=" << id << L">" << MakeTextHtmled(user) << L"</div>\n";
EXP_FILE << L"<div class=text>\n";
@@ -407,7 +407,7 @@ std::wstring RichHtmlExport::ReplaceSmileys(bool isMe, const std::wstring &msg, 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_BATCHPARSE2 sp = { 0 };
SMADD_BATCHPARSERES *spr;
sp.cbSize = sizeof(sp);
sp.Protocolname = baseProto.length() == 0 ? NULL : baseProto.c_str();
@@ -423,8 +423,8 @@ std::wstring RichHtmlExport::ReplaceSmileys(bool isMe, const std::wstring &msg, std::queue<std::pair<size_t, size_t> > positionMap;
std::wstring newMsg = MakeTextHtmled(msg, &positionMap);
std::wstring smileyMsg;
-
- size_t last_pos=0;
+
+ size_t last_pos = 0;
std::pair<size_t, size_t> pos(0, 0);
size_t currentAdd = 0;
if (!positionMap.empty()) {
@@ -434,7 +434,7 @@ std::wstring RichHtmlExport::ReplaceSmileys(bool isMe, const std::wstring &msg, for (unsigned i = 0; i < sp.numSmileys; ++i) {
size_t startChar = spr[i].startChar + currentAdd;
- while(startChar >= pos.first && pos.second) {
+ while (startChar >= pos.first && pos.second) {
startChar += pos.second;
currentAdd += pos.second;
if (!positionMap.empty()) {
@@ -445,7 +445,7 @@ std::wstring RichHtmlExport::ReplaceSmileys(bool isMe, const std::wstring &msg, }
size_t endChar = spr[i].startChar + spr[i].size + currentAdd;
- while(endChar >= pos.first && pos.second) {
+ while (endChar >= pos.first && pos.second) {
endChar += pos.second;
currentAdd += pos.second;
if (!positionMap.empty()) {
|