From ca942b88c295830544e03804666229e0e955f64b Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 31 Aug 2016 12:19:31 +0000 Subject: - memory leak fixed; - code cleaning git-svn-id: http://svn.miranda-ng.org/main/trunk@17226 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/BasicHistory/src/BasicHistory.cpp | 39 +++--- plugins/BasicHistory/src/BinaryExport.cpp | 12 +- plugins/BasicHistory/src/DatExport.cpp | 19 +-- plugins/BasicHistory/src/EventList.cpp | 10 +- plugins/BasicHistory/src/ExportManager.cpp | 62 +++++---- plugins/BasicHistory/src/HotkeyHelper.cpp | 6 +- plugins/BasicHistory/src/ImageDataObject.cpp | 20 +-- plugins/BasicHistory/src/Options.cpp | 165 +++++++++++----------- plugins/BasicHistory/src/RichHtmlExport.cpp | 200 +++++++++++++-------------- plugins/BasicHistory/src/Scheduler.cpp | 163 +++++++++++----------- plugins/BasicHistory/src/Searcher.cpp | 74 +++++----- plugins/BasicHistory/src/TxtExport.cpp | 8 -- 12 files changed, 380 insertions(+), 398 deletions(-) (limited to 'plugins/BasicHistory/src') diff --git a/plugins/BasicHistory/src/BasicHistory.cpp b/plugins/BasicHistory/src/BasicHistory.cpp index 8c91b57629..4af03cc15c 100644 --- a/plugins/BasicHistory/src/BasicHistory.cpp +++ b/plugins/BasicHistory/src/BasicHistory.cpp @@ -25,7 +25,7 @@ HINSTANCE hInst; #define MS_HISTORY_EXECUTE_TASK "BasicHistory/ExecuteTask" HCURSOR hCurSplitNS, hCurSplitWE; -HANDLE g_hMainThread=NULL; +HANDLE g_hMainThread = NULL; HANDLE hServiceShowContactHistory, hServiceDeleteAllContactHistory, hServiceExecuteTask; HANDLE *hEventIcons = NULL; @@ -36,7 +36,7 @@ HGENMENU hTaskMainMenu; std::vector taskMenus; bool g_SmileyAddAvail = false; char* metaContactProto = NULL; -const IID IID_ITextDocument={0x8CC497C0, 0xA1DF, 0x11ce, {0x80, 0x98, 0x00, 0xAA, 0x00, 0x47, 0xBE, 0x5D}}; +const IID IID_ITextDocument = { 0x8CC497C0, 0xA1DF, 0x11ce, {0x80, 0x98, 0x00, 0xAA, 0x00, 0x47, 0xBE, 0x5D} }; #define MODULE "BasicHistory" @@ -67,7 +67,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) return &pluginInfo; } -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_UIHISTORY, MIID_LAST}; +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_UIHISTORY, MIID_LAST }; void InitScheduler(); void DeinitScheduler(); @@ -84,7 +84,7 @@ int PrebuildContactMenu(WPARAM hContact, LPARAM) return 0; } -int ToolbarModuleLoaded(WPARAM,LPARAM) +int ToolbarModuleLoaded(WPARAM, LPARAM) { TTBButton ttb = { 0 }; ttb.pszService = MS_HISTORY_SHOWCONTACTHISTORY; @@ -167,7 +167,7 @@ IconItem iconList[] = { LPGEN("Find Previous"), "BasicHistory_findprev", IDI_FINDPREV }, { LPGEN("Plus in export"), "BasicHistory_plusex", IDI_PLUSEX }, { LPGEN("Minus in export"), "BasicHistory_minusex", IDI_MINUSEX }, -}; +}; void InitIcolib() { @@ -175,8 +175,8 @@ void InitIcolib() HICON LoadIconEx(int iconId, bool big) { - for (int i=0; i < _countof(iconList); i++) - if ( iconList[i].defIconID == iconId) + for (int i = 0; i < _countof(iconList); i++) + if (iconList[i].defIconID == iconId) return IcoLib_GetIconByHandle(iconList[i].hIcolib, big); return 0; @@ -204,20 +204,20 @@ int HistoryContactDelete(WPARAM wParam, LPARAM) int ModulesLoaded(WPARAM, LPARAM) { InitMenuItems(); - + wchar_t ftpExe[MAX_PATH]; if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_CURRENT, ftpExe))) { wcscat_s(ftpExe, L"\\WinSCP\\WinSCP.exe"); DWORD atr = GetFileAttributes(ftpExe); if (atr == INVALID_FILE_ATTRIBUTES || atr & FILE_ATTRIBUTE_DIRECTORY) { -#ifdef _WIN64 + #ifdef _WIN64 if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PROGRAM_FILESX86, NULL, SHGFP_TYPE_CURRENT, ftpExe))) { wcscat_s(ftpExe, L"\\WinSCP\\WinSCP.exe"); atr = GetFileAttributes(ftpExe); if (!(atr == INVALID_FILE_ATTRIBUTES || atr & FILE_ATTRIBUTE_DIRECTORY)) Options::instance->ftpExePathDef = ftpExe; } -#endif + #endif } else Options::instance->ftpExePathDef = ftpExe; } @@ -234,7 +234,7 @@ int ModulesLoaded(WPARAM, LPARAM) HookEvent(ME_DB_CONTACT_DELETED, HistoryContactDelete); HookEvent(ME_FONT_RELOAD, HistoryWindow::FontsChanged); HookEvent(ME_SYSTEM_OKTOEXIT, DoLastTask); - + if (ServiceExists(MS_SMILEYADD_REPLACESMILEYS)) g_SmileyAddAvail = true; @@ -248,7 +248,7 @@ extern "C" int __declspec(dllexport) Load(void) mir_getCLI(); hTaskMainMenu = NULL; - DuplicateHandle(GetCurrentProcess(),GetCurrentThread(),GetCurrentProcess(),&g_hMainThread,0,FALSE,DUPLICATE_SAME_ACCESS); + DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &g_hMainThread, 0, FALSE, DUPLICATE_SAME_ACCESS); hCurSplitNS = LoadCursor(NULL, IDC_SIZENS); hCurSplitWE = LoadCursor(NULL, IDC_SIZEWE); @@ -263,7 +263,7 @@ extern "C" int __declspec(dllexport) Load(void) HookEvent(ME_OPT_INITIALISE, Options::InitOptions); HistoryEventList::Init(); - + Icon_Register(hInst, LPGEN("History"), iconList, _countof(iconList)); return 0; } @@ -272,23 +272,22 @@ extern "C" int __declspec(dllexport) Unload(void) { if (g_hMainThread) CloseHandle(g_hMainThread); - g_hMainThread=NULL; - + g_hMainThread = NULL; + DestroyServiceFunction(hServiceShowContactHistory); DestroyServiceFunction(hServiceDeleteAllContactHistory); DestroyServiceFunction(hServiceExecuteTask); - + HistoryWindow::Deinit(); - + DestroyCursor(hCurSplitNS); DestroyCursor(hCurSplitWE); - + if (Options::instance != NULL) { delete Options::instance; Options::instance = NULL; } - delete [] hEventIcons; - + delete[] hEventIcons; return 0; } diff --git a/plugins/BasicHistory/src/BinaryExport.cpp b/plugins/BasicHistory/src/BinaryExport.cpp index 6164e8062b..619a9de152 100644 --- a/plugins/BasicHistory/src/BinaryExport.cpp +++ b/plugins/BasicHistory/src/BinaryExport.cpp @@ -60,12 +60,12 @@ void BinaryExport::WriteString(const std::wstring &str) } bool BinaryExport::ReadString(std::wstring &str) -{ +{ std::string buf; int size = 1024; int pos = 0; - int totalSize = 0; - while(true) { + int totalSize = 0; + while (true) { buf.resize(size); if (IMP_FILE.peek() == 0) { IMP_FILE.get(); @@ -187,7 +187,7 @@ int BinaryExport::IsContactInFile(const std::vector& contacts) size_t pos = IMP_FILE.tellg(); if (header.dataStart < pos) return -2; - + IMP_FILE.seekg(0, std::ios_base::beg); for (int i = 0; i < (int)contacts.size(); ++i) { std::wstring pn = GetProtocolName(contacts[i]); @@ -208,7 +208,7 @@ bool BinaryExport::GetEventList(std::vector& eventList codepage = header.codepage; IMP_FILE.seekg(header.dataStart, std::ios_base::beg); BinaryFileMessageHeader messageHeader; - while(true) { + while (true) { IMP_FILE.read((char*)&messageHeader, sizeof(BinaryFileMessageHeader)); if (IMP_FILE.eof()) break; @@ -221,7 +221,7 @@ bool BinaryExport::GetEventList(std::vector& eventList exMsg.timestamp = messageHeader.timestamp; if (!ReadString(exMsg.message)) return false; - + eventList.push_back(exMsg); } diff --git a/plugins/BasicHistory/src/DatExport.cpp b/plugins/BasicHistory/src/DatExport.cpp index 92975b61ff..7ef7bb0f79 100644 --- a/plugins/BasicHistory/src/DatExport.cpp +++ b/plugins/BasicHistory/src/DatExport.cpp @@ -37,12 +37,13 @@ struct MCHeader #pragma pack(pop) -typedef struct { +typedef struct +{ int cbSize; //size of the structure in bytes DWORD szModule; //pointer to name of the module that 'owns' this - //event, ie the one that is in control of the data format + //event, ie the one that is in control of the data format DWORD timestamp; //seconds since 00:00, 01/01/1970. Gives us times until - //2106 unless you use the standard C library which is + //2106 unless you use the standard C library which is //signed and can only do until 2038. In GMT. DWORD flags; //the omnipresent flags WORD eventType; //module-defined event type field @@ -133,10 +134,10 @@ int DatExport::IsContactInFile(const std::vector& contacts) MCHeader header; if (!ReadHeader(header, IImport::stream)) return -2; - + if (contacts.size() == 1) hContact = contacts[0]; - + IMP_FILE.seekg(0, std::ios_base::beg); return -3; } @@ -149,12 +150,12 @@ bool DatExport::GetEventList(std::vector& eventList) dataSize = header.dataSize; DBEVENTINFO86 messageHeader; - DBEVENTINFO info = {0}; + DBEVENTINFO info = { 0 }; info.cbSize = sizeof(DBEVENTINFO); info.szModule = GetContactProto(hContact); wchar_t _str[MAXSELECTSTR + 8]; // for safety reason std::multimap sortedEvents; - while(dataSize > 0) { + while (dataSize > 0) { messageHeader.cbSize = 0; IMP_FILE.read((char*)&messageHeader, sizeof(DBEVENTINFO86)); if (!IMP_FILE.good()) @@ -176,7 +177,7 @@ bool DatExport::GetEventList(std::vector& eventList) IMP_FILE.read((char*)memBuf.c_str(), messageHeader.cbBlob); if (!IMP_FILE.good()) return false; - + info.eventType = messageHeader.eventType; info.flags = messageHeader.flags; info.timestamp = messageHeader.timestamp; @@ -187,7 +188,7 @@ bool DatExport::GetEventList(std::vector& eventList) sortedEvents.insert(std::pair(messageHeader.timestamp, exMsg)); dataSize -= messageHeader.cbSize + messageHeader.cbBlob; } - + memBuf.resize(0); memBuf.shrink_to_fit(); diff --git a/plugins/BasicHistory/src/EventList.cpp b/plugins/BasicHistory/src/EventList.cpp index 932242a65d..bc459bfd95 100644 --- a/plugins/BasicHistory/src/EventList.cpp +++ b/plugins/BasicHistory/src/EventList.cpp @@ -79,15 +79,15 @@ bool HistoryEventList::CanShowHistory(DBEVENTINFO* dbei) return true; if (m_defFilter < 1) { - switch(dbei->eventType) { + switch (dbei->eventType) { case EVENTTYPE_MESSAGE: case EVENTTYPE_URL: case EVENTTYPE_FILE: return true; default: - DBEVENTTYPEDESCR *et = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, ( WPARAM )dbei->szModule, ( LPARAM )dbei->eventType); - if (et && ( et->flags & DETF_HISTORY)) + DBEVENTTYPEDESCR *et = (DBEVENTTYPEDESCR*)CallService(MS_DB_EVENT_GETTYPE, (WPARAM)dbei->szModule, (LPARAM)dbei->eventType); + if (et && (et->flags & DETF_HISTORY)) return true; } @@ -123,7 +123,7 @@ bool HistoryEventList::CanShowHistory(const IImport::ExternalMessage &message) return true; if (m_defFilter < 1) { - switch(message.eventType ) { + switch (message.eventType) { case EVENTTYPE_MESSAGE: case EVENTTYPE_URL: case EVENTTYPE_FILE: @@ -220,7 +220,7 @@ void HistoryEventList::GetTempList(std::list& tempList, bool noF for (int i = 0; i < (int)m_importedMessages.size(); ++i) { if (noFilter || CanShowHistory(m_importedMessages[i])) { DWORD ts = m_importedMessages[i].timestamp; - while(itL != tempList.end() && itL->timestamp < ts)++itL; + while (itL != tempList.end() && itL->timestamp < ts)++itL; if (itL == tempList.end() || itL->timestamp > ts) { ti.exIdx = i; ti.timestamp = ts; diff --git a/plugins/BasicHistory/src/ExportManager.cpp b/plugins/BasicHistory/src/ExportManager.cpp index c7ac9b099c..820abcf64b 100644 --- a/plugins/BasicHistory/src/ExportManager.cpp +++ b/plugins/BasicHistory/src/ExportManager.cpp @@ -52,7 +52,7 @@ std::wstring GetFile(const wchar_t* ext, HWND hwnd, bool open) wcscat_s(stzFilePath, ext); len = mir_wstrlen(stzFilePath) + 1; stzFilePath[len] = 0; - OPENFILENAME ofn = {0}; + OPENFILENAME ofn = { 0 }; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwnd; ofn.lpstrFilter = filter; @@ -94,7 +94,7 @@ bool ExportManager::Export(IExport::ExportType type) UINT cp; std::wstring encoding; bool isBin = false; - switch(type) { + switch (type) { case IExport::Txt: m_exp = new TxtExport(); cp = Options::instance->codepageTxt; @@ -142,19 +142,19 @@ bool ExportManager::Export(IExport::ExportType type) std::wofstream* stream; if (!isBin) { - stream = new std::wofstream (fileName.c_str()); + stream = new std::wofstream(fileName.c_str()); if (!stream->is_open()) return false; - + std::locale filelocale(std::locale(), new codecvt_CodePage(cp)); stream->imbue(filelocale); m_exp->SetStream(stream); } else { - std::ofstream* cstream = new std::ofstream (fileName.c_str(), std::ios_base::binary); + std::ofstream* cstream = new std::ofstream(fileName.c_str(), std::ios_base::binary); if (!cstream->is_open()) return false; - + stream = (std::wofstream*)cstream; m_exp->SetStream(stream); } @@ -181,7 +181,7 @@ bool ExportManager::Export(IExport::ExportType type) const wchar_t* ExportManager::GetExt(IImport::ImportType type) { IImport *imp = NULL; - switch(type) { + switch (type) { case IImport::Binary: imp = new BinaryExport(); break; @@ -191,7 +191,7 @@ const wchar_t* ExportManager::GetExt(IImport::ImportType type) default: return L""; } - + const wchar_t *ext = imp->GetExt(); delete imp; return ext; @@ -200,7 +200,7 @@ const wchar_t* ExportManager::GetExt(IImport::ImportType type) int ExportManager::Import(IImport::ImportType type, const std::vector& contacts) { IImport *imp = NULL; - switch(type) { + switch (type) { case IImport::Binary: imp = new BinaryExport(); break; @@ -211,17 +211,23 @@ int ExportManager::Import(IImport::ImportType type, const std::vector& return -2; } - if (m_file.empty()) + if (m_file.empty()) { + delete imp; return -2; + } std::wstring fileName = ReplaceExt(m_file, imp->GetExt()); - if (fileName.empty()) + if (fileName.empty()) { + delete imp; return -2; + } - std::ifstream* stream = new std::ifstream (fileName.c_str(), std::ios_base::binary); - if (!stream->is_open()) + std::ifstream* stream = new std::ifstream(fileName.c_str(), std::ios_base::binary); + if (!stream->is_open()) { + delete imp; return -2; - + } + imp->SetStream(stream); int t = imp->IsContactInFile(contacts); stream->close(); @@ -233,7 +239,7 @@ int ExportManager::Import(IImport::ImportType type, const std::vector& bool ExportManager::Import(IImport::ImportType type, std::vector& eventList, std::wstring* err, bool* differentContact, std::vector* contacts) { IImport *imp = NULL; - switch(type) { + switch (type) { case IImport::Binary: imp = new BinaryExport(); break; @@ -243,17 +249,19 @@ bool ExportManager::Import(IImport::ImportType type, std::vectorGetExt(), m_hwnd, true); else fileName = ReplaceExt(m_file, imp->GetExt()); - std::ifstream *stream = new std::ifstream (fileName.c_str(), std::ios_base::binary); - if (!stream->is_open()) + std::ifstream *stream = new std::ifstream(fileName.c_str(), std::ios_base::binary); + if (!stream->is_open()) { + delete imp; return false; - + } + imp->SetStream(stream); std::vector v; v.push_back(m_hContact); @@ -263,7 +271,7 @@ bool ExportManager::Import(IImport::ImportType type, std::vectorIsContactInFile(*contacts); if (contInFile >= 0) { @@ -292,7 +300,7 @@ void ExportManager::AddGroup(bool isMe, const std::wstring &time, const std::wst { if (m_exp == NULL) return; - + m_exp->WriteGroup(isMe, time, user, eventText); wchar_t str[MAXSELECTSTR + 8]; // for safety reason str[0] = 0; @@ -319,20 +327,20 @@ void ExportManager::AddGroup(bool isMe, const std::wstring &time, const std::wst isFirst = false; formatDate = Options::instance->messagesShowSec ? L"s" : L"t"; time_t tt = data.timestamp; - localtime_s(&lastTime, &tt); + localtime_s(&lastTime, &tt); } else { time_t tt = data.timestamp; tm t; - localtime_s(&t, &tt); + localtime_s(&t, &tt); if (lastTime.tm_yday == t.tm_yday && lastTime.tm_year == t.tm_year) formatDate = Options::instance->messagesShowSec ? L"s" : L"t"; } } - - TimeZone_PrintTimeStamp(NULL, data.timestamp, longFormatDate, str , MAXSELECTSTR, 0); + + TimeZone_PrintTimeStamp(NULL, data.timestamp, longFormatDate, str, MAXSELECTSTR, 0); std::wstring longDate = str; - TimeZone_PrintTimeStamp(NULL, data.timestamp, formatDate, str , MAXSELECTSTR, 0); + TimeZone_PrintTimeStamp(NULL, data.timestamp, formatDate, str, MAXSELECTSTR, 0); std::wstring shortDate = str; std::wstring wszUser; @@ -340,7 +348,7 @@ void ExportManager::AddGroup(bool isMe, const std::wstring &time, const std::wst wszUser = m_myName; else wszUser = m_contactName; - + GetEventMessage(hDbEvent, str); std::wstring strMessage = str; if (strMessage.length() + 1 >= MAXSELECTSTR) diff --git a/plugins/BasicHistory/src/HotkeyHelper.cpp b/plugins/BasicHistory/src/HotkeyHelper.cpp index ba2e2195d2..8a9441e8b3 100644 --- a/plugins/BasicHistory/src/HotkeyHelper.cpp +++ b/plugins/BasicHistory/src/HotkeyHelper.cpp @@ -40,8 +40,7 @@ static LRESULT CALLBACK HotkeySubclassProc(HWND hwnd, UINT msg, WPARAM wParam, L break; case WM_KEYUP: case WM_SYSKEYUP: - if (isPresed) - { + if (isPresed) { isPresed = false; return 0; } @@ -58,8 +57,7 @@ static LRESULT CALLBACK HotkeySubclassProc(HWND hwnd, UINT msg, WPARAM wParam, L filter.nmhdr.hwndFrom = hwnd; filter.nmhdr.code = EN_MSGFILTER; filter.nmhdr.idFrom = GetDlgCtrlID(hwnd); - if (SendMessage(hwndParent, WM_NOTIFY, NULL, (LPARAM)&filter)) - { + if (SendMessage(hwndParent, WM_NOTIFY, NULL, (LPARAM)&filter)) { isPresed = true; return 0; } diff --git a/plugins/BasicHistory/src/ImageDataObject.cpp b/plugins/BasicHistory/src/ImageDataObject.cpp index 8e6c1b9b55..d0cbc85843 100644 --- a/plugins/BasicHistory/src/ImageDataObject.cpp +++ b/plugins/BasicHistory/src/ImageDataObject.cpp @@ -55,7 +55,6 @@ bool ImageDataObject::InsertIcon(IRichEditOle* pRichEditOle, HICON hIcon, // returns true on success, false on failure bool ImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap) { - SCODE sc; BITMAP bminfo; // Get the image data object @@ -72,16 +71,16 @@ bool ImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap) // Initialize a Storage Object // - IStorage *pStorage; LPLOCKBYTES lpLockBytes = NULL; - sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); + SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); if (sc != S_OK) { pOleClientSite->Release(); return false; } - sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, - STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage); + + IStorage *pStorage; + sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_READWRITE, 0, &pStorage); if (sc != S_OK) { lpLockBytes = NULL; pOleClientSite->Release(); @@ -117,7 +116,7 @@ bool ImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap) } reobject.clsid = clsid; - reobject.cp = REO_CP_SELECTION ; + reobject.cp = REO_CP_SELECTION; reobject.dvaspect = DVASPECT_CONTENT; reobject.poleobj = pOleObject; reobject.polesite = pOleClientSite; @@ -134,10 +133,7 @@ bool ImageDataObject::InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap) pOleClientSite->Release(); lpLockBytes->Release(); pStorage->Release(); - if (sc != S_OK) - return false; - else - return true; + return sc == S_OK; } @@ -161,10 +157,8 @@ void ImageDataObject::SetBitmap(HBITMAP hBitmap) IOleObject *ImageDataObject::GetOleObject(IOleClientSite *pOleClientSite, IStorage *pStorage) { - SCODE sc; IOleObject *pOleObject; - sc = ::OleCreateStaticFromData(this, IID_IOleObject, OLERENDER_FORMAT, - &m_format, pOleClientSite, pStorage, (void **) & pOleObject); + SCODE sc = ::OleCreateStaticFromData(this, IID_IOleObject, OLERENDER_FORMAT, &m_format, pOleClientSite, pStorage, (void **)& pOleObject); if (sc != S_OK) pOleObject = NULL; return pOleObject; diff --git a/plugins/BasicHistory/src/Options.cpp b/plugins/BasicHistory/src/Options.cpp index f27b62597d..6b1bf7ba1d 100644 --- a/plugins/BasicHistory/src/Options.cpp +++ b/plugins/BasicHistory/src/Options.cpp @@ -33,7 +33,7 @@ struct EventNamesType int id; wchar_t* name; } -EventNames[] = +EventNames[] = { EVENTTYPE_MESSAGE, LPGENW("Message"), EVENTTYPE_FILE, LPGENW("File transfer"), @@ -44,7 +44,8 @@ EventNames[] = ICQEVENTTYPE_SMS, LPGENW("SMS message") }; -struct TCpTable { +struct TCpTable +{ UINT cpId; wchar_t *cpName; } @@ -157,7 +158,8 @@ int Options::InitOptions(WPARAM wParam, LPARAM) return 0; } -struct FontOptionsList { +struct FontOptionsList +{ wchar_t* szDescr; COLORREF defColour; wchar_t* szDefFace; @@ -167,12 +169,14 @@ struct FontOptionsList { DWORD flags; }; -struct ColorOptionsList { +struct ColorOptionsList +{ wchar_t* tszName; COLORREF def; }; -struct HotkeyOptionsList { +struct HotkeyOptionsList +{ const char *pszName; const wchar_t *pwszDescription; const wchar_t *pwszSection; @@ -202,7 +206,7 @@ static ColorOptionsList g_ColorOptionsList[] = { }; static HotkeyOptionsList g_HotkeyOptionsList[] = { - { "basichistory_hot_showall", LPGENW("Open global history"), LPGENW("History"), MS_HISTORY_SHOWCONTACTHISTORY, HOTKEYCODE(HOTKEYF_CONTROL|HOTKEYF_SHIFT, 'H') | HKF_MIRANDA_LOCAL, 0 }, + { "basichistory_hot_showall", LPGENW("Open global history"), LPGENW("History"), MS_HISTORY_SHOWCONTACTHISTORY, HOTKEYCODE(HOTKEYF_CONTROL | HOTKEYF_SHIFT, 'H') | HKF_MIRANDA_LOCAL, 0 }, { "basichistory_hot_find", LPGENW("Find"), LPGENW("History"), 0, HOTKEYCODE(HOTKEYF_CONTROL, 'F'), HISTORY_HK_FIND }, { "basichistory_hot_findnext", LPGENW("Find Next"), LPGENW("History"), 0, VK_F3, HISTORY_HK_FINDNEXT }, { "basichistory_hot_findprev", LPGENW("Find Previous"), LPGENW("History"), 0, VK_F2, HISTORY_HK_FINDPREV }, @@ -231,9 +235,9 @@ const int g_hotkeysSize = _countof(g_HotkeyOptionsList); void Options::Load(void) { - FontIDW fid = {0}; - ColourIDW cid = {0}; - HOTKEYDESC hid = {0}; + FontIDW fid = { 0 }; + ColourIDW cid = { 0 }; + HOTKEYDESC hid = { 0 }; fid.cbSize = sizeof(FontIDW); cid.cbSize = sizeof(ColourIDW); hid.cbSize = sizeof(HOTKEYDESC); @@ -243,7 +247,7 @@ void Options::Load(void) for (int i = 0; i < g_fontsSize; ++i) { fid.order = i; wcsncpy_s(fid.deffontsettings.szFace, g_FontOptionsList[i].szDefFace, _TRUNCATE); - fid.deffontsettings.size = g_FontOptionsList[i].defSize; + fid.deffontsettings.size = g_FontOptionsList[i].defSize; fid.deffontsettings.colour = g_FontOptionsList[i].defColour; fid.deffontsettings.style = g_FontOptionsList[i].defStyle; fid.deffontsettings.charset = DEFAULT_CHARSET; @@ -253,7 +257,7 @@ void Options::Load(void) fid.flags = FIDF_DEFAULTVALID | FIDF_CLASSGENERAL | g_FontOptionsList[i].flags; FontRegisterW(&fid); } - + strncpy_s(cid.dbSettingsGroup, "BasicHistory_Fonts", _TRUNCATE); wcsncpy_s(cid.group, LPGENW("History"), _TRUNCATE); for (int i = 0; i < g_colorsSize; ++i) { @@ -274,7 +278,7 @@ void Options::Load(void) hid.lParam = g_HotkeyOptionsList[i].lParam; Hotkey_Register(&hid); } - + showContacts = db_get_b(0, MODULE, "showContacts", 0) ? true : false; showContactGroups = db_get_b(0, MODULE, "showContactGroups", 1) ? true : false; noFindBorder = db_get_b(0, MODULE, "noFindBorder", 0) ? true : false; @@ -329,7 +333,7 @@ void Options::Load(void) if (!db_get_s(0, MODULE, buf, &eventsV)) { int k = 0; char* id = eventsV.pszVal; - while(eventsV.pszVal[k]) { + while (eventsV.pszVal[k]) { if (eventsV.pszVal[k] == ';') { eventsV.pszVal[k] = 0; fo.events.push_back(strtol(id, NULL, 16)); @@ -341,13 +345,13 @@ void Options::Load(void) db_free(&eventsV); } else break; - + customFilters.insert(customFilters.end(), fo); } if (defFilter > 1) { defFilter = 0; - + DBVARIANT defFilterStrV; if (!db_get_ws(0, MODULE, "defFilterStr", &defFilterStrV)) { std::wstring filterName = defFilterStrV.pwszVal; @@ -360,7 +364,7 @@ void Options::Load(void) db_free(&defFilterStrV); } } - + codepageTxt = db_get_dw(0, MODULE, "codepageTxt", CP_UTF8); codepageHtml1 = db_get_dw(0, MODULE, "codepageHtml1", CP_UTF8); codepageHtml2 = db_get_dw(0, MODULE, "codepageHtml2", CP_UTF8); @@ -402,13 +406,13 @@ void Options::Load(void) db_free(&encodingV); } else ftpExePath = ftpExePathDef; - + LoadTasks(); } COLORREF Options::GetFont(Fonts fontId, PLOGFONT font) { - FontIDW fid = {0}; + FontIDW fid = { 0 }; fid.cbSize = sizeof(FontIDW); wcsncpy_s(fid.group, LPGENW("History"), _TRUNCATE); wcsncpy_s(fid.name, g_FontOptionsList[fontId].szDescr, _TRUNCATE); @@ -417,7 +421,7 @@ COLORREF Options::GetFont(Fonts fontId, PLOGFONT font) COLORREF Options::GetColor(Colors colorId) { - ColourIDW cid = {0}; + ColourIDW cid = { 0 }; cid.cbSize = sizeof(ColourIDW); wcsncpy_s(cid.group, LPGENW("History"), _TRUNCATE); wcsncpy_s(cid.name, g_ColorOptionsList[colorId].tszName, _TRUNCATE); @@ -465,7 +469,7 @@ void Options::Save() if (defFilter >= 2) db_set_ws(0, MODULE, "defFilterStr", customFilters[defFilter - 2].name.c_str()); db_set_dw(0, MODULE, "customFiltersCount", (DWORD)customFilters.size()); - for (int i = 0 ; i < (int)customFilters.size(); ++i) { + for (int i = 0; i < (int)customFilters.size(); ++i) { char buf[256]; mir_snprintf(buf, "filterName_%d", i); db_set_ws(0, MODULE, buf, customFilters[i].name.c_str()); @@ -566,7 +570,7 @@ void Options::SaveTasks(std::list* tasks) } db_set_dw(0, MODULE, "Task_count", i); - + for (i = (int)tasks->size(); i < oldTaskNr; ++i) { mir_snprintf(buf, "Task_compress_%d", i); db_unset(NULL, MODULE, buf); @@ -723,9 +727,9 @@ void SetEventCB(HWND hwndCB, int eventId) if (selCpIdx == -1) { wchar_t buf[24]; mir_snwprintf(buf, L"%d", eventId); - ComboBox_SetText(hwndCB, buf); + ComboBox_SetText(hwndCB, buf); } - else ComboBox_SetCurSel(hwndCB, selCpIdx); + else ComboBox_SetCurSel(hwndCB, selCpIdx); } int GetEventCB(HWND hwndCB, bool errorReport, int &eventId) @@ -748,19 +752,19 @@ int GetEventCB(HWND hwndCB, bool errorReport, int &eventId) eventId = EventNames[selCpIdx - 2].id; else return selCpIdx + 1; - + return 0; } void ClearLB(HWND hwndLB) { - while(ListBox_GetCount(hwndLB) > 0) + while (ListBox_GetCount(hwndLB) > 0) ListBox_DeleteString(hwndLB, 0); } void ReloadEventLB(HWND hwndLB, const FilterOptions &sel) { - while(ListBox_GetCount(hwndLB) > 0) + while (ListBox_GetCount(hwndLB) > 0) ListBox_DeleteString(hwndLB, 0); if (sel.onlyIncomming && !sel.onlyOutgoing) @@ -778,9 +782,9 @@ void ReloadEventLB(HWND hwndLB, const FilterOptions &sel) if (selCpIdx == -1) { wchar_t buf[24]; mir_snwprintf(buf, L"%d", *it); - ListBox_AddString(hwndLB, buf); + ListBox_AddString(hwndLB, buf); } - else ListBox_AddString(hwndLB, TranslateW(EventNames[selCpIdx].name)); + else ListBox_AddString(hwndLB, TranslateW(EventNames[selCpIdx].name)); } } @@ -827,7 +831,7 @@ bool OpenFileDlg(HWND hwndDlg, HWND hwndEdit, const wchar_t* defName, const wcha stzFilePath[len] = 0; } - OPENFILENAME ofn = {0}; + OPENFILENAME ofn = { 0 }; ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hwndDlg; ofn.lpstrFilter = filter; @@ -856,7 +860,7 @@ bool OpenFileDlg(HWND hwndDlg, HWND hwndEdit, const wchar_t* defName, const wcha INT_PTR CALLBACK Options::DlgProcOptsMain(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { @@ -871,7 +875,7 @@ INT_PTR CALLBACK Options::DlgProcOptsMain(HWND hwndDlg, UINT msg, WPARAM wParam, HWND ftpLog = GetDlgItem(hwndDlg, IDC_WINSCPLOG); ComboBox_AddString(events, TranslateT("Incoming events")); ComboBox_AddString(events, TranslateT("Outgoing events")); - for (int i = 0 ; i < _countof(EventNames); ++i) + for (int i = 0; i < _countof(EventNames); ++i) ComboBox_AddString(events, TranslateW(EventNames[i].name)); ComboBox_AddString(defFilter, TranslateT("Default history events")); @@ -908,7 +912,7 @@ INT_PTR CALLBACK Options::DlgProcOptsMain(HWND hwndDlg, UINT msg, WPARAM wParam, HWND nameFilter = GetDlgItem(hwndDlg, IDC_FILTER_NAME); HWND defFilter = GetDlgItem(hwndDlg, IDC_DEFFILTER); HWND eventCB = GetDlgItem(hwndDlg, IDC_EVENT); - switch(LOWORD(wParam)) { + switch (LOWORD(wParam)) { case IDC_ADD_FILTER: { wchar_t name[24]; @@ -1119,7 +1123,7 @@ public: INT_PTR CALLBACK Options::DlgProcOptsGroupList(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { @@ -1183,7 +1187,7 @@ INT_PTR CALLBACK Options::DlgProcOptsGroupList(HWND hwndDlg, UINT msg, WPARAM wP INT_PTR CALLBACK Options::DlgProcOptsMessages(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); @@ -1222,7 +1226,7 @@ INT_PTR CALLBACK Options::DlgProcOptsMessages(HWND hwndDlg, UINT msg, WPARAM wPa INT_PTR CALLBACK Options::DlgProcOptsSearching(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); @@ -1284,9 +1288,9 @@ void InitCodepageCB(HWND hwndCB, unsigned int codepage, const std::wstring& name if (selCpIdx == -1) { wchar_t buf[300]; mir_snwprintf(buf, L"%d;%s", codepage, name.c_str()); - ComboBox_SetText(hwndCB, buf); + ComboBox_SetText(hwndCB, buf); } - else ComboBox_SetCurSel(hwndCB, selCpIdx); + else ComboBox_SetCurSel(hwndCB, selCpIdx); ComboBox_LimitText(hwndCB, 127); } @@ -1327,7 +1331,7 @@ unsigned int GetCodepageCB(HWND hwndCB, bool errorReport, unsigned int, const st INT_PTR CALLBACK Options::DlgProcOptsExport(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)FALSE); @@ -1366,7 +1370,7 @@ INT_PTR CALLBACK Options::DlgProcOptsExport(HWND hwndDlg, UINT msg, WPARAM wPara return TRUE; } - if (init && (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam)==CBN_SELCHANGE || HIWORD(wParam)==CBN_EDITCHANGE || HIWORD(wParam) == EN_CHANGE)) + if (init && (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == CBN_EDITCHANGE || HIWORD(wParam) == EN_CHANGE)) SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); } return TRUE; @@ -1434,7 +1438,7 @@ INT_PTR CALLBACK Options::DlgProcOptsScheduler(HWND hwndDlg, UINT msg, WPARAM wP { std::list* tasks = (std::list*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { @@ -1461,11 +1465,11 @@ INT_PTR CALLBACK Options::DlgProcOptsScheduler(HWND hwndDlg, UINT msg, WPARAM wP int sel = ListBox_GetCurSel(listTasks); TaskOptions toAdd; TaskOptions* to = &toAdd; - switch(LOWORD(wParam)) { + switch (LOWORD(wParam)) { case IDC_EDIT_TASK: if (sel >= 0) { std::list::iterator it = tasks->begin(); - while(sel-- > 0 && it != tasks->end()) + while (sel-- > 0 && it != tasks->end()) ++it; if (it == tasks->end()) break; @@ -1480,7 +1484,7 @@ INT_PTR CALLBACK Options::DlgProcOptsScheduler(HWND hwndDlg, UINT msg, WPARAM wP top.to = to; if (DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_DLG_TASK), hwndDlg, DlgProcOptsTask, (LPARAM)&top) == IDOK) { if (LOWORD(wParam) == IDC_ADD_TASK) { - tasks->push_back(*to); + tasks->push_back(*to); ListBox_AddString(listTasks, to->taskName.c_str()); ListBox_SetCurSel(listTasks, tasks->size() - 1); } @@ -1501,7 +1505,7 @@ INT_PTR CALLBACK Options::DlgProcOptsScheduler(HWND hwndDlg, UINT msg, WPARAM wP if (sel >= 0) { ListBox_DeleteString(listTasks, sel); std::list::iterator it = tasks->begin(); - while(sel-- > 0 && it != tasks->end()) + while (sel-- > 0 && it != tasks->end()) ++it; if (it != tasks->end()) tasks->erase(it); @@ -1552,12 +1556,12 @@ void RebuildList(HWND hwnd, MCONTACT hSystem, TaskOptions* to) { HANDLE hItem; if (to->isSystem && hSystem) - SendMessage(hwnd, CLM_SETCHECKMARK, (WPARAM) hSystem, 1); + SendMessage(hwnd, CLM_SETCHECKMARK, (WPARAM)hSystem, 1); for (size_t i = 0; i < to->contacts.size(); ++i) { - hItem = (HANDLE) SendMessage(hwnd, CLM_FINDCONTACT, (WPARAM) to->contacts[i], 0); + hItem = (HANDLE)SendMessage(hwnd, CLM_FINDCONTACT, (WPARAM)to->contacts[i], 0); if (hItem) - SendMessage(hwnd, CLM_SETCHECKMARK, (WPARAM) hItem, 1); + SendMessage(hwnd, CLM_SETCHECKMARK, (WPARAM)hItem, 1); } } @@ -1568,10 +1572,10 @@ void SaveList(HWND hwnd, MCONTACT hSystem, TaskOptions* to) to->isSystem = SendMessage(hwnd, CLM_GETCHECKMARK, (WPARAM)hSystem, 0) != 0; for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - HANDLE hItem = (HANDLE) SendMessage(hwnd, CLM_FINDCONTACT, hContact, 0); - if (hItem && SendMessage(hwnd, CLM_GETCHECKMARK, (WPARAM) hItem, 0)) + HANDLE hItem = (HANDLE)SendMessage(hwnd, CLM_FINDCONTACT, hContact, 0); + if (hItem && SendMessage(hwnd, CLM_GETCHECKMARK, (WPARAM)hItem, 0)) to->contacts.push_back(hContact); - } + } } bool IsValidTask(TaskOptions& to, std::list* top = NULL, std::wstring* err = NULL, std::wstring* errDescr = NULL); @@ -1583,7 +1587,7 @@ bool IsValidTask(TaskOptions& to, std::list* top = NULL, std::wstri INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { static MCONTACT hSystem; - switch(msg) { + switch (msg) { case WM_INITDIALOG: TranslateDialogDefault(hwndDlg); { @@ -1705,9 +1709,9 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, } SYSTEMTIME st; - GetSystemTime (&st); - st.wHour = to->dayTime/60; - st.wMinute = to->dayTime%60; + GetSystemTime(&st); + st.wHour = to->dayTime / 60; + st.wMinute = to->dayTime % 60; st.wSecond = 0; st.wMilliseconds = 0; DateTime_SetFormat(time, timeFormat); @@ -1717,7 +1721,7 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, cii.cbSize = sizeof(cii); cii.flags = CLCIIF_GROUPFONT | CLCIIF_CHECKBOX | CLCIIF_BELOWCONTACTS; cii.pszText = TranslateT("System"); - hSystem = (MCONTACT)SendMessage(contactList, CLM_ADDINFOITEM, 0, (LPARAM) & cii); + hSystem = (MCONTACT)SendMessage(contactList, CLM_ADDINFOITEM, 0, (LPARAM)& cii); SendMessage(contactList, CLM_AUTOREBUILD, 0, 0); RebuildList(contactList, hSystem, to); @@ -1827,8 +1831,7 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, else EnableWindow(GetDlgItem(hwndDlg, IDC_FTP), TRUE); } - else if (LOWORD(wParam) == IDC_COMPRESS) - { + else if (LOWORD(wParam) == IDC_COMPRESS) { if (Button_GetCheck(GetDlgItem(hwndDlg, IDC_COMPRESS)) == 0) { EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_PASSWORD_LABEL), FALSE); @@ -1845,22 +1848,22 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, int show = sel == TaskOptions::Delete ? SW_HIDE : SW_SHOW; int showFilter = (sel == TaskOptions::Import || sel == TaskOptions::ImportAndMarge) ? SW_HIDE : SW_SHOW; int showImport = (sel == TaskOptions::Import || sel == TaskOptions::ImportAndMarge) ? SW_SHOW : SW_HIDE; - ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_TYPE), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_TYPE_LABEL), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_COMPRESS), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_PASSWORD_LABEL), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PATH), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PATH_LABEL), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_FTP), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_UPLOAD), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_FTP_LABEL), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_EXPIMP), show); - ShowWindow(GetDlgItem(hwndDlg, IDC_TASK_FILTER), showFilter); - ShowWindow(GetDlgItem(hwndDlg, IDC_TASK_FILTER_LABEL), showFilter); - ShowWindow(GetDlgItem(hwndDlg, IDC_EVENT_TIME), showFilter); - ShowWindow(GetDlgItem(hwndDlg, IDC_EVENT_UNIT), showFilter); - ShowWindow(GetDlgItem(hwndDlg, IDC_EVENT_LABEL), showFilter); + ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_TYPE), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_TYPE_LABEL), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_COMPRESS), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASSWORD), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_PASSWORD_LABEL), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PATH), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_PATH_LABEL), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_FTP), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_UPLOAD), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_FTP_LABEL), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_EXPIMP), show); + ShowWindow(GetDlgItem(hwndDlg, IDC_TASK_FILTER), showFilter); + ShowWindow(GetDlgItem(hwndDlg, IDC_TASK_FILTER_LABEL), showFilter); + ShowWindow(GetDlgItem(hwndDlg, IDC_EVENT_TIME), showFilter); + ShowWindow(GetDlgItem(hwndDlg, IDC_EVENT_UNIT), showFilter); + ShowWindow(GetDlgItem(hwndDlg, IDC_EVENT_LABEL), showFilter); if (show != showFilter) { ShowWindow(GetDlgItem(hwndDlg, IDC_EXPORT_TYPE), SW_HIDE); ShowWindow(GetDlgItem(hwndDlg, IDC_EXPIMP), SW_HIDE); @@ -1896,14 +1899,14 @@ INT_PTR CALLBACK Options::DlgProcOptsTask(HWND hwndDlg, UINT msg, WPARAM wParam, int showW = sel == TaskOptions::Weekly ? SW_SHOW : SW_HIDE; int showM = sel == TaskOptions::Monthly ? SW_SHOW : SW_HIDE; int showDT = (sel == TaskOptions::DeltaMin || sel == TaskOptions::DeltaHour) ? SW_SHOW : SW_HIDE; - ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_TIME), showT); - ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_TIME_LABEL), showT); - ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_WEEK), showW); - ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_WEEK_LABEL), showW); - ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DAY), showM); - ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DAY_LABEL), showM); - ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DELTA_TIME), showDT); - ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DELTA_TIME_LABEL), showDT); + ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_TIME), showT); + ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_TIME_LABEL), showT); + ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_WEEK), showW); + ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_WEEK_LABEL), showW); + ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DAY), showM); + ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DAY_LABEL), showM); + ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DELTA_TIME), showDT); + ShowWindow(GetDlgItem(hwndDlg, IDC_TRIGER_DELTA_TIME_LABEL), showDT); } } return TRUE; 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= 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<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"\n"; - + bool isUrl = false; std::wstring mes = ReplaceSmileys(isMe, eventText, isUrl); EXP_FILE << L"
\n"; @@ -391,7 +391,7 @@ void RichHtmlExport::WriteMessage(bool isMe, const std::wstring &longDate, const if (isUrl) ev = L"2"; EXP_FILE << L"
\n"; - EXP_FILE << L"
" << 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"; @@ -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 > positionMap; std::wstring newMsg = MakeTextHtmled(msg, &positionMap); std::wstring smileyMsg; - - size_t last_pos=0; + + size_t last_pos = 0; std::pair 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()) { diff --git a/plugins/BasicHistory/src/Scheduler.cpp b/plugins/BasicHistory/src/Scheduler.cpp index 9c391dce1a..62966543f5 100644 --- a/plugins/BasicHistory/src/Scheduler.cpp +++ b/plugins/BasicHistory/src/Scheduler.cpp @@ -113,7 +113,7 @@ bool IsValidTask(TaskOptions& to, std::list* top, std::wstring* err } } } - + if (!to.isSystem && to.contacts.size() == 0) { if (err != NULL) *err = TranslateT("Contacts"); @@ -126,7 +126,7 @@ bool IsValidTask(TaskOptions& to, std::list* top, std::wstring* err if (!isImportTask) { if (to.filterId > 1) { int filter = 0; - + for (int i = 0; i < (int)Options::instance->customFilters.size(); ++i) { if (to.filterName == Options::instance->customFilters[i].name) { filter = i + 2; @@ -403,12 +403,12 @@ bool DoTask(TaskOptions& to) errorStr += L"\n"; wchar_t msg[1024]; - + mir_snwprintf(msg, TranslateT("Unknown contact in file: %s."), GetName(*it).c_str()); errorStr += msg; } } - + if (contactList.size() > 0) { MCONTACT *pContacts = new MCONTACT[contactList.size() + 1]; pContacts[0] = (MCONTACT)contactList.size(); @@ -459,8 +459,8 @@ bool DoTask(TaskOptions& to) errorStr += L"\n"; wchar_t msg[1024]; - - mir_snwprintf(msg, TranslateT("Cannot export history for contact: %s."), exp->GetContactName().c_str()); + + mir_snwprintf(msg, TranslateT("Cannot export history for contact: %s."), exp->GetContactName().c_str()); errorStr += msg; } @@ -481,7 +481,7 @@ bool DoTask(TaskOptions& to) errorStr += L"\n"; wchar_t msg[1024]; - mir_snwprintf(msg, TranslateT("Cannot export history for contact: %s."), exp->GetContactName().c_str()); + mir_snwprintf(msg, TranslateT("Cannot export history for contact: %s."), exp->GetContactName().c_str()); errorStr += msg; break; } @@ -537,11 +537,11 @@ bool DoTask(TaskOptions& to) errorStr += TranslateT("Cannot send FTP file(s)."); } } - + DeleteDirectory(dir.c_str()); } } - + if (to.type == TaskOptions::Delete || to.type == TaskOptions::ExportAndDelete) { for (std::list::iterator it = managers.begin(); it != managers.end(); ++it) { if (!error) @@ -569,7 +569,7 @@ std::wstring GetFileName(const std::wstring &baseName, std::wstring contactName, int i = 0; wchar_t buf[32]; std::map::iterator it = existingContacts.find(name); - while(it != existingContacts.end()) { + while (it != existingContacts.end()) { _itow_s(++i, buf, 10); name = baseName1 + buf; it = existingContacts.find(name); @@ -606,22 +606,20 @@ std::wstring GetDirectoryName(const std::wstring &path) } void ListDirectory(const std::wstring &basePath, const std::wstring &path, std::list& files) -{ +{ WIN32_FIND_DATA findFileData; HANDLE hFind = FindFirstFile((basePath + path + L"*").c_str(), &findFileData); - if (hFind == INVALID_HANDLE_VALUE) + if (hFind == INVALID_HANDLE_VALUE) return; - do - { + do { if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { std::wstring name = findFileData.cFileName; if (name != L"." && name != L"..") ListDirectory(basePath, path + findFileData.cFileName + L"\\", files); } else files.push_back(path + findFileData.cFileName); - } - while(FindNextFile(hFind, &findFileData)); + } while (FindNextFile(hFind, &findFileData)); FindClose(hFind); } @@ -630,62 +628,61 @@ std::wstring ReplaceStr(const std::wstring& str, wchar_t oldCh, wchar_t newCh) std::wstring ret; size_t start = 0; size_t find; - while((find = str.find_first_of(oldCh, start)) < str.length()) { + while ((find = str.find_first_of(oldCh, start)) < str.length()) { ret += str.substr(start, find - start); ret += newCh; start = find + 1; } - + ret += str.substr(start, str.length() - start); return ret; } time_t GetNextExportTime(TaskOptions& to) { - switch(to.trigerType) { + tm t; + time_t newTime; + + switch (to.trigerType) { case TaskOptions::Daily: - { - tm t; localtime_s(&t, &to.lastExport); - t.tm_hour = to.dayTime/60; - t.tm_min = to.dayTime%60; + t.tm_hour = to.dayTime / 60; + t.tm_min = to.dayTime % 60; t.tm_sec = 0; - time_t newTime = mktime(&t); + newTime = mktime(&t); if (newTime <= to.lastExport) newTime += 60 * 60 * 24; return newTime; - } + case TaskOptions::Weekly: - { - tm t; localtime_s(&t, &to.lastExport); - t.tm_hour = to.dayTime/60; - t.tm_min = to.dayTime%60; + t.tm_hour = to.dayTime / 60; + t.tm_min = to.dayTime % 60; t.tm_sec = 0; - int dow = (to.dayOfWeek + 1) % 7; - time_t newTime = mktime(&t); - while(dow != t.tm_wday) { - newTime += 60 * 60 * 24; - localtime_s(&t, &newTime); + { + int dow = (to.dayOfWeek + 1) % 7; newTime = mktime(&t); + while (dow != t.tm_wday) { + newTime += 60 * 60 * 24; + localtime_s(&t, &newTime); + newTime = mktime(&t); + } } if (newTime <= to.lastExport) newTime += 7 * 60 * 60 * 24; return newTime; - } + case TaskOptions::Monthly: - { - tm t; localtime_s(&t, &to.lastExport); - t.tm_hour = to.dayTime/60; - t.tm_min = to.dayTime%60; + t.tm_hour = to.dayTime / 60; + t.tm_min = to.dayTime % 60; t.tm_sec = 0; - time_t newTime = mktime(&t); - int lastM = t.tm_mon; - int lastD; - while(to.dayOfMonth != t.tm_mday || newTime <= to.lastExport) { - lastD = t.tm_mday; + newTime = mktime(&t); + + while (to.dayOfMonth != t.tm_mday || newTime <= to.lastExport) { + int lastM = t.tm_mon; + int lastD = t.tm_mday; newTime += 60 * 60 * 24; localtime_s(&t, &newTime); newTime = mktime(&t); @@ -699,7 +696,7 @@ time_t GetNextExportTime(TaskOptions& to) } return newTime; - } + case TaskOptions::DeltaMin: return to.lastExport + to.deltaTime * 60; case TaskOptions::DeltaHour: @@ -713,13 +710,13 @@ void SchedulerThreadFunc(void*) { if (initTask) { WaitForSingleObject(hThreadEvent, 5 * 1000); - initTask = false; + initTask = false; } - while(!finishThread) { + while (!finishThread) { DWORD timeWait; time_t now = time(NULL); - while(nextExportTime <= now) + while (nextExportTime <= now) if (!ExecuteCurrentTask(now)) return; @@ -733,7 +730,7 @@ void SchedulerThreadFunc(void*) void StartThread(bool init) { StopThread(); - + initTask = false; bool isExport = GetNextExportTime(init, time(NULL)); if (isExport) { @@ -787,13 +784,13 @@ bool GetNextExportTime(bool init, time_t now) initTask = true; } } - + return isExport; } static void CALLBACK DoTaskFinishInMainAPCFunc(ULONG_PTR dwParam) { - wchar_t *item = (wchar_t*) dwParam; + wchar_t *item = (wchar_t*)dwParam; MessageBox(NULL, item, TranslateT("Task finished"), MB_OK | MB_ICONINFORMATION); delete[] item; } @@ -846,7 +843,7 @@ bool ExecuteCurrentTask(time_t now) mir_snwprintf(name, size, TranslateT("Task '%s' execution failed"), to.taskName.c_str()); else mir_snwprintf(name, size, TranslateT("Task '%s' finished successfully"), to.taskName.c_str()); - QueueUserAPC(DoTaskFinishInMainAPCFunc, g_hMainThread, (ULONG_PTR) name); + QueueUserAPC(DoTaskFinishInMainAPCFunc, g_hMainThread, (ULONG_PTR)name); } } } @@ -861,13 +858,13 @@ void GetZipFileTime(const wchar_t *file, uLong *dt) HANDLE hFind = FindFirstFile(file, &ff32); if (hFind != INVALID_HANDLE_VALUE) { FileTimeToLocalFileTime(&(ff32.ftLastWriteTime), &ftLocal); - FileTimeToDosDateTime(&ftLocal,((LPWORD)dt)+1,((LPWORD)dt)+0); + FileTimeToDosDateTime(&ftLocal, ((LPWORD)dt) + 1, ((LPWORD)dt) + 0); FindClose(hFind); } } /* calculate the CRC32 of a file, - because to encrypt a file, we need known the CRC32 of the file before */ + because to encrypt a file, we need known the CRC32 of the file before */ bool GetFileCrc(const wchar_t *filenameinzip, unsigned char *buf, unsigned long, unsigned long *result_crc) { unsigned long calculate_crc = 0; @@ -875,23 +872,21 @@ bool GetFileCrc(const wchar_t *filenameinzip, unsigned char *buf, unsigned long, HANDLE hFile = CreateFile(filenameinzip, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { DWORD readed; - do - { + do { if (!ReadFile(hFile, buf, 1024, &readed, NULL)) { error = false; break; } - + if (readed > 0) calculate_crc = crc32(calculate_crc, buf, readed); - } - while (readed > 0); + } while (readed > 0); CloseHandle(hFile); } else error = false; - *result_crc=calculate_crc; - return error; + *result_crc = calculate_crc; + return error; } bool ZipFiles(const std::wstring &dir, std::wstring zipFilePath, const std::string &password) @@ -909,10 +904,10 @@ bool ZipFiles(const std::wstring &dir, std::wstring zipFilePath, const std::stri if (zf != NULL) { unsigned char buf[1024]; char bufF[MAX_PATH + 20]; - while(files.size() > 0) { + while (files.size() > 0) { std::wstring zipDir = *files.begin(); std::wstring localDir = dir + L"\\" + zipDir; - zip_fileinfo zi = {0}; + zip_fileinfo zi = { 0 }; GetZipFileTime(localDir.c_str(), &zi.dosDate); if (zipDir.size() > MAX_PATH + 19) { error = true; @@ -938,27 +933,25 @@ bool ZipFiles(const std::wstring &dir, std::wstring zipFilePath, const std::stri passwordCh = password.c_str(); } - int err = zipOpenNewFileInZip4_64 (zf, bufF, &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, - -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, passwordCh, calculate_crc, 0, flag, 0); + int err = zipOpenNewFileInZip4_64(zf, bufF, &zi, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION, 0, + -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, passwordCh, calculate_crc, 0, flag, 0); if (err == ZIP_OK) { HANDLE hFile = CreateFile(localDir.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hFile != INVALID_HANDLE_VALUE) { DWORD readed; - do - { + do { err = ZIP_OK; if (!ReadFile(hFile, buf, 1024, &readed, NULL)) { error = true; break; } - + if (readed > 0) err = zipWriteInFileInZip(zf, buf, readed); - } - while ((err == ZIP_OK) && (readed > 0)); + } while ((err == ZIP_OK) && (readed > 0)); CloseHandle(hFile); } - + if (zipCloseFileInZip(zf) != ZIP_OK) { error = true; break; @@ -997,8 +990,7 @@ bool UnzipFiles(const std::wstring &dir, std::wstring &zipFilePath, const std::s char buf[8192]; char bufF[MAX_PATH + 20]; unz_file_info file_info; - do - { + do { int err = unzGetCurrentFileInfo(zf, &file_info, bufF, MAX_PATH + 20, buf, 8192, NULL, 0); if (err == UNZ_OK) { UINT cp = CP_OEMCP; @@ -1007,12 +999,12 @@ bool UnzipFiles(const std::wstring &dir, std::wstring &zipFilePath, const std::s // Get Unicode file name for InfoZip style archives, otherwise assume PKZip/WinZip style if (file_info.size_file_extra) { - char *p = buf; + char *p = buf; unsigned long size = min(file_info.size_file_extra, 8192); while (size > 0) { - unsigned short id = *(unsigned short*)p; - unsigned len = *(unsigned short*)(p + 2); - + unsigned short id = *(unsigned short*)p; + unsigned len = *(unsigned short*)(p + 2); + if (size < (len + 4)) break; if (id == 0x7075 && len > 5 && (len - 5) < MAX_PATH + 20 && *(p + 4) == 1) { @@ -1025,16 +1017,16 @@ bool UnzipFiles(const std::wstring &dir, std::wstring &zipFilePath, const std::s p += len + 4; } } - + int sizeC = (int)mir_strlen(bufF); int sizeW = MultiByteToWideChar(cp, 0, bufF, sizeC, NULL, 0); fileNameInZip.resize(sizeW); MultiByteToWideChar(cp, 0, bufF, sizeC, (wchar_t*)fileNameInZip.c_str(), sizeW); fileNameInZip = dir + L"\\" + fileNameInZip; - for (size_t i = 0; i < fileNameInZip.length(); ++i) - if (fileNameInZip[i] == L'/') - fileNameInZip[i] = L'\\'; - + for (size_t i = 0; i < fileNameInZip.length(); ++i) + if (fileNameInZip[i] == L'/') + fileNameInZip[i] = L'\\'; + if (file_info.external_fa & FILE_ATTRIBUTE_DIRECTORY) CreatePath(fileNameInZip.c_str()); else { @@ -1052,7 +1044,7 @@ bool UnzipFiles(const std::wstring &dir, std::wstring &zipFilePath, const std::s err = unzReadCurrentFile(zf, buf, 8192); if (err <= 0) break; - if ( !WriteFile(hFile, buf, err, &writed, FALSE)) { + if (!WriteFile(hFile, buf, err, &writed, FALSE)) { err = -1; break; } @@ -1069,7 +1061,7 @@ bool UnzipFiles(const std::wstring &dir, std::wstring &zipFilePath, const std::s error = true; break; } - + if (unzCloseCurrentFile(zf) != ZIP_OK) { error = true; break; @@ -1085,8 +1077,7 @@ bool UnzipFiles(const std::wstring &dir, std::wstring &zipFilePath, const std::s error = true; break; } - } - while (unzGoToNextFile(zf) == UNZ_OK); + } while (unzGoToNextFile(zf) == UNZ_OK); unzClose(zf); return error; diff --git a/plugins/BasicHistory/src/Searcher.cpp b/plugins/BasicHistory/src/Searcher.cpp index a2f09eb24c..e47007893b 100644 --- a/plugins/BasicHistory/src/Searcher.cpp +++ b/plugins/BasicHistory/src/Searcher.cpp @@ -35,10 +35,10 @@ void Searcher::ChangeFindDirection(bool isBack) { if (isBack != findBack) { findBack = isBack; - ClearFind(); + ClearFind(); TBBUTTONINFO tbInfo; - tbInfo.cbSize = sizeof(TBBUTTONINFO); - tbInfo.dwMask = TBIF_TEXT | TBIF_IMAGE; + tbInfo.cbSize = sizeof(TBBUTTONINFO); + tbInfo.dwMask = TBIF_TEXT | TBIF_IMAGE; if (isBack) { tbInfo.pszText = TranslateT("Find Previous"); tbInfo.iImage = 1; @@ -46,7 +46,7 @@ void Searcher::ChangeFindDirection(bool isBack) else { tbInfo.pszText = TranslateT("Find Next"); tbInfo.iImage = 0; - } + } SendMessage(context->toolbarWindow, TB_SETBUTTONINFO, (WPARAM)IDM_FIND, (LPARAM)&tbInfo); } @@ -56,7 +56,7 @@ void Searcher::ChangeFindDirection(bool isBack) void Searcher::ClearFind() { if (lastFindSelection != -1) { - SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_AND,~ECO_NOHIDESEL); + SendMessage(context->editWindow, EM_SETOPTIONS, ECOOP_AND, ~ECO_NOHIDESEL); lastFindSelection = -1; } } @@ -76,7 +76,7 @@ bool Searcher::CompareStr(std::wstring str, wchar_t *strFind) size_t findid = str.find(strFind); size_t findLen = mir_wstrlen(strFind); - while(findid < str.length()) { + while (findid < str.length()) { if ((findid == 0 || std::isspace(str[findid - 1], loc) || std::ispunct(str[findid - 1], loc)) && (findid + findLen >= str.length() || std::isspace(str[findid + findLen], loc) || std::ispunct(str[findid + findLen], loc))) return true; @@ -97,7 +97,7 @@ void Searcher::Find() ft.chrg.cpMax = -1; ft.lpstrText = str; if (context->currentGroup.size() < 1) { - SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_AND,~ECO_NOHIDESEL); + SendMessage(context->editWindow, EM_SETOPTIONS, ECOOP_AND, ~ECO_NOHIDESEL); lastFindSelection = -1; return; } @@ -113,7 +113,7 @@ void Searcher::Find() std::locale loc; std::transform(str, str + mir_wstrlen(str), str, std::bind2nd(std::ptr_fun(mytoupper), &loc)); } - + bool findBack1 = findBack ^ !searchForInMes; bool findBack2 = findBack ^ !searchForInLG; int adder1 = findBack1 ? -1 : 1; @@ -123,16 +123,16 @@ void Searcher::Find() if (onlyIn && context->currentGroup[lastFindSelection].isMe || onlyOut && !context->currentGroup[lastFindSelection].isMe) curSel = lastFindSelection + adder1; else { - SendDlgItemMessage(context->m_hWnd,IDC_EDIT,EM_EXGETSEL,0,(LPARAM)&ft.chrg); + SendDlgItemMessage(context->m_hWnd, IDC_EDIT, EM_EXGETSEL, 0, (LPARAM)&ft.chrg); if (findBack1) { - ft.chrg.cpMin = ft.chrg.cpMin < context->currentGroup[lastFindSelection].endPos ? ft.chrg.cpMin : context->currentGroup[lastFindSelection].endPos; + ft.chrg.cpMin = ft.chrg.cpMin < context->currentGroup[lastFindSelection].endPos ? ft.chrg.cpMin : context->currentGroup[lastFindSelection].endPos; ft.chrg.cpMax = context->currentGroup[lastFindSelection].startPos; } else { ft.chrg.cpMin = ft.chrg.cpMax > context->currentGroup[lastFindSelection].startPos ? ft.chrg.cpMax : context->currentGroup[lastFindSelection].startPos; ft.chrg.cpMax = context->currentGroup[lastFindSelection].endPos; } - SendMessage(context->editWindow,EM_FINDTEXTEX, findStyle,(LPARAM)&ft); + SendMessage(context->editWindow, EM_FINDTEXTEX, findStyle, (LPARAM)&ft); if (ft.chrgText.cpMin < 0 || ft.chrgText.cpMax < 0) curSel = lastFindSelection + adder1; else { @@ -140,8 +140,8 @@ void Searcher::Find() finished = true; else { curSel = lastFindSelection; - SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ft.chrgText); - SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL); + SendMessage(context->editWindow, EM_EXSETSEL, 0, (LPARAM)&ft.chrgText); + SendMessage(context->editWindow, EM_SETOPTIONS, ECOOP_OR, ECO_NOHIDESEL); lastFindSelection = curSel; return; } @@ -150,8 +150,8 @@ void Searcher::Find() } else { isStart = true; - SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL); - SendMessage(context->editWindow,EM_EXGETSEL,0,(LPARAM)&ft.chrg); + SendMessage(context->editWindow, EM_SETOPTIONS, ECOOP_OR, ECO_NOHIDESEL); + SendMessage(context->editWindow, EM_EXGETSEL, 0, (LPARAM)&ft.chrg); startFindPos = findBack1 ? ft.chrg.cpMin : (ft.chrg.cpMax >= 0 ? ft.chrg.cpMax : ft.chrg.cpMin); startFindSel = context->selected; if (startFindPos < 0) @@ -188,21 +188,21 @@ void Searcher::Find() if (!isFindSelChanged && ft.chrg.cpMin < startFindPos) ft.chrg.cpMin = startFindPos; } - SendMessage(context->editWindow,EM_FINDTEXTEX, findStyle,(LPARAM)&ft); + SendMessage(context->editWindow, EM_FINDTEXTEX, findStyle, (LPARAM)&ft); if (!(ft.chrgText.cpMin < 0 || ft.chrgText.cpMax < 0)) { if (isFindContactChanged && startFindContact == context->m_hContact && isFindSelChanged && context->selected == startFindSel && ((!findBack1 && ft.chrg.cpMin >= startFindPos) || (findBack1 && ft.chrg.cpMax <= startFindPos))) { finished = true; break; } - SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ft.chrgText); - SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL); + SendMessage(context->editWindow, EM_EXSETSEL, 0, (LPARAM)&ft.chrgText); + SendMessage(context->editWindow, EM_SETOPTIONS, ECOOP_OR, ECO_NOHIDESEL); lastFindSelection = curSel; return; } } } } - + if (isFindContactChanged && startFindContact == context->m_hContact && isFindSelChanged && context->selected == startFindSel) finished = true; @@ -212,7 +212,7 @@ void Searcher::Find() if (IsInSel(context->selected, str)) { CHARRANGE ch; ch.cpMin = ch.cpMax = findBack1 ? MAXLONG : 0; - SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ch); + SendMessage(context->editWindow, EM_EXSETSEL, 0, (LPARAM)&ch); lastFindSelection = findBack1 ? (int)context->currentGroup.size() - 1 : 0; Find(); return; @@ -224,11 +224,9 @@ void Searcher::Find() isFindContactChanged = true; if (allUsers) { MCONTACT hNext = context->m_hContact; - do - { + do { hNext = context->GetNextContact(hNext, adder2); - } - while(hNext != startFindContact && !context->SearchInContact(hNext, str, this)); + } while (hNext != startFindContact && !context->SearchInContact(hNext, str, this)); context->SelectContact(hNext); } @@ -238,18 +236,16 @@ void Searcher::Find() isFindContactChanged = true; if (allUsers) { MCONTACT hNext = context->m_hContact; - do - { + do { hNext = context->GetNextContact(hNext, adder2); - } - while(hNext != startFindContact && !context->SearchInContact(hNext, str, this)); + } while (hNext != startFindContact && !context->SearchInContact(hNext, str, this)); context->SelectContact(hNext); } sel = 0; } if (IsInSel(sel, str)) { - LVITEM item = {0}; + LVITEM item = { 0 }; item.mask = LVIF_STATE; item.iItem = context->selected; item.state = 0; @@ -258,11 +254,11 @@ void Searcher::Find() item.iItem = sel; item.state = LVIS_SELECTED; ListView_SetItem(context->listWindow, &item); - ListView_EnsureVisible(context->listWindow, sel, FALSE); + ListView_EnsureVisible(context->listWindow, sel, FALSE); CHARRANGE ch; ch.cpMin = ch.cpMax = findBack1 ? MAXLONG : 0; - SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ch); - SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL); + SendMessage(context->editWindow, EM_EXSETSEL, 0, (LPARAM)&ch); + SendMessage(context->editWindow, EM_SETOPTIONS, ECOOP_OR, ECO_NOHIDESEL); lastFindSelection = findBack1 ? (int)context->currentGroup.size() - 1 : 0; isFindSelChanged = true; Find(); @@ -273,12 +269,12 @@ void Searcher::Find() } } } - + if (startFindContact != context->m_hContact) context->SelectContact(startFindContact); if (startFindSel != context->selected) { - LVITEM item = {0}; + LVITEM item = { 0 }; item.mask = LVIF_STATE; item.iItem = context->selected; item.state = 0; @@ -287,14 +283,14 @@ void Searcher::Find() item.iItem = startFindSel; item.state = LVIS_SELECTED; ListView_SetItem(context->listWindow, &item); - ListView_EnsureVisible(context->listWindow, startFindSel, FALSE); + ListView_EnsureVisible(context->listWindow, startFindSel, FALSE); context->SelectEventGroup(startFindSel); - SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_OR,ECO_NOHIDESEL); + SendMessage(context->editWindow, EM_SETOPTIONS, ECOOP_OR, ECO_NOHIDESEL); } ft.chrgText.cpMin = startFindPos; ft.chrgText.cpMax = startFindPos; - SendMessage(context->editWindow,EM_EXSETSEL,0,(LPARAM)&ft.chrgText); - SendMessage(context->editWindow,EM_SETOPTIONS,ECOOP_AND,~ECO_NOHIDESEL); + SendMessage(context->editWindow, EM_EXSETSEL, 0, (LPARAM)&ft.chrgText); + SendMessage(context->editWindow, EM_SETOPTIONS, ECOOP_AND, ~ECO_NOHIDESEL); lastFindSelection = -1; if (isStart) { wchar_t buf[256]; @@ -324,7 +320,7 @@ bool Searcher::IsInSel(int sel, wchar_t *strFind) return true; } } - + return false; } diff --git a/plugins/BasicHistory/src/TxtExport.cpp b/plugins/BasicHistory/src/TxtExport.cpp index 89df71c8b3..45874d7276 100644 --- a/plugins/BasicHistory/src/TxtExport.cpp +++ b/plugins/BasicHistory/src/TxtExport.cpp @@ -30,23 +30,15 @@ void TxtExport::WriteHeader(const std::wstring&, const std::wstring &filterName, EXP_FILE << start << "\n" << start << L" " << TranslateT("History Log") << L"\n"; EXP_FILE << start << L" " << myName; if (proto1.length() || myId.length()) - { EXP_FILE << L" (" << proto1 << L": " << myId << L") - "; - } else - { EXP_FILE << L" - "; - } EXP_FILE << name1; if (proto1.length() || id1.length()) - { EXP_FILE << L" (" << proto1 << L": " << id1 << L")\n"; - } else - { EXP_FILE << L"\n"; - } EXP_FILE << start << L" " << TranslateT("Filter:") << L" " << filterName << L"\n" << start << L"\n"; } -- cgit v1.2.3