From 477a6ea70d0bb1b1dfe9cbd9a15b6dad0284ddeb Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 21 Feb 2018 18:40:03 +0300 Subject: all another C++'11 iterators --- plugins/CSList/src/cslist.cpp | 7 +- plugins/DbEditorPP/src/modsettingenum.cpp | 14 +- plugins/Db_autobackups/src/zip.cpp | 17 +- plugins/Dbx_mdbx/src/dbcontacts.cpp | 6 +- plugins/Dbx_mdbx/src/dbsettings.cpp | 4 +- plugins/FavContacts/src/contact_cache.cpp | 4 +- plugins/FavContacts/src/favlist.h | 4 +- plugins/FavContacts/src/menu.cpp | 10 +- plugins/FloatingContacts/src/main.cpp | 44 ++-- plugins/FloatingContacts/src/thumbs.cpp | 23 +-- plugins/Folders/src/dlg_handlers.cpp | 20 +- plugins/GmailNotifier/src/check.cpp | 9 +- plugins/GmailNotifier/src/main.cpp | 8 +- plugins/GmailNotifier/src/options.cpp | 8 +- plugins/GmailNotifier/src/utility.cpp | 15 +- plugins/HistorySweeperLight/src/options.cpp | 4 +- plugins/Import/src/import.cpp | 54 +++-- plugins/MirLua/src/mlua_metatable.h | 10 +- plugins/MirLua/src/mlua_options.cpp | 9 +- plugins/NewXstatusNotify/src/options.cpp | 11 +- plugins/Nudge/src/main.cpp | 94 ++++----- plugins/Nudge/src/options.cpp | 21 +- plugins/PluginUpdater/src/DlgListNew.cpp | 74 +++---- plugins/PluginUpdater/src/DlgUpdate.cpp | 60 +++--- plugins/QuickContacts/src/quickcontacts.cpp | 298 ++++++++++++---------------- plugins/QuickReplies/src/events.cpp | 4 +- plugins/Scriver/src/chat_manager.cpp | 3 +- plugins/Scriver/src/msgs.cpp | 9 +- plugins/SecureIM/src/crypt_icons.cpp | 10 +- plugins/SecureIM/src/crypt_lists.cpp | 21 +- plugins/SeenPlugin/src/utils.cpp | 4 +- plugins/SimpleStatusMsg/src/utils.cpp | 6 +- plugins/SpellChecker/src/dictionary.cpp | 12 +- plugins/SpellChecker/src/options.cpp | 10 +- plugins/SpellChecker/src/spellchecker.cpp | 6 +- plugins/SpellChecker/src/utils.cpp | 7 +- plugins/TopToolBar/src/toolbar.cpp | 19 +- plugins/TopToolBar/src/ttbopt.cpp | 12 +- plugins/Variables/src/contact.cpp | 27 ++- plugins/Variables/src/parse_alias.cpp | 12 +- plugins/Variables/src/tokenregister.cpp | 3 +- plugins/XSoundNotify/src/options.cpp | 22 +- plugins/YAPP/src/options.cpp | 3 +- plugins/YAPP/src/services.cpp | 10 +- protocols/FacebookRM/src/messages.cpp | 4 +- protocols/FacebookRM/src/stdafx.h | 4 +- protocols/FacebookRM/src/theme.cpp | 6 +- protocols/Gadu-Gadu/src/avatar.cpp | 12 +- protocols/Gadu-Gadu/src/gg.cpp | 6 +- protocols/Gadu-Gadu/src/links.cpp | 12 +- protocols/Gadu-Gadu/src/oauth.cpp | 55 ++--- protocols/MRA/src/MraProto.cpp | 4 +- protocols/MRA/src/Mra_functions.cpp | 255 ++++++++++++------------ protocols/MRA/src/Mra_svcs.cpp | 7 +- protocols/Steam/src/steam_accounts.cpp | 6 +- protocols/Tox/src/tox_accounts.cpp | 7 +- protocols/Tox/src/tox_utils.cpp | 6 +- protocols/Twitter/src/theme.cpp | 6 +- 58 files changed, 649 insertions(+), 769 deletions(-) diff --git a/plugins/CSList/src/cslist.cpp b/plugins/CSList/src/cslist.cpp index d90e0181d4..2bc27345bb 100644 --- a/plugins/CSList/src/cslist.cpp +++ b/plugins/CSList/src/cslist.cpp @@ -106,8 +106,8 @@ static int OnCreateMenuItems(WPARAM, LPARAM) static int OnPreshutdown(WPARAM, LPARAM) { - for (int i = 0; i < arWindows.getCount(); i++) - DestroyWindow(arWindows[i]->m_handle); + for (auto &it : arWindows) + DestroyWindow(it->m_handle); return 0; } @@ -208,8 +208,7 @@ void SetStatus(WORD code, StatusItem* item, char *szAccName) INT_PTR showList(WPARAM, LPARAM, LPARAM param) { char* szProto = (char*)param; - for (int i = 0; i < arWindows.getCount(); i++) { - CSWindow *p = arWindows[i]; + for (auto &p : arWindows) { if (!mir_strcmp(szProto, p->m_protoName)) { ShowWindow(p->m_handle, SW_SHOW); SetForegroundWindow(p->m_handle); diff --git a/plugins/DbEditorPP/src/modsettingenum.cpp b/plugins/DbEditorPP/src/modsettingenum.cpp index e0a4d40ba1..79e734baf3 100644 --- a/plugins/DbEditorPP/src/modsettingenum.cpp +++ b/plugins/DbEditorPP/src/modsettingenum.cpp @@ -103,9 +103,8 @@ int LoadResidentSettings() void FreeResidentSettings() { - for (int i = 0; i < m_lResidentSettings.getCount(); i++) - mir_free(m_lResidentSettings[i]); - + for (auto &it : m_lResidentSettings) + mir_free(it); m_lResidentSettings.destroy(); } @@ -132,13 +131,14 @@ int EnumResidentSettings(const char *module, ModuleSettingLL *msll) int len = (int)mir_strlen(module); int cnt = 0; - for (int i = 0; i < m_lResidentSettings.getCount(); i++) { - if (strncmp(module, m_lResidentSettings[i], len)) + for (auto &it : m_lResidentSettings) { + if (strncmp(module, it, len)) continue; - if (m_lResidentSettings[i][len] != '/' || m_lResidentSettings[i][len + 1] == 0) continue; + if (it[len] != '/' || it[len + 1] == 0) + continue; - enumModulesSettingsProc(&m_lResidentSettings[i][len + 1], msll); + enumModulesSettingsProc(&it[len + 1], msll); cnt++; } return cnt; diff --git a/plugins/Db_autobackups/src/zip.cpp b/plugins/Db_autobackups/src/zip.cpp index c4a2b145f1..c0c7e08c43 100644 --- a/plugins/Db_autobackups/src/zip.cpp +++ b/plugins/Db_autobackups/src/zip.cpp @@ -9,17 +9,14 @@ int CreateZipFile(const char *szDestPath, OBJLIST &lstFiles, const std: zip_fileinfo fi = { 0 }; int ret = 0; - for (int i = 0; i < lstFiles.getCount(); i++) - { + for (int i = 0; i < lstFiles.getCount(); i++) { ZipFile &zf = lstFiles[i]; HANDLE hSrcFile = CreateFileA(zf.sPath.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); - if (hSrcFile != INVALID_HANDLE_VALUE) - { + if (hSrcFile != INVALID_HANDLE_VALUE) { int iOpenRes = zipOpenNewFileInZip(hZip, zf.sZipPath.c_str(), &fi, nullptr, 0, nullptr, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION); - if (iOpenRes == ZIP_OK) - { + if (iOpenRes == ZIP_OK) { DWORD dwRead; BYTE buf[0x40000]; @@ -27,17 +24,15 @@ int CreateZipFile(const char *szDestPath, OBJLIST &lstFiles, const std: zipCloseFileInZip(hZip); CloseHandle(hSrcFile); - if (!fnCallback(i)) - { + if (!fnCallback(i)) { ret = 3; break; } } - else - CloseHandle(hSrcFile); + else CloseHandle(hSrcFile); } } zipClose(hZip, CMStringA(FORMAT, Translate("Miranda NG [%s] database backup"), g_szMirVer)); return ret; -} \ No newline at end of file +} diff --git a/plugins/Dbx_mdbx/src/dbcontacts.cpp b/plugins/Dbx_mdbx/src/dbcontacts.cpp index 72a88492d1..8c2efb9df1 100644 --- a/plugins/Dbx_mdbx/src/dbcontacts.cpp +++ b/plugins/Dbx_mdbx/src/dbcontacts.cpp @@ -130,8 +130,7 @@ BOOL CDbxMDBX::MetaMergeHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) LIST list(1000); GatherContactHistory(ccSub->contactID, list); - for (int i = 0; i < list.getCount(); i++) { - EventItem *EI = list[i]; + for (auto &EI : list) { { txn_ptr trnlck(m_env); @@ -163,8 +162,7 @@ BOOL CDbxMDBX::MetaSplitHistory(DBCachedContact *ccMeta, DBCachedContact *ccSub) LIST list(1000); GatherContactHistory(ccSub->contactID, list); - for (int i = 0; i < list.getCount(); i++) { - EventItem *EI = list[i]; + for (auto &EI : list) { { txn_ptr trnlck(m_env); DBEventSortingKey insVal = { ccMeta->contactID, EI->eventId, EI->ts }; diff --git a/plugins/Dbx_mdbx/src/dbsettings.cpp b/plugins/Dbx_mdbx/src/dbsettings.cpp index 775e69b733..b4491189bf 100644 --- a/plugins/Dbx_mdbx/src/dbsettings.cpp +++ b/plugins/Dbx_mdbx/src/dbsettings.cpp @@ -399,8 +399,8 @@ STDMETHODIMP_(BOOL) CDbxMDBX::EnumContactSettings(MCONTACT hContact, DBSETTINGEN } int result = -1; - for (int i=0; i < arKeys.getCount(); i++) - result = pfnEnumProc(arKeys[i], param); + for (auto &it : arKeys) + result = pfnEnumProc(it, param); return result; } diff --git a/plugins/FavContacts/src/contact_cache.cpp b/plugins/FavContacts/src/contact_cache.cpp index d6039f3782..d60cd00d84 100644 --- a/plugins/FavContacts/src/contact_cache.cpp +++ b/plugins/FavContacts/src/contact_cache.cpp @@ -19,8 +19,8 @@ CContactCache::CContactCache() : CContactCache::~CContactCache() { - for (int i = 0; i < m_cache.getCount(); i++) - delete m_cache[i]; + for (auto &it : m_cache) + delete it; } int __cdecl CContactCache::OnDbEventAdded(WPARAM hContact, LPARAM hEvent) diff --git a/plugins/FavContacts/src/favlist.h b/plugins/FavContacts/src/favlist.h index b6ebc70f2e..c9ed5bc2c3 100644 --- a/plugins/FavContacts/src/favlist.h +++ b/plugins/FavContacts/src/favlist.h @@ -99,8 +99,8 @@ public: ~TFavContacts() { - for (int i = 0; i < this->getCount(); ++i) - delete (*this)[i]; + for (auto &it : *this) + delete it; } __forceinline int groupCount() const { return nGroups; } diff --git a/plugins/FavContacts/src/menu.cpp b/plugins/FavContacts/src/menu.cpp index f0c8e1072e..4770696e65 100644 --- a/plugins/FavContacts/src/menu.cpp +++ b/plugins/FavContacts/src/menu.cpp @@ -458,21 +458,21 @@ int ShowMenu(bool centered) g_maxItemWidth /= favList.groupCount(); prevGroup = nullptr; - for (int i = 0; i < favList.getCount(); ++i) { - hContact = favList[i]->getHandle(); + for (auto &it : favList) { + hContact = it->getHandle(); MEASUREITEMSTRUCT mis = { 0 }; mis.CtlID = 0; mis.CtlType = ODT_MENU; - if (!prevGroup || mir_wstrcmp(prevGroup, favList[i]->getGroup())) { + if (!prevGroup || mir_wstrcmp(prevGroup, it->getGroup())) { if (prevGroup && g_Options.bUseColumns) { szMenu.cx += szColumn.cx; szMenu.cy = max(szMenu.cy, szColumn.cy); szColumn.cx = szColumn.cy = 0; } - int groupID = -((INT_PTR)Clist_GroupExists(favList[i]->getGroup()) + 1); + int groupID = -((INT_PTR)Clist_GroupExists(it->getGroup()) + 1); AppendMenu(hMenu, MF_OWNERDRAW | MF_SEPARATOR | ((prevGroup && g_Options.bUseColumns) ? MF_MENUBREAK : 0), @@ -493,7 +493,7 @@ int ShowMenu(bool centered) szColumn.cx = max(szColumn.cx, (int)mis.itemWidth); szColumn.cy += mis.itemHeight; - prevGroup = favList[i]->getGroup(); + prevGroup = it->getGroup(); } szMenu.cx += szColumn.cx; szMenu.cy = max(szMenu.cy, szColumn.cy); diff --git a/plugins/FloatingContacts/src/main.cpp b/plugins/FloatingContacts/src/main.cpp index fb098b2752..80b435b9cd 100644 --- a/plugins/FloatingContacts/src/main.cpp +++ b/plugins/FloatingContacts/src/main.cpp @@ -213,8 +213,8 @@ static int OnSkinIconsChanged(WPARAM, LPARAM) himlMiranda = Clist_GetImageList(); // Update thumbs - for (int i = 0; i < thumbList.getCount(); ++i) - thumbList[i].UpdateContent(); + for (auto &it : thumbList) + it->UpdateContent(); return 0; } @@ -261,9 +261,9 @@ static int OnContactSettingChanged(WPARAM hContact, LPARAM lParam) static int OnStatusModeChange(WPARAM wParam, LPARAM) { - for (int i = 0; i < thumbList.getCount(); ++i) { - int idStatus = GetContactStatus(thumbList[i].hContact); - thumbList[i].RefreshContactStatus(idStatus); + for (auto &it : thumbList) { + int idStatus = GetContactStatus(it->hContact); + it->RefreshContactStatus(idStatus); } if (wParam == ID_STATUS_OFFLINE) { @@ -434,8 +434,8 @@ static LRESULT __stdcall CommWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM extern void SetThumbsOpacity(BYTE btAlpha) { - for (int i = 0; i < thumbList.getCount(); ++i) - thumbList[i].SetThumbOpacity(btAlpha); + for (auto &it : thumbList) + it->SetThumbOpacity(btAlpha); } static void GetScreenRect() @@ -450,9 +450,9 @@ void OnStatusChanged() { int idStatus = ID_STATUS_OFFLINE; - for (int i = 0; i < thumbList.getCount(); ++i) { - idStatus = GetContactStatus(thumbList[i].hContact); - thumbList[i].RefreshContactStatus(idStatus); + for (auto &it : thumbList) { + idStatus = GetContactStatus(it->hContact); + it->RefreshContactStatus(idStatus); } } @@ -475,8 +475,8 @@ void ApplyOptionsChanges() OnStatusChanged(); - for (int i = 0; i < thumbList.getCount(); ++i) - thumbList[i].ResizeThumb(); + for (auto &it : thumbList) + it->ResizeThumb(); } /////////////////////////////////////////////////////// @@ -656,14 +656,14 @@ void RegHotkey(MCONTACT hContact, HWND hwnd) void SaveContactsPos() { - for (int i = 0; i < thumbList.getCount(); ++i) { + for (auto &it : thumbList) { SetLastError(0); RECT rc; - thumbList[i].GetThumbRect(&rc); + it->GetThumbRect(&rc); if (0 == GetLastError()) - db_set_dw(thumbList[i].hContact, MODULE, "ThumbsPos", DB_POS_MAKE_XY(rc.left, rc.top)); + db_set_dw(it->hContact, MODULE, "ThumbsPos", DB_POS_MAKE_XY(rc.left, rc.top)); } } @@ -803,8 +803,8 @@ BOOL HideOnFullScreen() static VOID CALLBACK ToTopTimerProc(HWND, UINT, UINT_PTR, DWORD) { - for (int i = 0; i < thumbList.getCount(); ++i) - SetWindowPos(thumbList[i].hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); + for (auto &it : thumbList) + SetWindowPos(it->hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); } void ShowThumbsOnHideCList() @@ -812,9 +812,9 @@ void ShowThumbsOnHideCList() if (!fcOpt.bHideWhenCListShow || fcOpt.bHideAll || HideOnFullScreen()) return; - for (int i = 0; i < thumbList.getCount(); ++i) - if (!fcOpt.bHideOffline || IsStatusVisible(GetContactStatus(thumbList[i].hContact))) - ShowWindow(thumbList[i].hwnd, SW_SHOWNA); + for (auto &it : thumbList) + if (!fcOpt.bHideOffline || IsStatusVisible(GetContactStatus(it->hContact))) + ShowWindow(it->hwnd, SW_SHOWNA); } @@ -823,8 +823,8 @@ void HideThumbsOnShowCList() if (!fcOpt.bHideWhenCListShow || fcOpt.bHideAll || HideOnFullScreen()) return; - for (int i = 0; i < thumbList.getCount(); ++i) - ShowWindow(thumbList[i].hwnd, SW_HIDE); + for (auto &it : thumbList) + ShowWindow(it->hwnd, SW_HIDE); } static LRESULT __stdcall newMirandaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) diff --git a/plugins/FloatingContacts/src/thumbs.cpp b/plugins/FloatingContacts/src/thumbs.cpp index 27f953a689..46a593c656 100644 --- a/plugins/FloatingContacts/src/thumbs.cpp +++ b/plugins/FloatingContacts/src/thumbs.cpp @@ -107,15 +107,14 @@ void ThumbInfo::PositionThumbWorker(int nX, int nY, POINT *newPos) if (fcOpt.bMoveTogether) UndockThumbs(this, thumbList.FindThumb(dockOpt.hwndLeft)); - for (int i = 0; i < thumbList.getCount(); ++i) { - ThumbInfo *pCurThumb = &thumbList[i]; - if (pCurThumb == this) + for (auto &it : thumbList) { + if (it == this) continue; GetThumbRect(&rcThumb); OffsetRect(&rcThumb, nX - rcThumb.left, nY - rcThumb.top); - pCurThumb->GetThumbRect(&rc); + it->GetThumbRect(&rc); // These are rects we will dock into @@ -190,10 +189,10 @@ void ThumbInfo::PositionThumbWorker(int nX, int nY, POINT *newPos) if (fcOpt.bMoveTogether) { if (bDockedRight) - DockThumbs(this, pCurThumb); + DockThumbs(this, it); if (bDockedLeft) - DockThumbs(pCurThumb, this); + DockThumbs(it, this); } // Lower-left @@ -776,9 +775,9 @@ ThumbInfo* ThumbList::FindThumb(HWND hwnd) { if (!hwnd) return nullptr; - for (int i = 0; i < getCount(); ++i) - if (items[i]->hwnd == hwnd) - return items[i]; + for (auto &it : *this) + if (it->hwnd == hwnd) + return it; return nullptr; } @@ -787,9 +786,9 @@ ThumbInfo *ThumbList::FindThumbByContact(MCONTACT hContact) { if (!hContact) return nullptr; - for (int i = 0; i < getCount(); ++i) - if (items[i]->hContact == hContact) - return items[i]; + for (auto &it : *this) + if (it->hContact == hContact) + return it; return nullptr; } diff --git a/plugins/Folders/src/dlg_handlers.cpp b/plugins/Folders/src/dlg_handlers.cpp index 806b0972c7..1135235741 100644 --- a/plugins/Folders/src/dlg_handlers.cpp +++ b/plugins/Folders/src/dlg_handlers.cpp @@ -35,12 +35,11 @@ static void LoadRegisteredFolderSections(HWND hWnd) { HWND hwndList = GetDlgItem(hWnd, IDC_FOLDERS_SECTIONS_LIST); - for (int i = 0; i < lstRegisteredFolders.getCount(); i++) { - CFolderItem &tmp = lstRegisteredFolders[i]; - wchar_t *translated = mir_a2u(tmp.GetSection()); + for (auto &it : lstRegisteredFolders) { + wchar_t *translated = mir_a2u(it->GetSection()); if (!ContainsSection(hWnd, TranslateW(translated))) { int idx = SendMessage(hwndList, LB_ADDSTRING, 0, (LPARAM)TranslateW(translated)); - SendMessage(hwndList, LB_SETITEMDATA, idx, (LPARAM)tmp.GetSection()); + SendMessage(hwndList, LB_SETITEMDATA, idx, (LPARAM)it->GetSection()); } mir_free(translated); @@ -58,11 +57,10 @@ static void LoadRegisteredFolderItems(HWND hWnd) HWND hwndItems = GetDlgItem(hWnd, IDC_FOLDERS_ITEMS_LIST); SendMessage(hwndItems, LB_RESETCONTENT, 0, 0); - for (int i = 0; i < lstRegisteredFolders.getCount(); i++) { - CFolderItem &item = lstRegisteredFolders[i]; - if (!mir_strcmp(szSection, item.GetSection())) { - idx = SendMessage(hwndItems, LB_ADDSTRING, 0, (LPARAM)TranslateW(item.GetUserName())); - SendMessage(hwndItems, LB_SETITEMDATA, idx, (LPARAM)&item); + for (auto &it : lstRegisteredFolders) { + if (!mir_strcmp(szSection, it->GetSection())) { + idx = SendMessage(hwndItems, LB_ADDSTRING, 0, (LPARAM)TranslateW(it->GetUserName())); + SendMessage(hwndItems, LB_SETITEMDATA, idx, (LPARAM)it); } } SendMessage(hwndItems, LB_SETCURSEL, 0, 0); //select the first item @@ -234,8 +232,8 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l LoadItem(hWnd, item); } - for (int i = 0; i < lstRegisteredFolders.getCount(); i++) - lstRegisteredFolders[i].Save(); + for (auto &it : lstRegisteredFolders) + it->Save(); CallPathChangedEvents(); } } diff --git a/plugins/GmailNotifier/src/check.cpp b/plugins/GmailNotifier/src/check.cpp index 0d642a8a42..88cafca600 100644 --- a/plugins/GmailNotifier/src/check.cpp +++ b/plugins/GmailNotifier/src/check.cpp @@ -141,11 +141,10 @@ void __cdecl Check_ThreadFunc(void *lpParam) NotifyUser((Account *)lpParam); } else { - for (int i = 0; i < g_accs.getCount(); i++) { - Account &acc = g_accs[i]; - if (GetContactProto(acc.hContact)) { - CheckMailInbox(&acc); - NotifyUser(&acc); + for (auto &it : g_accs) { + if (GetContactProto(it->hContact)) { + CheckMailInbox(it); + NotifyUser(it); } } } diff --git a/plugins/GmailNotifier/src/main.cpp b/plugins/GmailNotifier/src/main.cpp index 3fc69d130d..3a715ca048 100644 --- a/plugins/GmailNotifier/src/main.cpp +++ b/plugins/GmailNotifier/src/main.cpp @@ -133,8 +133,8 @@ extern "C" int __declspec(dllexport) Load() BuildList(); ID_STATUS_NONEW = opt.UseOnline ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE; - for (int i = 0; i < g_accs.getCount(); i++) - db_set_dw(g_accs[i].hContact, MODULE_NAME, "Status", ID_STATUS_NONEW); + for (auto &it : g_accs) + db_set_dw(it->hContact, MODULE_NAME, "Status", ID_STATUS_NONEW); hTimer = SetTimer(nullptr, 0, opt.circleTime * 60000, TimerProc); hMirandaStarted = HookEvent(ME_SYSTEM_MODULESLOADED, OnMirandaStart); @@ -162,8 +162,8 @@ extern "C" int __declspec(dllexport) Unload(void) if (hTimer) KillTimer(nullptr, hTimer); - for (int i = 0; i < g_accs.getCount(); i++) - DeleteResults(g_accs[i].results.next); + for (auto &it : g_accs) + DeleteResults(it->results.next); g_accs.destroy(); Netlib_CloseHandle(hNetlibUser); diff --git a/plugins/GmailNotifier/src/options.cpp b/plugins/GmailNotifier/src/options.cpp index a3f781c8b1..cc2bd0ffa9 100644 --- a/plugins/GmailNotifier/src/options.cpp +++ b/plugins/GmailNotifier/src/options.cpp @@ -46,8 +46,8 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA optionWindowIsOpen = TRUE; BuildList(); - for (int i = 0; i < g_accs.getCount(); i++) - SendMessageA(hwndCombo, CB_ADDSTRING, 0, (LONG_PTR)g_accs[i].name); + for (auto &it : g_accs) + SendMessageA(hwndCombo, CB_ADDSTRING, 0, (LONG_PTR)it->name); SendMessage(hwndCombo, CB_SETCURSEL, curIndex, 0); if (curIndex < g_accs.getCount()) SetDlgItemTextA(hwndDlg, IDC_PASS, g_accs[curIndex].pass); @@ -256,8 +256,8 @@ static INT_PTR CALLBACK DlgProcOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA db_set_dw(NULL, MODULE_NAME, "LogThreads", opt.LogThreads); ID_STATUS_NONEW = opt.UseOnline ? ID_STATUS_ONLINE : ID_STATUS_OFFLINE; - for (int i = 0; i < g_accs.getCount(); i++) - db_set_w(g_accs[i].hContact, MODULE_NAME, "Status", ID_STATUS_NONEW); + for (auto &it : g_accs) + db_set_w(it->hContact, MODULE_NAME, "Status", ID_STATUS_NONEW); } return TRUE; diff --git a/plugins/GmailNotifier/src/utility.cpp b/plugins/GmailNotifier/src/utility.cpp index cadc6820db..840ff28a3c 100644 --- a/plugins/GmailNotifier/src/utility.cpp +++ b/plugins/GmailNotifier/src/utility.cpp @@ -19,12 +19,11 @@ void BuildList(void) } } - for (int i = 0; i < g_accs.getCount(); i++) { - Account &acc = g_accs[i]; - char *tail = strchr(acc.name, '@'); + for (auto &acc : g_accs) { + char *tail = strchr(acc->name, '@'); if (tail && mir_strcmp(tail + 1, "gmail.com") != 0) - mir_strcpy(acc.hosted, tail + 1); - acc.IsChecking = false; + mir_strcpy(acc->hosted, tail + 1); + acc->IsChecking = false; } } @@ -70,9 +69,9 @@ BOOL GetBrowser(char *str) Account* GetAccountByContact(MCONTACT hContact) { - for (int i = 0; i < g_accs.getCount(); i++) - if (g_accs[i].hContact == hContact) - return &g_accs[i]; + for (auto &it : g_accs) + if (it->hContact == hContact) + return it; return nullptr; } diff --git a/plugins/HistorySweeperLight/src/options.cpp b/plugins/HistorySweeperLight/src/options.cpp index 7d8071eb63..60da041125 100644 --- a/plugins/HistorySweeperLight/src/options.cpp +++ b/plugins/HistorySweeperLight/src/options.cpp @@ -160,8 +160,8 @@ void SaveSettings(HWND hwndDlg) db_unset(hContact, ModuleName, "SweepHistory"); } - for (int i = 0; i < g_hWindows.getCount(); i++) - SetSrmmIcon(UINT_PTR(g_hWindows[i])); + for (auto &it : g_hWindows) + SetSrmmIcon(UINT_PTR(it)); // set tooltips int st = db_get_b(NULL, ModuleName, "SweepHistory", 0); diff --git a/plugins/Import/src/import.cpp b/plugins/Import/src/import.cpp index 249c998afe..590bce6a5a 100644 --- a/plugins/Import/src/import.cpp +++ b/plugins/Import/src/import.cpp @@ -352,12 +352,11 @@ static char* newStr(const char *s) static bool FindDestAccount(const char *szProto) { - for (int i = 0; i < arAccountMap.getCount(); i++) { - AccountMap &pam = arAccountMap[i]; - if (pam.pa == nullptr) + for (auto &pam : arAccountMap) { + if (pam->pa == nullptr) continue; - if (!mir_strcmp(pam.pa->szModuleName, szProto)) + if (!mir_strcmp(pam->pa->szModuleName, szProto)) return true; } @@ -458,49 +457,48 @@ bool ImportAccounts(OBJLIST &arSkippedModules) bool bImportSysAll = (nImportOptions & IOPT_SYS_SETTINGS) != 0; - for (int i = 0; i < arAccountMap.getCount(); i++) { - AccountMap &p = arAccountMap[i]; - if (p.pa != nullptr || p.szBaseProto == NULL || !mir_strcmp(p.szSrcAcc, META_PROTO)) + for (auto &p : arAccountMap) { + if (p->pa != nullptr || p->szBaseProto == NULL || !mir_strcmp(p->szSrcAcc, META_PROTO)) continue; - if (!Proto_IsProtocolLoaded(p.szBaseProto)) { - AddMessage(LPGENW("Protocol %S is not loaded, skipping account %s creation"), p.szBaseProto, p.tszSrcName); + if (!Proto_IsProtocolLoaded(p->szBaseProto)) { + AddMessage(LPGENW("Protocol %S is not loaded, skipping account %s creation"), p->szBaseProto, p->tszSrcName); continue; } ACC_CREATE newacc; - newacc.pszBaseProto = p.szBaseProto; + newacc.pszBaseProto = p->szBaseProto; newacc.pszInternal = nullptr; - newacc.ptszAccountName = p.tszSrcName; + newacc.ptszAccountName = p->tszSrcName; - p.pa = ProtoCreateAccount(&newacc); - if (p.pa == nullptr) { - AddMessage(LPGENW("Unable to create an account %s of protocol %S"), p.tszSrcName, p.szBaseProto); + p->pa = ProtoCreateAccount(&newacc); + if (p->pa == nullptr) { + AddMessage(LPGENW("Unable to create an account %s of protocol %S"), p->tszSrcName, p->szBaseProto); return false; } char szSetting[100]; - itoa(400 + p.iSrcIndex, szSetting, 10); + itoa(400 + p->iSrcIndex, szSetting, 10); int iVal = myGetD(NULL, "Protocols", szSetting, 1); - itoa(400 + p.pa->iOrder, szSetting, 10); + itoa(400 + p->pa->iOrder, szSetting, 10); db_set_dw(NULL, "Protocols", szSetting, iVal); - p.pa->bIsVisible = iVal != 0; + p->pa->bIsVisible = iVal != 0; - itoa(600 + p.iSrcIndex, szSetting, 10); + itoa(600 + p->iSrcIndex, szSetting, 10); iVal = myGetD(NULL, "Protocols", szSetting, 1); - itoa(600 + p.pa->iOrder, szSetting, 10); + itoa(600 + p->pa->iOrder, szSetting, 10); db_set_dw(NULL, "Protocols", szSetting, iVal); - p.pa->bIsEnabled = iVal != 0; + p->pa->bIsEnabled = iVal != 0; - if (p.tszSrcName == NULL) { - p.pa->tszAccountName = mir_a2u(p.pa->szModuleName); - itoa(800 + p.pa->iOrder, szSetting, 10); - db_set_ws(NULL, "Protocols", szSetting, p.pa->tszAccountName); + if (p->tszSrcName == NULL) { + p->pa->tszAccountName = mir_a2u(p->pa->szModuleName); + itoa(800 + p->pa->iOrder, szSetting, 10); + db_set_ws(NULL, "Protocols", szSetting, p->pa->tszAccountName); } - CopySettings(NULL, p.szSrcAcc, NULL, p.pa->szModuleName); + CopySettings(NULL, p->szSrcAcc, NULL, p->pa->szModuleName); if (bImportSysAll) - arSkippedModules.insert(newStr(p.szSrcAcc)); + arSkippedModules.insert(newStr(p->szSrcAcc)); } CopySettings(NULL, META_PROTO, NULL, META_PROTO); @@ -1053,8 +1051,8 @@ void MirandaImport(HWND hdlg) hContact = srcDb->FindNextContact(hContact); } - for (i = 0; i < arMetas.getCount(); i++) - ImportMeta(arMetas[i]); + for (auto &it : arMetas) + ImportMeta(it); } else AddMessage(LPGENW("Skipping new contacts import.")); AddMessage(L""); diff --git a/plugins/MirLua/src/mlua_metatable.h b/plugins/MirLua/src/mlua_metatable.h index 6b4f916668..7fb8c27578 100644 --- a/plugins/MirLua/src/mlua_metatable.h +++ b/plugins/MirLua/src/mlua_metatable.h @@ -217,14 +217,12 @@ private: CMStringA data(MT::name); data += "("; - for (int i = 0; i < fields.getCount(); i++) { - CMTField &field = fields[i]; - - data += field.GetName(); + for (auto &it : fields) { + data += it->GetName(); data += "="; - MTValue value = field.GetValue(obj); - int type = field.GetType(); + MTValue value = it->GetValue(obj); + int type = it->GetType(); switch (type) { case LUA_TNIL: data.Append("nil"); diff --git a/plugins/MirLua/src/mlua_options.cpp b/plugins/MirLua/src/mlua_options.cpp index 6a2dbd669b..9a4438d408 100644 --- a/plugins/MirLua/src/mlua_options.cpp +++ b/plugins/MirLua/src/mlua_options.cpp @@ -34,12 +34,11 @@ CMLuaOptions::CMLuaOptions(int idDialog) void CMLuaOptions::LoadScripts() { - for (int i = 0; i < g_mLua->Scripts.getCount(); i++) + for (auto &it : g_mLua->Scripts) { - CMLuaScript *script = g_mLua->Scripts[i]; - wchar_t *fileName = NEWWSTR_ALLOCA(script->GetFileName()); - int iIcon = script->GetStatus() - 1; - int iItem = m_scripts.AddItem(fileName, iIcon, (LPARAM)script); + wchar_t *fileName = NEWWSTR_ALLOCA(it->GetFileName()); + int iIcon = it->GetStatus() - 1; + int iItem = m_scripts.AddItem(fileName, iIcon, (LPARAM)it); if (db_get_b(NULL, MODULE, _T2A(fileName), 1)) m_scripts.SetCheckState(iItem, TRUE); m_scripts.SetItem(iItem, 1, TranslateT("Open"), 2); diff --git a/plugins/NewXstatusNotify/src/options.cpp b/plugins/NewXstatusNotify/src/options.cpp index 82705d78b0..2b3231a74b 100644 --- a/plugins/NewXstatusNotify/src/options.cpp +++ b/plugins/NewXstatusNotify/src/options.cpp @@ -132,13 +132,12 @@ void SaveTemplates() db_set_b(0, MODULE, "TLogXFlags", templates.LogXFlags); db_set_b(0, MODULE, "TLogSMsgFlags", templates.LogSMsgFlags); - for (int i = 0; i < ProtoTemplates.getCount(); i++) { - PROTOTEMPLATE *prototemplate = ProtoTemplates[i]; + for (auto &it : ProtoTemplates) { char str[MAX_PATH]; - mir_snprintf(str, "%s_TPopupSMsgChanged", prototemplate->ProtoName); - db_set_ws(0, MODULE, str, prototemplate->ProtoTemplateMsg); - mir_snprintf(str, "%s_TPopupSMsgRemoved", prototemplate->ProtoName); - db_set_ws(0, MODULE, str, prototemplate->ProtoTemplateRemoved); + mir_snprintf(str, "%s_TPopupSMsgChanged", it->ProtoName); + db_set_ws(0, MODULE, str, it->ProtoTemplateMsg); + mir_snprintf(str, "%s_TPopupSMsgRemoved", it->ProtoName); + db_set_ws(0, MODULE, str, it->ProtoTemplateRemoved); } } diff --git a/plugins/Nudge/src/main.cpp b/plugins/Nudge/src/main.cpp index 0524554f05..fc2b9b6fd1 100644 --- a/plugins/Nudge/src/main.cpp +++ b/plugins/Nudge/src/main.cpp @@ -32,13 +32,11 @@ PLUGININFOEX pluginInfo = { INT_PTR NudgeShowMenu(WPARAM wParam, LPARAM lParam) { bool bEnabled = false; - for (int i = 0; i < arNudges.getCount(); i++) { - CNudgeElement &p = arNudges[i]; - if (!mir_strcmp((char*)wParam, p.ProtocolName)) { - bEnabled = (GlobalNudge.useByProtocol) ? p.enabled : DefaultNudge.enabled; + for (auto &p : arNudges) + if (!mir_strcmp((char*)wParam, p->ProtocolName)) { + bEnabled = (GlobalNudge.useByProtocol) ? p->enabled : DefaultNudge.enabled; break; } - } Menu_ShowItem(g_hContactMenu, bEnabled && lParam != 0); return 0; @@ -52,11 +50,9 @@ INT_PTR NudgeSend(WPARAM hContact, LPARAM lParam) wchar_t msg[500]; mir_snwprintf(msg, TranslateT("You are not allowed to send too much nudge (only 1 each %d sec, %d sec left)"), GlobalNudge.sendTimeSec, 30 - diff); if (GlobalNudge.useByProtocol) { - for (int i = 0; i < arNudges.getCount(); i++) { - CNudgeElement &p = arNudges[i]; - if (!mir_strcmp(protoName, p.ProtocolName)) - Nudge_ShowPopup(&p, hContact, msg); - } + for (auto &p : arNudges) + if (!mir_strcmp(protoName, p->ProtocolName)) + Nudge_ShowPopup(p, hContact, msg); } else Nudge_ShowPopup(&DefaultNudge, hContact, msg); @@ -66,12 +62,10 @@ INT_PTR NudgeSend(WPARAM hContact, LPARAM lParam) db_set_dw(hContact, "Nudge", "LastSent", time(nullptr)); if (GlobalNudge.useByProtocol) { - for (int i = 0; i < arNudges.getCount(); i++) { - CNudgeElement &p = arNudges[i]; - if (!mir_strcmp(protoName, p.ProtocolName)) - if (p.showStatus) - Nudge_SentStatus(&p, hContact); - } + for (auto &p : arNudges) + if (!mir_strcmp(protoName, p->ProtocolName)) + if (p->showStatus) + Nudge_SentStatus(p, hContact); } else if (DefaultNudge.showStatus) Nudge_SentStatus(&DefaultNudge, hContact); @@ -103,48 +97,47 @@ int NudgeReceived(WPARAM hContact, LPARAM lParam) db_set_dw(hContact, "Nudge", "LastReceived2", nudgeSentTimestamp); if (GlobalNudge.useByProtocol) { - for (int i = 0; i < arNudges.getCount(); i++) { - CNudgeElement &p = arNudges[i]; - if (!mir_strcmp(protoName, p.ProtocolName)) { + for (auto &p : arNudges) { + if (!mir_strcmp(protoName, p->ProtocolName)) { - if (p.enabled) { - if (p.useIgnoreSettings && CallService(MS_IGNORE_ISIGNORED, hContact, IGNOREEVENT_USERONLINE)) + if (p->enabled) { + if (p->useIgnoreSettings && CallService(MS_IGNORE_ISIGNORED, hContact, IGNOREEVENT_USERONLINE)) return 0; DWORD Status = CallProtoService(protoName, PS_GETSTATUS, 0, 0); - if (((p.statusFlags & NUDGE_ACC_ST0) && (Status <= ID_STATUS_OFFLINE)) || - ((p.statusFlags & NUDGE_ACC_ST1) && (Status == ID_STATUS_ONLINE)) || - ((p.statusFlags & NUDGE_ACC_ST2) && (Status == ID_STATUS_AWAY)) || - ((p.statusFlags & NUDGE_ACC_ST3) && (Status == ID_STATUS_DND)) || - ((p.statusFlags & NUDGE_ACC_ST4) && (Status == ID_STATUS_NA)) || - ((p.statusFlags & NUDGE_ACC_ST5) && (Status == ID_STATUS_OCCUPIED)) || - ((p.statusFlags & NUDGE_ACC_ST6) && (Status == ID_STATUS_FREECHAT)) || - ((p.statusFlags & NUDGE_ACC_ST7) && (Status == ID_STATUS_INVISIBLE)) || - ((p.statusFlags & NUDGE_ACC_ST8) && (Status == ID_STATUS_ONTHEPHONE)) || - ((p.statusFlags & NUDGE_ACC_ST9) && (Status == ID_STATUS_OUTTOLUNCH))) + if (((p->statusFlags & NUDGE_ACC_ST0) && (Status <= ID_STATUS_OFFLINE)) || + ((p->statusFlags & NUDGE_ACC_ST1) && (Status == ID_STATUS_ONLINE)) || + ((p->statusFlags & NUDGE_ACC_ST2) && (Status == ID_STATUS_AWAY)) || + ((p->statusFlags & NUDGE_ACC_ST3) && (Status == ID_STATUS_DND)) || + ((p->statusFlags & NUDGE_ACC_ST4) && (Status == ID_STATUS_NA)) || + ((p->statusFlags & NUDGE_ACC_ST5) && (Status == ID_STATUS_OCCUPIED)) || + ((p->statusFlags & NUDGE_ACC_ST6) && (Status == ID_STATUS_FREECHAT)) || + ((p->statusFlags & NUDGE_ACC_ST7) && (Status == ID_STATUS_INVISIBLE)) || + ((p->statusFlags & NUDGE_ACC_ST8) && (Status == ID_STATUS_ONTHEPHONE)) || + ((p->statusFlags & NUDGE_ACC_ST9) && (Status == ID_STATUS_OUTTOLUNCH))) { if (diff >= GlobalNudge.recvTimeSec) { - if (p.showPopup) - Nudge_ShowPopup(&p, hContact, p.recText); - if (p.openContactList) + if (p->showPopup) + Nudge_ShowPopup(p, hContact, p->recText); + if (p->openContactList) OpenContactList(); - if (p.shakeClist) + if (p->shakeClist) ShakeClist(hContact, lParam); - if (p.openMessageWindow) + if (p->openMessageWindow) CallService(MS_MSG_SENDMESSAGEW, hContact, 0); - if (p.shakeChat) + if (p->shakeChat) ShakeChat(hContact, lParam); - if (p.autoResend) + if (p->autoResend) mir_forkthread(AutoResendNudge, (void*)hContact); - Skin_PlaySound(p.NudgeSoundname); + Skin_PlaySound(p->NudgeSoundname); } } if (diff2 >= GlobalNudge.recvTimeSec) - if (p.showStatus) - Nudge_ShowStatus(&p, hContact, nudgeSentTimestamp); + if (p->showStatus) + Nudge_ShowStatus(p, hContact, nudgeSentTimestamp); } break; } @@ -407,19 +400,18 @@ int Preview() { MCONTACT hContact = db_find_first(); if (GlobalNudge.useByProtocol) { - for (int i = 0; i < arNudges.getCount(); i++) { - CNudgeElement &p = arNudges[i]; - if (p.enabled) { - Skin_PlaySound(p.NudgeSoundname); - if (p.showPopup) - Nudge_ShowPopup(&p, hContact, p.recText); - if (p.openContactList) + for (auto &p : arNudges) { + if (p->enabled) { + Skin_PlaySound(p->NudgeSoundname); + if (p->showPopup) + Nudge_ShowPopup(p, hContact, p->recText); + if (p->openContactList) OpenContactList(); - if (p.shakeClist) + if (p->shakeClist) ShakeClist(0, 0); - if (p.openMessageWindow) + if (p->openMessageWindow) CallService(MS_MSG_SENDMESSAGEW, hContact, NULL); - if (p.shakeChat) + if (p->shakeChat) ShakeChat(hContact, (LPARAM)time(nullptr)); } } diff --git a/plugins/Nudge/src/options.cpp b/plugins/Nudge/src/options.cpp index fce6159268..c72e07390c 100644 --- a/plugins/Nudge/src/options.cpp +++ b/plugins/Nudge/src/options.cpp @@ -21,11 +21,9 @@ static void UpdateControls(HWND hwnd) if (GlobalNudge.useByProtocol) { proto = GetSelProto(hwnd, nullptr); ActualNudge = nullptr; - for (int i = 0; i < arNudges.getCount(); i++) { - CNudgeElement &p = arNudges[i]; - if (p.iProtoNumber == proto) - ActualNudge = &p; - } + for (auto &p : arNudges) + if (p->iProtoNumber == proto) + ActualNudge = p; } else ActualNudge = &DefaultNudge; @@ -71,11 +69,9 @@ static void CheckChange(HWND hwnd, HTREEITEM hItem) if (GlobalNudge.useByProtocol) { proto = GetSelProto(hwnd, hItem); ActualNudge = nullptr; - for (int i = 0; i < arNudges.getCount(); i++) { - CNudgeElement &p = arNudges[i]; - if (p.iProtoNumber == proto) - ActualNudge = &p; - } + for (auto &p : arNudges) + if (p->iProtoNumber == proto) + ActualNudge = p; } else ActualNudge = &DefaultNudge; @@ -208,9 +204,8 @@ static void CreateImageList(HWND hWnd) // Create and populate image list HIMAGELIST hImList = ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_MASK | ILC_COLOR32, nProtocol, 0); - for (int i = 0; i < arNudges.getCount(); i++) { - CNudgeElement &p = arNudges[i]; - INT_PTR res = CallProtoService(p.ProtocolName, PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL | PLIF_ICOLIB, 0); + for (auto &p : arNudges) { + INT_PTR res = CallProtoService(p->ProtocolName, PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL | PLIF_ICOLIB, 0); if (res == CALLSERVICE_NOTFOUND) res = (INT_PTR)IcoLib_GetIcon("Nudge_Default"); diff --git a/plugins/PluginUpdater/src/DlgListNew.cpp b/plugins/PluginUpdater/src/DlgListNew.cpp index 12c4853002..fa521bbcfc 100644 --- a/plugins/PluginUpdater/src/DlgListNew.cpp +++ b/plugins/PluginUpdater/src/DlgListNew.cpp @@ -27,7 +27,7 @@ static void SelectAll(HWND hDlg, bool bEnable) OBJLIST &todo = *(OBJLIST *)GetWindowLongPtr(hDlg, GWLP_USERDATA); HWND hwndList = GetDlgItem(hDlg, IDC_LIST_UPDATES); - for (int i=0; i < todo.getCount(); i++) { + for (int i = 0; i < todo.getCount(); i++) { ListView_SetCheckState(hwndList, i, todo[i].bEnabled = bEnable); } } @@ -64,17 +64,18 @@ static void ApplyDownloads(void *param) VARSW tszMirandaPath(L"%miranda_path%"); HNETLIBCONN nlc = nullptr; - for (int i=0; i < todo.getCount(); ++i) { + for (int i = 0; i < todo.getCount(); ++i) { + auto &p = todo[i]; ListView_EnsureVisible(hwndList, i, FALSE); - if (todo[i].bEnabled) { + if (p.bEnabled) { // download update ListView_SetItemText(hwndList, i, 1, TranslateT("Downloading...")); - if (DownloadFile(&todo[i].File, nlc)) { + if (DownloadFile(&p.File, nlc)) { ListView_SetItemText(hwndList, i, 1, TranslateT("Succeeded.")); - if (unzip(todo[i].File.tszDiskPath, tszMirandaPath, tszFileBack,false)) - SafeDeleteFile(todo[i].File.tszDiskPath); // remove .zip after successful update - db_unset(NULL, DB_MODULE_NEW_FILES, _T2A(todo[i].tszOldName)); + if (unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack, false)) + SafeDeleteFile(p.File.tszDiskPath); // remove .zip after successful update + db_unset(NULL, DB_MODULE_NEW_FILES, _T2A(p.tszOldName)); } else ListView_SetItemText(hwndList, i, 1, TranslateT("Failed!")); @@ -104,7 +105,7 @@ static LRESULT CALLBACK PluginListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LP hi.pt.x = LOWORD(lParam); hi.pt.y = HIWORD(lParam); ListView_SubItemHitTest(hwnd, &hi); if ((hi.iSubItem == 0) && (hi.flags & LVHT_ONITEMICON)) { - LVITEM lvi = {0}; + LVITEM lvi = { 0 }; lvi.mask = LVIF_IMAGE | LVIF_PARAM | LVIF_GROUPID; lvi.stateMask = -1; lvi.iItem = hi.iItem; @@ -152,9 +153,9 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) switch (message) { case WM_INITDIALOG: - TranslateDialogDefault( hDlg ); + TranslateDialogDefault(hDlg); oldWndProc = (WNDPROC)SetWindowLongPtr(hwndList, GWLP_WNDPROC, (LONG_PTR)PluginListWndProc); - + Window_SetIcon_IcoLib(hDlg, iconList[2].hIcolib); { HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0); @@ -182,7 +183,7 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) GetClientRect(hwndList, &r); /// - LVCOLUMN lvc = {0}; + LVCOLUMN lvc = { 0 }; lvc.mask = LVCF_WIDTH | LVCF_TEXT; //lvc.fmt = LVCFMT_LEFT; @@ -206,7 +207,7 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) lvg.pszHeader = TranslateT("Icons"); lvg.iGroupId = 2; ListView_InsertGroup(hwndList, 0, &lvg); - + lvg.pszHeader = TranslateT("Languages"); lvg.iGroupId = 3; ListView_InsertGroup(hwndList, 0, &lvg); @@ -224,23 +225,24 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) /// bool enableOk = false; OBJLIST &todo = *(OBJLIST *)lParam; - for (int i = 0; i < todo.getCount(); ++i) { - LVITEM lvi = {0}; + for (int i = 0; i < todo.getCount(); i++) { + auto &p = todo[i]; + + LVITEM lvi = { 0 }; lvi.mask = LVIF_PARAM | LVIF_GROUPID | LVIF_TEXT | LVIF_IMAGE; - + int groupId = 4; - if (wcschr(todo[i].tszOldName, L'\\') != nullptr) - groupId = (wcsstr(todo[i].tszOldName, L"Plugins") != nullptr) ? 1 : ((wcsstr(todo[i].tszOldName, L"Languages") != nullptr) ? 3 : 2); + if (wcschr(p.tszOldName, L'\\') != nullptr) + groupId = (wcsstr(p.tszOldName, L"Plugins") != nullptr) ? 1 : ((wcsstr(p.tszOldName, L"Languages") != nullptr) ? 3 : 2); lvi.iItem = i; lvi.lParam = (LPARAM)&todo[i]; lvi.iGroupId = groupId; - lvi.iImage = ((groupId ==1) ? 0 : -1); - lvi.pszText = todo[i].tszOldName; + lvi.iImage = ((groupId == 1) ? 0 : -1); + lvi.pszText = p.tszOldName; ListView_InsertItem(hwndList, &lvi); - if (todo[i].bEnabled) - { + if (p.bEnabled) { enableOk = true; ListView_SetCheckState(hwndList, lvi.iItem, 1); } @@ -255,13 +257,13 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) return TRUE; case WM_NOTIFY: - if (((LPNMHDR) lParam)->hwndFrom == hwndList) { - switch (((LPNMHDR) lParam)->code) { + if (((LPNMHDR)lParam)->hwndFrom == hwndList) { + switch (((LPNMHDR)lParam)->code) { case LVN_ITEMCHANGED: if (GetWindowLongPtr(hDlg, GWLP_USERDATA)) { NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam; if ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK) { - LVITEM lvI = {0}; + LVITEM lvI = { 0 }; lvI.iItem = nmlv->iItem; lvI.iSubItem = 0; lvI.mask = LVIF_PARAM; @@ -272,8 +274,8 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) p->bEnabled = ListView_GetCheckState(hwndList, nmlv->iItem); bool enableOk = false; - for (int i=0; i < todo.getCount(); ++i) { - if (todo[i].bEnabled) { + for (int i = 0; i < todo.getCount(); ++i) { + if (p->bEnabled) { enableOk = true; break; } @@ -287,11 +289,11 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) break; case WM_COMMAND: - if (HIWORD( wParam ) == BN_CLICKED) { - switch(LOWORD(wParam)) { + if (HIWORD(wParam) == BN_CLICKED) { + switch (LOWORD(wParam)) { case IDOK: - EnableWindow( GetDlgItem(hDlg, IDOK), FALSE); - EnableWindow( GetDlgItem(hDlg, IDC_SELNONE), FALSE); + EnableWindow(GetDlgItem(hDlg, IDOK), FALSE); + EnableWindow(GetDlgItem(hDlg, IDC_SELNONE), FALSE); mir_forkthread(ApplyDownloads, hDlg); return TRUE; @@ -312,7 +314,7 @@ INT_PTR CALLBACK DlgList(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) Utils_ResizeDialog(hDlg, hInst, MAKEINTRESOURCEA(IDD_LIST), ListDlg_Resize); break; - case WM_GETMINMAXINFO: + case WM_GETMINMAXINFO: { LPMINMAXINFO mmi = (LPMINMAXINFO)lParam; @@ -382,10 +384,10 @@ static void GetList(void *) wchar_t tszTempPath[MAX_PATH]; DWORD dwLen = GetTempPath(_countof(tszTempPath), tszTempPath); - if (tszTempPath[dwLen-1] == '\\') - tszTempPath[dwLen-1] = 0; + if (tszTempPath[dwLen - 1] == '\\') + tszTempPath[dwLen - 1] = 0; - ptrW updateUrl( GetDefaultUrl()), baseUrl; + ptrW updateUrl(GetDefaultUrl()), baseUrl; SERVLIST hashes(50, CompareHashes); if (!ParseHashes(updateUrl, baseUrl, hashes)) { hListThread = nullptr; @@ -395,7 +397,7 @@ static void GetList(void *) FILELIST *UpdateFiles = new FILELIST(20); VARSW dirname(L"%miranda_path%"); - for (int i=0; i < hashes.getCount(); i++) { + for (int i = 0; i < hashes.getCount(); i++) { ServListEntry &hash = hashes[i]; wchar_t tszPath[MAX_PATH]; @@ -436,7 +438,7 @@ void UninitListNew() DestroyWindow(hwndDialog); } -static INT_PTR ShowListCommand(WPARAM,LPARAM) +static INT_PTR ShowListCommand(WPARAM, LPARAM) { DoGetList(); return 0; diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index 1c32790add..c7c792cde7 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -97,27 +97,26 @@ static void ApplyUpdates(void *param) // 3) Unpack all zips VARSW tszMirandaPath(L"%miranda_path%"); - for (int i = 0; i < todo.getCount(); i++) { - FILEINFO& p = todo[i]; - if (p.bEnabled) { - if (p.bDeleteOnly) { + for (auto &it : todo) { + if (it->bEnabled) { + if (it->bDeleteOnly) { // we need only to backup the old file - wchar_t *ptszRelPath = p.tszNewName + wcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH]; + wchar_t *ptszRelPath = it->tszNewName + wcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH]; mir_snwprintf(tszBackFile, L"%s\\%s", tszFileBack, ptszRelPath); - BackupFile(p.tszNewName, tszBackFile); + BackupFile(it->tszNewName, tszBackFile); } else { // if file name differs, we also need to backup the old file here // otherwise it would be replaced by unzip - if (_wcsicmp(p.tszOldName, p.tszNewName)) { + if (_wcsicmp(it->tszOldName, it->tszNewName)) { wchar_t tszSrcPath[MAX_PATH], tszBackFile[MAX_PATH]; - mir_snwprintf(tszSrcPath, L"%s\\%s", tszMirandaPath, p.tszOldName); - mir_snwprintf(tszBackFile, L"%s\\%s", tszFileBack, p.tszOldName); + mir_snwprintf(tszSrcPath, L"%s\\%s", tszMirandaPath, it->tszOldName); + mir_snwprintf(tszBackFile, L"%s\\%s", tszFileBack, it->tszOldName); BackupFile(tszSrcPath, tszBackFile); } - if ( unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack,true)) - SafeDeleteFile(p.File.tszDiskPath); // remove .zip after successful update + if ( unzip(it->File.tszDiskPath, tszMirandaPath, tszFileBack,true)) + SafeDeleteFile(it->File.tszDiskPath); // remove .zip after successful update } } } @@ -449,28 +448,27 @@ static void DlgUpdateSilent(void *param) // 3) Unpack all zips VARSW tszMirandaPath(L"%miranda_path%"); - for (int i = 0; i < UpdateFiles.getCount(); i++) { - FILEINFO& p = UpdateFiles[i]; - if (p.bEnabled) { - if (p.bDeleteOnly) { + for (auto &it : UpdateFiles) { + if (it->bEnabled) { + if (it->bDeleteOnly) { // we need only to backup the old file - wchar_t *ptszRelPath = p.tszNewName + wcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH]; + wchar_t *ptszRelPath = it->tszNewName + wcslen(tszMirandaPath) + 1, tszBackFile[MAX_PATH]; mir_snwprintf(tszBackFile, L"%s\\%s", tszFileBack, ptszRelPath); - BackupFile(p.tszNewName, tszBackFile); + BackupFile(it->tszNewName, tszBackFile); } else { // if file name differs, we also need to backup the old file here // otherwise it would be replaced by unzip - if (_wcsicmp(p.tszOldName, p.tszNewName)) { + if (_wcsicmp(it->tszOldName, it->tszNewName)) { wchar_t tszSrcPath[MAX_PATH], tszBackFile[MAX_PATH]; - mir_snwprintf(tszSrcPath, L"%s\\%s", tszMirandaPath, p.tszOldName); - mir_snwprintf(tszBackFile, L"%s\\%s", tszFileBack, p.tszOldName); + mir_snwprintf(tszSrcPath, L"%s\\%s", tszMirandaPath, it->tszOldName); + mir_snwprintf(tszBackFile, L"%s\\%s", tszFileBack, it->tszOldName); BackupFile(tszSrcPath, tszBackFile); } // remove .zip after successful update - if (unzip(p.File.tszDiskPath, tszMirandaPath, tszFileBack, true)) - SafeDeleteFile(p.File.tszDiskPath); + if (unzip(it->File.tszDiskPath, tszMirandaPath, tszFileBack, true)) + SafeDeleteFile(it->File.tszDiskPath); } } } @@ -532,9 +530,9 @@ struct } static renameTable[] = { - { L"svc_dbepp.dll", L"Plugins\\dbeditorpp.dll" }, - { L"svc_crshdmp.dll", L"Plugins\\crashdumper.dll" }, - { L"crashdmp.dll", L"Plugins\\crashdumper.dll" }, + { L"svc_dbepit->dll", L"Plugins\\dbeditorpit->dll" }, + { L"svc_crshdmit->dll", L"Plugins\\crashdumper.dll" }, + { L"crashdmit->dll", L"Plugins\\crashdumper.dll" }, { L"crashrpt.dll", L"Plugins\\crashdumper.dll" }, { L"attache.dll", L"Plugins\\crashdumper.dll" }, { L"svc_vi.dll", L"Plugins\\crashdumper.dll" }, @@ -551,7 +549,7 @@ static renameTable[] = { L"ttnotify.dll", L"Plugins\\tooltipnotify.dll" }, { L"newstatusnotify.dll", L"Plugins\\newxstatusnotify.dll" }, { L"rss.dll", L"Plugins\\newsaggregator.dll" }, - { L"dbx_3x.dll", L"Plugins\\dbx_mmap.dll" }, + { L"dbx_3x.dll", L"Plugins\\dbx_mmait->dll" }, { L"actman30.dll", L"Plugins\\actman.dll" }, { L"skype.dll", L"Plugins\\skypeweb.dll" }, { L"skypeclassic.dll", L"Plugins\\skypeweb.dll" }, @@ -561,12 +559,12 @@ static renameTable[] = { L"startupstatus.dll", L"Plugins\\statusmanager.dll" }, #if MIRANDA_VER >= 0x0A00 - { L"dbx_mmap_sa.dll", L"Plugins\\dbx_mmap.dll" }, - { L"dbx_tree.dll", L"Plugins\\dbx_mmap.dll" }, + { L"dbx_mmap_sa.dll", L"Plugins\\dbx_mmait->dll" }, + { L"dbx_tree.dll", L"Plugins\\dbx_mmait->dll" }, { L"rc4.dll", nullptr }, { L"athena.dll", nullptr }, { L"skypekit.exe", nullptr }, - { L"mir_app.dll", nullptr }, + { L"mir_apit->dll", nullptr }, { L"mir_core.dll", nullptr }, { L"zlib.dll", nullptr }, #endif @@ -598,7 +596,7 @@ static renameTable[] = { L"msvcp100.dll", nullptr }, { L"msvcr100.dll", nullptr }, { L"tlen.dll", nullptr }, - { L"whatsapp.dll", nullptr }, + { L"whatsapit->dll", nullptr }, { L"xfire.dll", nullptr }, { L"yahoo.dll", nullptr }, { L"yahoogroups.dll", nullptr }, @@ -643,7 +641,7 @@ static bool isValidDirectory(const wchar_t *ptszDirName) } // Scans folders recursively -static int ScanFolder(const wchar_t *tszFolder, size_t cbBaseLen, const wchar_t *tszBaseUrl, SERVLIST& hashes, OBJLIST *UpdateFiles, int level = 0) +static int ScanFolder(const wchar_t *tszFolder, size_t cbBaseLen, const wchar_t *tszBaseUrl, SERVLIST &hashes, OBJLIST *UpdateFiles, int level = 0) { wchar_t tszBuf[MAX_PATH]; mir_snwprintf(tszBuf, L"%s\\*", tszFolder); diff --git a/plugins/QuickContacts/src/quickcontacts.cpp b/plugins/QuickContacts/src/quickcontacts.cpp index 7407230a1f..b530245b6b 100644 --- a/plugins/QuickContacts/src/quickcontacts.cpp +++ b/plugins/QuickContacts/src/quickcontacts.cpp @@ -1,4 +1,4 @@ -/* +/* Copyright (C) 2006 Ricardo Pescuma Domenecci Based on work (C) Heiko Schillinger @@ -15,14 +15,14 @@ Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this file; see the file license.txt. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -Boston, MA 02111-1307, USA. +Boston, MA 02111-1307, USA. */ #include "stdafx.h" // Prototypes /////////////////////////////////////////////////////////////////////////// - -PLUGININFOEX pluginInfo={ + +PLUGININFOEX pluginInfo = { sizeof(PLUGININFOEX), __PLUGIN_NAME, PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), @@ -50,7 +50,7 @@ HWND hwndMain = nullptr; int ModulesLoaded(WPARAM wParam, LPARAM lParam); int EventAdded(WPARAM wparam, LPARAM lparam); int HotkeyPressed(WPARAM wParam, LPARAM lParam); -INT_PTR ShowDialog(WPARAM wParam,LPARAM lParam); +INT_PTR ShowDialog(WPARAM wParam, LPARAM lParam); void FreeContacts(); int hksModule = 0; @@ -62,7 +62,7 @@ BOOL hasNewHotkeyModule = FALSE; // Functions //////////////////////////////////////////////////////////////////////////// -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID) { hInst = hinstDLL; return TRUE; @@ -74,7 +74,7 @@ extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD) return &pluginInfo; } -extern "C" __declspec(dllexport) int Load() +extern "C" __declspec(dllexport) int Load() { mir_getLP(&pluginInfo); pcli = Clist_GetInterface(); @@ -88,7 +88,7 @@ extern "C" __declspec(dllexport) int Load() return 0; } -extern "C" __declspec(dllexport) int Unload(void) +extern "C" __declspec(dllexport) int Unload(void) { FreeContacts(); @@ -102,7 +102,7 @@ extern "C" __declspec(dllexport) int Unload(void) // Called when all the modules are loaded -int ModulesLoaded(WPARAM, LPARAM) +int ModulesLoaded(WPARAM, LPARAM) { InitOptions(); @@ -110,7 +110,7 @@ int ModulesLoaded(WPARAM, LPARAM) int pcount = 0; PROTOACCOUNT** pdesc; - Proto_EnumAccounts(&pcount,&pdesc); + Proto_EnumAccounts(&pcount, &pdesc); opts.num_protos = pcount; @@ -124,7 +124,7 @@ int ModulesLoaded(WPARAM, LPARAM) hkd.szDescription.w = LPGENW("Open dialog"); hkd.szSection.w = LPGENW("Quick Contacts"); hkd.pszService = MS_QC_SHOW_DIALOG; - hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL|HOTKEYF_ALT, 'Q'); + hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL | HOTKEYF_ALT, 'Q'); Hotkey_Register(&hkd); hkd.pszService = nullptr; @@ -146,28 +146,27 @@ int ModulesLoaded(WPARAM, LPARAM) hkd.pszName = "Quick Contacts/Info"; hkd.szDescription.w = LPGENW("Open user info"); Hotkey_Register(&hkd); - + hkd.lParam = HOTKEY_HISTORY; hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL, 'H'); hkd.pszName = "Quick Contacts/History"; hkd.szDescription.w = LPGENW("Open history"); Hotkey_Register(&hkd); - + hkd.lParam = HOTKEY_MENU; hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL, 'M'); hkd.pszName = "Quick Contacts/Menu"; hkd.szDescription.w = LPGENW("Open contact menu"); Hotkey_Register(&hkd); - + hkd.lParam = HOTKEY_ALL_CONTACTS; hkd.DefHotKey = HOTKEYCODE(HOTKEYF_CONTROL, 'A'); hkd.pszName = "Quick Contacts/All Contacts"; hkd.szDescription.w = LPGENW("Show all contacts"); Hotkey_Register(&hkd); - if (ServiceExists(MS_SKIN_ADDHOTKEY)) - { - SKINHOTKEYDESCEX hk = {0}; + if (ServiceExists(MS_SKIN_ADDHOTKEY)) { + SKINHOTKEYDESCEX hk = { 0 }; hk.cbSize = sizeof(hk); hk.pszSection = Translate("Quick Contacts"); hk.pszName = Translate("Open dialog"); @@ -198,9 +197,9 @@ int EventAdded(WPARAM wparam, LPARAM hDbEvent) { DBEVENTINFO dbei = {}; db_event_get(hDbEvent, &dbei); - if ( !(dbei.flags & DBEF_SENT) || (dbei.flags & DBEF_READ) - || !db_get_b(NULL, MODULE_NAME, "EnableLastSentTo", 0) - || db_get_w(NULL, MODULE_NAME, "MsgTypeRec", TYPE_GLOBAL) != TYPE_GLOBAL) + if (!(dbei.flags & DBEF_SENT) || (dbei.flags & DBEF_READ) + || !db_get_b(NULL, MODULE_NAME, "EnableLastSentTo", 0) + || db_get_w(NULL, MODULE_NAME, "MsgTypeRec", TYPE_GLOBAL) != TYPE_GLOBAL) return 0; db_set_dw(NULL, MODULE_NAME, "LastSentTo", (UINT_PTR)wparam); @@ -217,7 +216,8 @@ int EventAdded(WPARAM wparam, LPARAM hDbEvent) // array where the contacts are put into -struct c_struct { +struct c_struct +{ wchar_t szname[120]; wchar_t szgroup[50]; MCONTACT hcontact; @@ -242,13 +242,11 @@ wchar_t tmp_list_name[120]; wchar_t *GetListName(c_struct *cs) { - if (opts.group_append && cs->szgroup[0] != '\0') - { + if (opts.group_append && cs->szgroup[0] != '\0') { mir_snwprintf(tmp_list_name, L"%s (%s)", cs->szname, cs->szgroup); return tmp_list_name; } - else - { + else { return cs->szname; } } @@ -273,28 +271,23 @@ int lstreq(wchar_t *a, wchar_t *b, size_t len = -1) // the contact array in alphabetical order void SortArray(void) { - int loop,doop; + int loop, doop; c_struct *cs_temp; - SortedList *sl = (SortedList *) &contacts; - for(loop=0;loopszname,contacts[doop]->szname); - if (cmp > 0) - { - cs_temp=contacts[loop]; - sl->items[loop]=contacts[doop]; - sl->items[doop]=cs_temp; + SortedList *sl = (SortedList *)&contacts; + for (loop = 0; loop < contacts.getCount(); loop++) { + for (doop = loop + 1; doop < contacts.getCount(); doop++) { + int cmp = lstreq(contacts[loop]->szname, contacts[doop]->szname); + if (cmp > 0) { + cs_temp = contacts[loop]; + sl->items[loop] = contacts[doop]; + sl->items[doop] = cs_temp; } - else if (cmp == 0) - { - if(lstreq(contacts[loop]->proto, contacts[doop]->proto) > 0) - { - cs_temp=contacts[loop]; - sl->items[loop]=contacts[doop]; - sl->items[doop]=cs_temp; + else if (cmp == 0) { + if (lstreq(contacts[loop]->proto, contacts[doop]->proto) > 0) { + cs_temp = contacts[loop]; + sl->items[loop] = contacts[doop]; + sl->items[doop] = cs_temp; } } @@ -317,8 +310,7 @@ int GetStatus(MCONTACT hContact, char *proto = nullptr) void FreeContacts() { - for (int i = contacts.getCount() - 1; i >= 0; i--) - { + for (int i = contacts.getCount() - 1; i >= 0; i--) { delete contacts[i]; contacts.remove(i); } @@ -339,24 +331,21 @@ void LoadContacts(HWND hwndDlg, BOOL show_all) for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { char *pszProto = GetContactProto(hContact); - if(pszProto == nullptr) + if (pszProto == nullptr) continue; // Get meta MCONTACT hMeta = NULL; - if (metacontactsEnabled) - { + if (metacontactsEnabled) { if ((!show_all && opts.hide_subcontacts) || opts.group_append) hMeta = db_mc_getMeta(hContact); } else if (!mir_strcmp(META_PROTO, pszProto)) continue; - if (!show_all) - { + if (!show_all) { // Check if is offline and have to show - if (GetStatus(hContact, pszProto) <= ID_STATUS_OFFLINE) - { + if (GetStatus(hContact, pszProto) <= ID_STATUS_OFFLINE) { // See if has to show char setting[128]; mir_snprintf(setting, "ShowOffline%s", pszProto); @@ -365,15 +354,14 @@ void LoadContacts(HWND hwndDlg, BOOL show_all) continue; // Check if proto offline - else if (opts.hide_from_offline_proto - && CallProtoService(pszProto, PS_GETSTATUS, 0, 0) <= ID_STATUS_OFFLINE) + else if (opts.hide_from_offline_proto + && CallProtoService(pszProto, PS_GETSTATUS, 0, 0) <= ID_STATUS_OFFLINE) continue; } // Check if is subcontact - if (opts.hide_subcontacts && hMeta != NULL) - { + if (opts.hide_subcontacts && hMeta != NULL) { if (!opts.keep_subcontacts_from_offline) continue; @@ -391,12 +379,10 @@ void LoadContacts(HWND hwndDlg, BOOL show_all) // Get group c_struct *contact = new c_struct(); - - if (opts.group_append) - { + + if (opts.group_append) { DBVARIANT dbv; - if (db_get_ws(hMeta == NULL ? hContact : hMeta, "CList", "Group", &dbv) == 0) - { + if (db_get_ws(hMeta == NULL ? hContact : hMeta, "CList", "Group", &dbv) == 0) { if (dbv.ptszVal != nullptr) mir_wstrncpy(contact->szgroup, dbv.ptszVal, _countof(contact->szgroup)); @@ -405,7 +391,7 @@ void LoadContacts(HWND hwndDlg, BOOL show_all) } // Make contact name - wchar_t *tmp = (wchar_t *) pcli->pfnGetContactDisplayName(hContact, 0); + wchar_t *tmp = (wchar_t *)pcli->pfnGetContactDisplayName(hContact, 0); mir_wstrncpy(contact->szname, tmp, _countof(contact->szname)); PROTOACCOUNT *acc = Proto_GetAccount(pszProto); @@ -417,14 +403,13 @@ void LoadContacts(HWND hwndDlg, BOOL show_all) } SortArray(); - + SendDlgItemMessage(hwndDlg, IDC_USERNAME, CB_RESETCONTENT, 0, 0); - for(int loop = 0; loop < contacts.getCount(); loop++) - { - SendDlgItemMessage(hwndDlg, IDC_USERNAME, CB_SETITEMDATA, - (WPARAM)SendDlgItemMessage(hwndDlg, IDC_USERNAME, - CB_ADDSTRING, 0, (LPARAM) GetListName(contacts[loop])), - (LPARAM)loop); + for (int loop = 0; loop < contacts.getCount(); loop++) { + SendDlgItemMessage(hwndDlg, IDC_USERNAME, CB_SETITEMDATA, + (WPARAM)SendDlgItemMessage(hwndDlg, IDC_USERNAME, + CB_ADDSTRING, 0, (LPARAM)GetListName(contacts[loop])), + (LPARAM)loop); } } @@ -432,8 +417,7 @@ void LoadContacts(HWND hwndDlg, BOOL show_all) // Enable buttons for the selected contact void EnableButtons(HWND hwndDlg, MCONTACT hContact) { - if (hContact == NULL) - { + if (hContact == NULL) { EnableWindow(GetDlgItem(hwndDlg, IDC_MESSAGE), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_FILE), FALSE); EnableWindow(GetDlgItem(hwndDlg, IDC_URL), FALSE); @@ -443,8 +427,7 @@ void EnableButtons(HWND hwndDlg, MCONTACT hContact) SendDlgItemMessage(hwndDlg, IDC_ICO, STM_SETICON, 0, 0); } - else - { + else { // Is a meta? MCONTACT hSub = db_mc_getMostOnline(hContact); if (hSub != NULL) @@ -465,7 +448,7 @@ void EnableButtons(HWND hwndDlg, MCONTACT hContact) EnableWindow(GetDlgItem(hwndDlg, IDC_MENU), TRUE); HICON ico = ImageList_GetIcon(hIml, pcli->pfnGetContactIcon(hContact), ILD_IMAGE); - SendDlgItemMessage(hwndDlg, IDC_ICO, STM_SETICON, (WPARAM) ico, 0); + SendDlgItemMessage(hwndDlg, IDC_ICO, STM_SETICON, (WPARAM)ico, 0); } } @@ -475,31 +458,25 @@ int CheckText(HWND hdlg, wchar_t *sztext, BOOL only_enable = FALSE) { EnableButtons(hwndMain, NULL); - if(sztext == nullptr || sztext[0] == '\0') + if (sztext == nullptr || sztext[0] == '\0') return 0; size_t len = mir_wstrlen(sztext); - if (only_enable) - { - for(int loop=0;loopszname)==0 || lstreq(sztext, GetListName(contacts[loop]))==0) - { - EnableButtons(hwndMain, contacts[loop]->hcontact); + if (only_enable) { + for (auto &it : contacts) { + if (lstreq(sztext, it->szname) == 0 || lstreq(sztext, GetListName(it)) == 0) { + EnableButtons(hwndMain, it->hcontact); return 0; } } } - else - { - for(int loop=0;loophcontact); + else { + for (auto &it : contacts) { + if (lstreq(sztext, GetListName(it), len) == 0) { + SetWindowText(hdlg, GetListName(it)); + SendMessage(hdlg, EM_SETSEL, (WPARAM)len, (LPARAM)-1); + EnableButtons(hwndMain, it->hcontact); return 0; } } @@ -514,8 +491,7 @@ MCONTACT GetSelectedContact(HWND hwndDlg) // First try selection int sel = SendDlgItemMessage(hwndDlg, IDC_USERNAME, CB_GETCURSEL, 0, 0); - if (sel != CB_ERR) - { + if (sel != CB_ERR) { int pos = SendDlgItemMessage(hwndDlg, IDC_USERNAME, CB_GETITEMDATA, sel, 0); if (pos != CB_ERR) return contacts[pos]->hcontact; @@ -525,12 +501,10 @@ MCONTACT GetSelectedContact(HWND hwndDlg) wchar_t cname[120] = L""; GetDlgItemText(hwndDlg, IDC_USERNAME, cname, _countof(cname)); - - for(int loop = 0; loop < contacts.getCount(); loop++) - { - if(!mir_wstrcmpi(cname, GetListName(contacts[loop]))) - return contacts[loop]->hcontact; - } + + for (auto &it : contacts) + if (!mir_wstrcmpi(cname, GetListName(it))) + return it->hcontact; return NULL; } @@ -538,8 +512,8 @@ MCONTACT GetSelectedContact(HWND hwndDlg) // get array position from handle int GetItemPos(MCONTACT hcontact) { - for(int loop=0; loop < contacts.getCount(); loop++) - if(hcontact == contacts[loop]->hcontact) + for (int loop = 0; loop < contacts.getCount(); loop++) + if (hcontact == contacts[loop]->hcontact) return loop; return -1; @@ -549,40 +523,37 @@ int GetItemPos(MCONTACT hcontact) // callback function for edit-box of the listbox // without this the autofill function isn't possible // this was done like ie does it..as far as spy++ could tell ;) -LRESULT CALLBACK EditProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) +LRESULT CALLBACK EditProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) { - switch(msg) { + switch (msg) { case WM_CHAR: { - if (wparam<32 && wparam != VK_BACK) + if (wparam < 32 && wparam != VK_BACK) break; wchar_t sztext[120] = L""; DWORD start; DWORD end; - int ret = SendMessage(hdlg,EM_GETSEL,(WPARAM)&start,(LPARAM)&end); + int ret = SendMessage(hdlg, EM_GETSEL, (WPARAM)&start, (LPARAM)&end); GetWindowText(hdlg, sztext, _countof(sztext)); BOOL at_end = (mir_wstrlen(sztext) == (int)end); - if (ret != -1) - { - if (wparam == VK_BACK) - { + if (ret != -1) { + if (wparam == VK_BACK) { if (start > 0) - SendMessage(hdlg,EM_SETSEL,(WPARAM)start-1,(LPARAM)end); + SendMessage(hdlg, EM_SETSEL, (WPARAM)start - 1, (LPARAM)end); - sztext[0]=0; + sztext[0] = 0; } - else - { - sztext[0]=wparam; - sztext[1]=0; + else { + sztext[0] = wparam; + sztext[1] = 0; } - SendMessage(hdlg,EM_REPLACESEL,0,(LPARAM)sztext); + SendMessage(hdlg, EM_REPLACESEL, 0, (LPARAM)sztext); GetWindowText(hdlg, sztext, _countof(sztext)); } @@ -594,21 +565,18 @@ LRESULT CALLBACK EditProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) { wchar_t sztext[120] = L""; - if (wparam == VK_RETURN) - { - switch(SendMessage(GetParent(hdlg),CB_GETDROPPEDSTATE,0,0)) - { + if (wparam == VK_RETURN) { + switch (SendMessage(GetParent(hdlg), CB_GETDROPPEDSTATE, 0, 0)) { case FALSE: - SendMessage(GetParent(GetParent(hdlg)),WM_COMMAND,MAKEWPARAM(IDC_ENTER,STN_CLICKED),0); + SendMessage(GetParent(GetParent(hdlg)), WM_COMMAND, MAKEWPARAM(IDC_ENTER, STN_CLICKED), 0); break; case TRUE: - SendMessage(GetParent(hdlg),CB_SHOWDROPDOWN,FALSE,0); + SendMessage(GetParent(hdlg), CB_SHOWDROPDOWN, FALSE, 0); break; } } - else if (wparam == VK_DELETE) - { + else if (wparam == VK_DELETE) { GetWindowText(hdlg, sztext, _countof(sztext)); CheckText(hdlg, sztext, TRUE); } @@ -617,7 +585,7 @@ LRESULT CALLBACK EditProc(HWND hdlg,UINT msg,WPARAM wparam,LPARAM lparam) } case WM_GETDLGCODE: - return DLGC_WANTCHARS|DLGC_WANTARROWS; + return DLGC_WANTCHARS | DLGC_WANTARROWS; } return mir_callNextSubclass(hdlg, EditProc, msg, wparam, lparam); @@ -630,15 +598,14 @@ HHOOK hHook; // the keyboard accelerators LRESULT CALLBACK HookProc(int code, WPARAM, LPARAM lparam) { - if (code!=MSGF_DIALOGBOX) + if (code != MSGF_DIALOGBOX) return 0; MSG *msg = (MSG*)lparam; if (hasNewHotkeyModule) { int action = Hotkey_Check(msg, "Quick Contacts"); - if (action != 0) - { + if (action != 0) { SendMessage(hwndMain, WM_COMMAND, action, 0); return 1; } @@ -649,8 +616,8 @@ LRESULT CALLBACK HookProc(int code, WPARAM, LPARAM lparam) if (TranslateAccelerator(msg->hwnd, hAcct, msg)) return 1; - - msg->hwnd=htemp; + + msg->hwnd = htemp; } if (msg->message == WM_KEYDOWN && msg->wParam == VK_ESCAPE) { @@ -664,7 +631,7 @@ LRESULT CALLBACK HookProc(int code, WPARAM, LPARAM lparam) break; } } - + return 0; } @@ -743,8 +710,8 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA GetWindowRect(GetDlgItem(hwndDlg, IDC_USERNAME), &rc); ScreenToClient(hwndDlg, &rc); - CreateWindow(L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_ICON | SS_CENTERIMAGE, - rc.left - 20, rc.top + (rc.bottom - rc.top - 16) / 2, 16, 16, hwndDlg, (HMENU) IDC_ICO, + CreateWindow(L"STATIC", L"", WS_CHILD | WS_VISIBLE | SS_ICON | SS_CENTERIMAGE, + rc.left - 20, rc.top + (rc.bottom - rc.top - 16) / 2, 16, 16, hwndDlg, (HMENU)IDC_ICO, hInst, nullptr); if (!hasNewHotkeyModule) @@ -754,7 +721,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA // Combo SendDlgItemMessage(hwndDlg, IDC_USERNAME, EM_LIMITTEXT, (WPARAM)119, 0); - mir_subclassWindow(GetWindow(GetDlgItem(hwndDlg, IDC_USERNAME),GW_CHILD), EditProc); + mir_subclassWindow(GetWindow(GetDlgItem(hwndDlg, IDC_USERNAME), GW_CHILD), EditProc); // Buttons FillCheckbox(hwndDlg, IDC_SHOW_ALL_CONTACTS, LPGENW("Show all contacts"), hasNewHotkeyModule ? NULL : L"Ctrl+A"); @@ -775,7 +742,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA if (db_get_b(NULL, MODULE_NAME, "EnableLastSentTo", 0)) { int pos = GetItemPos((MCONTACT)db_get_dw(NULL, MODULE_NAME, "LastSentTo", -1)); if (pos != -1) { - SendDlgItemMessage(hwndDlg, IDC_USERNAME, CB_SETCURSEL, (WPARAM) pos, 0); + SendDlgItemMessage(hwndDlg, IDC_USERNAME, CB_SETCURSEL, (WPARAM)pos, 0); EnableButtons(hwndDlg, contacts[pos]->hcontact); } } @@ -785,10 +752,9 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA return TRUE; case WM_COMMAND: - switch(LOWORD(wParam)) { + switch (LOWORD(wParam)) { case IDC_USERNAME: - if (HIWORD(wParam) == CBN_SELCHANGE) - { + if (HIWORD(wParam) == CBN_SELCHANGE) { int pos = SendDlgItemMessage(hwndDlg, IDC_USERNAME, CB_GETCURSEL, 0, 0); EnableButtons(hwndDlg, pos < contacts.getCount() ? contacts[pos]->hcontact : NULL); } @@ -809,8 +775,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA case IDC_MESSAGE: { MCONTACT hContact = GetSelectedContact(hwndDlg); - if (hContact == NULL) - { + if (hContact == NULL) { SetDlgItemText(hwndDlg, IDC_USERNAME, L""); SetFocus(GetDlgItem(hwndDlg, IDC_USERNAME)); break; @@ -831,8 +796,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA case IDC_FILE: { MCONTACT hContact = GetSelectedContact(hwndDlg); - if (hContact == NULL) - { + if (hContact == NULL) { SetDlgItemText(hwndDlg, IDC_USERNAME, L""); SetFocus(GetDlgItem(hwndDlg, IDC_USERNAME)); break; @@ -853,8 +817,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA case IDC_URL: { MCONTACT hContact = GetSelectedContact(hwndDlg); - if (hContact == NULL) - { + if (hContact == NULL) { SetDlgItemText(hwndDlg, IDC_USERNAME, L""); SetFocus(GetDlgItem(hwndDlg, IDC_USERNAME)); break; @@ -875,8 +838,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA case IDC_USERINFO: { MCONTACT hContact = GetSelectedContact(hwndDlg); - if (hContact == NULL) - { + if (hContact == NULL) { SetDlgItemText(hwndDlg, IDC_USERNAME, L""); SetFocus(GetDlgItem(hwndDlg, IDC_USERNAME)); break; @@ -897,8 +859,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA case IDC_HISTORY: { MCONTACT hContact = GetSelectedContact(hwndDlg); - if (hContact == NULL) - { + if (hContact == NULL) { SetDlgItemText(hwndDlg, IDC_USERNAME, L""); SetFocus(GetDlgItem(hwndDlg, IDC_USERNAME)); break; @@ -919,8 +880,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA case IDC_MENU: { MCONTACT hContact = GetSelectedContact(hwndDlg); - if (hContact == NULL) - { + if (hContact == NULL) { SetDlgItemText(hwndDlg, IDC_USERNAME, L""); SetFocus(GetDlgItem(hwndDlg, IDC_USERNAME)); break; @@ -933,16 +893,15 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA RECT rc; GetWindowRect(GetDlgItem(hwndDlg, IDC_MENU), &rc); HMENU hMenu = Menu_BuildContactMenu(hContact); - int ret = TrackPopupMenu(hMenu, TPM_TOPALIGN|TPM_RIGHTBUTTON|TPM_RETURNCMD, rc.left, rc.bottom, 0, hwndDlg, nullptr); + int ret = TrackPopupMenu(hMenu, TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, rc.left, rc.bottom, 0, hwndDlg, nullptr); DestroyMenu(hMenu); - if(ret) - { + if (ret) { SendMessage(hwndDlg, WM_CLOSE, 0, 0); Clist_MenuProcessCommand(LOWORD(ret), MPCF_CONTACTMENU, hContact); } - db_set_dw(NULL, MODULE_NAME, "LastSentTo", (DWORD) hContact); + db_set_dw(NULL, MODULE_NAME, "LastSentTo", (DWORD)hContact); } break; @@ -950,7 +909,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA case IDC_SHOW_ALL_CONTACTS: { // Get old text - HWND hEdit = GetWindow(GetWindow(hwndDlg,GW_CHILD),GW_CHILD); + HWND hEdit = GetWindow(GetWindow(hwndDlg, GW_CHILD), GW_CHILD); wchar_t sztext[120] = L""; if (SendMessage(hEdit, EM_GETSEL, 0, 0) != -1) @@ -961,8 +920,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA // Fill combo BOOL all = IsDlgButtonChecked(hwndDlg, IDC_SHOW_ALL_CONTACTS); - if (LOWORD(wParam) == HOTKEY_ALL_CONTACTS) - { + if (LOWORD(wParam) == HOTKEY_ALL_CONTACTS) { // Toggle checkbox all = !all; CheckDlgButton(hwndDlg, IDC_SHOW_ALL_CONTACTS, all ? BST_CHECKED : BST_UNCHECKED); @@ -994,26 +952,25 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam; // Handle contact menu - if(lpdis->CtlID != IDC_USERNAME) - { + if (lpdis->CtlID != IDC_USERNAME) { if (lpdis->CtlType == ODT_MENU) return Menu_DrawItem(lParam); break; } // Handle combo - if(lpdis->itemID == -1) + if (lpdis->itemID == -1) break; TEXTMETRIC tm; - int icon_width=0, icon_height=0; + int icon_width = 0, icon_height = 0; RECT rc; GetTextMetrics(lpdis->hDC, &tm); ImageList_GetIconSize(hIml, &icon_width, &icon_height); - COLORREF clrfore = SetTextColor(lpdis->hDC,GetSysColor(lpdis->itemState & ODS_SELECTED?COLOR_HIGHLIGHTTEXT:COLOR_WINDOWTEXT)); - COLORREF clrback = SetBkColor(lpdis->hDC,GetSysColor(lpdis->itemState & ODS_SELECTED?COLOR_HIGHLIGHT:COLOR_WINDOW)); + COLORREF clrfore = SetTextColor(lpdis->hDC, GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT)); + COLORREF clrback = SetBkColor(lpdis->hDC, GetSysColor(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_WINDOW)); FillRect(lpdis->hDC, &lpdis->rcItem, GetSysColorBrush(lpdis->itemState & ODS_SELECTED ? COLOR_HIGHLIGHT : COLOR_WINDOW)); @@ -1033,9 +990,9 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA if (max_proto_width == 0) { // Has to be done, else the DC isnt the right one // Dont ask me why - for (int loop = 0; loop < contacts.getCount(); loop++) { + for (auto &it : contacts) { RECT rcc = { 0, 0, 0x7FFF, 0x7FFF }; - DrawText(lpdis->hDC, contacts[loop]->proto, -1, &rcc, DT_END_ELLIPSIS | DT_NOPREFIX | DT_SINGLELINE | DT_CALCRECT); + DrawText(lpdis->hDC, it->proto, -1, &rcc, DT_END_ELLIPSIS | DT_NOPREFIX | DT_SINGLELINE | DT_CALCRECT); max_proto_width = max(max_proto_width, rcc.right - rcc.left); } @@ -1090,7 +1047,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA LPMEASUREITEMSTRUCT lpmis = (LPMEASUREITEMSTRUCT)lParam; // Handle contact menu - if(lpmis->CtlID != IDC_USERNAME) { + if (lpmis->CtlID != IDC_USERNAME) { if (lpmis->CtlType == ODT_MENU) return Menu_MeasureItem(lParam); break; @@ -1099,7 +1056,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA // Handle combo TEXTMETRIC tm; - int icon_width = 0, icon_height=0; + int icon_width = 0, icon_height = 0; GetTextMetrics(GetDC(hwndDlg), &tm); ImageList_GetIconSize(hIml, &icon_width, &icon_height); @@ -1115,10 +1072,9 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARA // Show the main dialog -INT_PTR ShowDialog(WPARAM, LPARAM) +INT_PTR ShowDialog(WPARAM, LPARAM) { - if (!main_dialog_open) - { + if (!main_dialog_open) { InterlockedExchange(&main_dialog_open, 1); hwndMain = CreateDialog(hInst, MAKEINTRESOURCE(IDD_MAIN), nullptr, MainDlgProc); diff --git a/plugins/QuickReplies/src/events.cpp b/plugins/QuickReplies/src/events.cpp index 5335379dd1..23ec25f537 100644 --- a/plugins/QuickReplies/src/events.cpp +++ b/plugins/QuickReplies/src/events.cpp @@ -97,8 +97,8 @@ int OnButtonPressed(WPARAM wParam, LPARAM lParam) } } - for (int i = 0; i < replyList.getCount(); i++) - mir_free(replyList[i]); + for (auto &it : replyList) + mir_free(it); replyList.destroy(); return 1; diff --git a/plugins/Scriver/src/chat_manager.cpp b/plugins/Scriver/src/chat_manager.cpp index c763f15e6a..0995b28b74 100644 --- a/plugins/Scriver/src/chat_manager.cpp +++ b/plugins/Scriver/src/chat_manager.cpp @@ -31,8 +31,7 @@ SESSION_INFO* SM_FindSessionAutoComplete(const char* pszModule, SESSION_INFO *cu if (currSession == prevSession) pszCurrent = pszOriginal; - for (int i = 0; i < pci->arSessions.getCount(); i++) { - SESSION_INFO *si = pci->arSessions[i]; + for (auto &si : pci->arSessions) { if (si != currSession && !mir_strcmpi(pszModule, si->pszModule)) { if (my_strstri(si->ptszName, pszOriginal) == si->ptszName) { if (prevSession != si && mir_wstrcmpi(si->ptszName, pszCurrent) > 0 && (!pszName || mir_wstrcmpi(si->ptszName, pszName) < 0)) { diff --git a/plugins/Scriver/src/msgs.cpp b/plugins/Scriver/src/msgs.cpp index e713c569cc..7e0ddb8a4f 100644 --- a/plugins/Scriver/src/msgs.cpp +++ b/plugins/Scriver/src/msgs.cpp @@ -276,11 +276,10 @@ static void RestoreUnreadMessageAlerts(void) cle.flags = CLEF_UNICODE; cle.szTooltip.w = toolTip; - for (int i = 0; i < arEvents.getCount(); i++) { - MSavedEvent &e = arEvents[i]; - mir_snwprintf(toolTip, TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(e.hContact, 0)); - cle.hContact = e.hContact; - cle.hDbEvent = e.hEvent; + for (auto &e : arEvents) { + mir_snwprintf(toolTip, TranslateT("Message from %s"), pcli->pfnGetContactDisplayName(e->hContact, 0)); + cle.hContact = e->hContact; + cle.hDbEvent = e->hEvent; pcli->pfnAddEvent(&cle); } } diff --git a/plugins/SecureIM/src/crypt_icons.cpp b/plugins/SecureIM/src/crypt_icons.cpp index 59e0059773..2c7eb2fd75 100644 --- a/plugins/SecureIM/src/crypt_icons.cpp +++ b/plugins/SecureIM/src/crypt_icons.cpp @@ -19,9 +19,9 @@ static ICON_CACHE& getCacheItem(int mode, int type) int m = mode & 0x0f, s = (mode & SECURED) >> 4, i; // разобрали на части - режим и состояние HICON icon; - for (i = 0; i < arIcoList.getCount(); i++) - if (arIcoList[i].mode == ((type << 8) | mode)) - return arIcoList[i]; + for (auto &it : arIcoList) + if (it->mode == ((type << 8) | mode)) + return *it; i = s; switch (type) { @@ -106,8 +106,8 @@ void ShowStatusIconNotify(MCONTACT hContact) void RefreshContactListIcons(void) { - for (int i = 0; i < arIcoList.getCount(); i++) - arIcoList[i].hCLIcon = nullptr; + for (auto &it : arIcoList) + it->hCLIcon = nullptr; for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) if (isSecureProtocol(hContact)) diff --git a/plugins/SecureIM/src/crypt_lists.cpp b/plugins/SecureIM/src/crypt_lists.cpp index bb97d160f0..be5f6a5e0a 100644 --- a/plugins/SecureIM/src/crypt_lists.cpp +++ b/plugins/SecureIM/src/crypt_lists.cpp @@ -56,9 +56,9 @@ void loadSupportedProtocols() void freeSupportedProtocols() { - for (int j = 0; j < arProto.getCount(); j++) { - mir_free(arProto[j]->name); - mir_free(arProto[j]); + for (auto &it : arProto) { + mir_free(it->name); + mir_free(it); } arProto.destroy(); @@ -66,9 +66,9 @@ void freeSupportedProtocols() pSupPro getSupPro(MCONTACT hContact) { - for (int j = 0; j < arProto.getCount(); j++) - if (Proto_IsProtoOnContact(hContact, arProto[j]->name)) - return arProto[j]; + for (auto &it : arProto) + if (Proto_IsProtoOnContact(hContact, it->name)) + return it; return nullptr; } @@ -127,8 +127,7 @@ void loadContactList() // free list of secureIM users void freeContactList() { - for (int j = 0; j < arClist.getCount(); j++) { - pUinKey p = arClist[j]; + for (auto &p : arClist) { cpp_delete_context(p->cntx); p->cntx = nullptr; mir_free(p->tmp); mir_free(p->msgSplitted); @@ -153,9 +152,9 @@ pUinKey getUinKey(MCONTACT hContact) pUinKey getUinCtx(HANDLE cntx) { - for (int j = 0; j < arClist.getCount(); j++) - if (arClist[j]->cntx == cntx) - return arClist[j]; + for (auto &it : arClist) + if (it->cntx == cntx) + return it; return nullptr; } diff --git a/plugins/SeenPlugin/src/utils.cpp b/plugins/SeenPlugin/src/utils.cpp index ef90cd1273..203c2ed258 100644 --- a/plugins/SeenPlugin/src/utils.cpp +++ b/plugins/SeenPlugin/src/utils.cpp @@ -47,8 +47,8 @@ void LoadWatchedProtos() void UnloadWatchedProtos() { - for (int i = 0; i < arWatchedProtos.getCount(); i++) - mir_free(arWatchedProtos[i]); + for (auto &it : arWatchedProtos) + mir_free(it); arWatchedProtos.destroy(); } diff --git a/plugins/SimpleStatusMsg/src/utils.cpp b/plugins/SimpleStatusMsg/src/utils.cpp index fda20d04a2..1b046968ff 100644 --- a/plugins/SimpleStatusMsg/src/utils.cpp +++ b/plugins/SimpleStatusMsg/src/utils.cpp @@ -48,7 +48,7 @@ HICON LoadIconEx(const char *name) HANDLE GetIconHandle(int iconId) { - for(int i = 0; i < _countof(iconList); i++) + for (int i = 0; i < _countof(iconList); i++) if (iconList[i].defIconID == iconId) return iconList[i].hIcolib; @@ -73,8 +73,8 @@ HANDLE HookProtoEvent(const char *szModule, const char *szEvent, MIRANDAHOOKPARA void UnhookProtoEvents(void) { - for (int i = 0; i < arProtoHooks.getCount(); ++i) - UnhookEvent( arProtoHooks[i] ); + for (auto &it : arProtoHooks) + UnhookEvent(it); arProtoHooks.destroy(); } diff --git a/plugins/SpellChecker/src/dictionary.cpp b/plugins/SpellChecker/src/dictionary.cpp index 03fa58e5fb..98178f0a23 100644 --- a/plugins/SpellChecker/src/dictionary.cpp +++ b/plugins/SpellChecker/src/dictionary.cpp @@ -733,8 +733,7 @@ BOOL CALLBACK EnumLocalesProc(LPTSTR lpLocaleString) wchar_t name[64]; mir_snwprintf(name, L"%s_%s", ini, end); - for (int i = 0; i < tmp_dicts->getCount(); i++) { - Dictionary *dict = (*tmp_dicts)[i]; + for (auto &dict : *tmp_dicts) { if (mir_wstrcmpi(dict->language, name) == 0) { GetLocaleInfo(MAKELCID(langID, 0), LOCALE_SENGLANGUAGE, dict->english_name, _countof(dict->english_name)); @@ -772,9 +771,7 @@ void GetDictsInfo(LIST &dicts) EnumSystemLocales(EnumLocalesProc, LCID_SUPPORTED); // Try to get name from DB - for (int i = 0; i < dicts.getCount(); i++) { - Dictionary *dict = dicts[i]; - + for (auto &dict : dicts) { if (dict->full_name[0] == '\0') { DBVARIANT dbv; @@ -931,9 +928,8 @@ void GetAvaibleDictionaries(LIST &dicts, wchar_t *path, wchar_t *use // Free the list returned by GetAvaibleDictionaries void FreeDictionaries(LIST &dicts) { - for (int i = 0; i < dicts.getCount(); i++) - delete dicts[i]; - + for (auto &it : dicts) + delete it; dicts.destroy(); } diff --git a/plugins/SpellChecker/src/options.cpp b/plugins/SpellChecker/src/options.cpp index 5dd5db0a0d..6f0d0e22e9 100644 --- a/plugins/SpellChecker/src/options.cpp +++ b/plugins/SpellChecker/src/options.cpp @@ -98,13 +98,11 @@ void LoadOptions() db_free(&dbv); } - int i; - for (i = 0; i < languages.getCount(); i++) - if (mir_wstrcmp(languages[i]->language, opts.default_language) == 0) - break; + for (auto &it : languages) + if (mir_wstrcmp(it->language, opts.default_language) == 0) + return; - if (i >= languages.getCount()) - mir_wstrcpy(opts.default_language, languages[0]->language); + mir_wstrcpy(opts.default_language, languages[0]->language); } static void DrawItem(LPDRAWITEMSTRUCT lpdis, Dictionary *dict) diff --git a/plugins/SpellChecker/src/spellchecker.cpp b/plugins/SpellChecker/src/spellchecker.cpp index 0640f6f10b..4b495303c1 100644 --- a/plugins/SpellChecker/src/spellchecker.cpp +++ b/plugins/SpellChecker/src/spellchecker.cpp @@ -145,7 +145,7 @@ static int ModulesLoaded(WPARAM, LPARAM) // Get language flags for (int i = 0; i < languages.getCount(); i++) { - Dictionary *p = languages[i]; + auto *p = languages[i]; sid.description.w = p->full_name; char lang[32]; @@ -179,9 +179,7 @@ static int ModulesLoaded(WPARAM, LPARAM) FreeLibrary(hFlagsDll); } - for (int j = 0; j < languages.getCount(); j++) { - Dictionary *dict = languages[j]; - + for (auto &dict : languages) { wchar_t filename[MAX_PATH]; mir_snwprintf(filename, L"%s\\%s.ar", customDictionariesFolder, dict->language); dict->autoReplace = new AutoReplaceMap(filename, dict); diff --git a/plugins/SpellChecker/src/utils.cpp b/plugins/SpellChecker/src/utils.cpp index 1b88e94621..7dfcd12884 100644 --- a/plugins/SpellChecker/src/utils.cpp +++ b/plugins/SpellChecker/src/utils.cpp @@ -728,11 +728,8 @@ void GetUserProtoLanguageSetting(Dialog *dlg, MCONTACT hContact, char *group, ch if (dbv.type == DBVT_WCHAR && dbv.ptszVal != nullptr) { wchar_t *lang = dbv.ptszVal; - for (int i = 0; i < languages.getCount(); i++) { - Dictionary *dict = languages[i]; - if (mir_wstrcmpi(dict->localized_name, lang) == 0 - || mir_wstrcmpi(dict->english_name, lang) == 0 - || mir_wstrcmpi(dict->language, lang) == 0) { + for (auto &dict : languages) { + if (mir_wstrcmpi(dict->localized_name, lang) == 0 || mir_wstrcmpi(dict->english_name, lang) == 0 || mir_wstrcmpi(dict->language, lang) == 0) { mir_wstrncpy(dlg->lang_name, dict->language, _countof(dlg->lang_name)); break; } diff --git a/plugins/TopToolBar/src/toolbar.cpp b/plugins/TopToolBar/src/toolbar.cpp index 2bf222f327..413ac69fb5 100644 --- a/plugins/TopToolBar/src/toolbar.cpp +++ b/plugins/TopToolBar/src/toolbar.cpp @@ -115,8 +115,8 @@ int SaveAllButtonsOptions() int LaunchCnt = 0; { mir_cslock lck(csButtonsHook); - for (int i = 0; i < Buttons.getCount(); i++) - Buttons[i]->SaveSettings(&SeparatorCnt, &LaunchCnt); + for (auto &it : Buttons) + it->SaveSettings(&SeparatorCnt, &LaunchCnt); } db_set_b(0, TTB_OPTDIR, "SepCnt", SeparatorCnt); db_set_b(0, TTB_OPTDIR, "LaunchCnt", LaunchCnt); @@ -128,8 +128,8 @@ static bool nameexists(const char *name) if (name == nullptr) return false; - for (int i = 0; i < Buttons.getCount(); i++) - if (!mir_strcmp(Buttons[i]->pszName, name)) + for (auto &it : Buttons) + if (!mir_strcmp(it->pszName, name)) return true; return false; @@ -210,8 +210,8 @@ int ArrangeButtons() int i, nextX = 0, y = 0; int nButtonCount = 0; - for (i = 0; i < Buttons.getCount(); i++) - if (Buttons[i]->hwnd) + for (auto &it : Buttons) + if (it->hwnd) nButtonCount++; if (nButtonCount == 0) @@ -492,8 +492,7 @@ INT_PTR TTBSetOptions(WPARAM wParam, LPARAM lParam) int OnIconChange(WPARAM, LPARAM) { mir_cslock lck(csButtonsHook); - for (int i = 0; i < Buttons.getCount(); i++) { - TopButtonInt *b = Buttons[i]; + for (auto &b : Buttons) { if (!b->hIconHandleUp && !b->hIconHandleDn) continue; @@ -678,8 +677,8 @@ int UnloadToolbarModule() { DestroyHookableEvent(hTTBModuleLoaded); - for (int i = 0; i < Buttons.getCount(); i++) - delete Buttons[i]; + for (auto &it : Buttons) + delete it; mir_free(g_ctrl); return 0; diff --git a/plugins/TopToolBar/src/ttbopt.cpp b/plugins/TopToolBar/src/ttbopt.cpp index 843db24ac6..27d1b36b2a 100644 --- a/plugins/TopToolBar/src/ttbopt.cpp +++ b/plugins/TopToolBar/src/ttbopt.cpp @@ -61,8 +61,8 @@ static int BuildTree(HWND hwndDlg) if (Buttons.getCount() == 0) return FALSE; - for (int i = 0; i < Buttons.getCount(); i++) - AddLine(hTree, Buttons[i], TVI_LAST, dat->himlButtonIcons); + for (auto &it : Buttons) + AddLine(hTree, it, TVI_LAST, dat->himlButtonIcons); return TRUE; } @@ -95,9 +95,8 @@ static void SaveTree(HWND hwndDlg) } { mir_cslock lck(csButtonsHook); - for (int i=0; i < Buttons.getCount(); i++) - delete Buttons[i]; - + for (auto &it : Buttons) + delete it; Buttons = tmpList; } SaveAllButtonsOptions(); @@ -128,8 +127,7 @@ static void RecreateWindows() { { mir_cslock lck(csButtonsHook); - for (int i = 0; i < Buttons.getCount(); i++) { - TopButtonInt *b = Buttons[i]; + for (auto &b : Buttons) { if (b->hwnd) { if (g_ctrl->bHardUpdate) { DestroyWindow(b->hwnd); diff --git a/plugins/Variables/src/contact.cpp b/plugins/Variables/src/contact.cpp index 270ae015b8..8574cea41f 100644 --- a/plugins/Variables/src/contact.cpp +++ b/plugins/Variables/src/contact.cpp @@ -317,22 +317,21 @@ static int contactSettingChanged(WPARAM hContact, LPARAM lParam) bool isUid = (((INT_PTR)uid != CALLSERVICE_NOTFOUND) && (uid != nullptr)) && (!strcmp(dbw->szSetting, uid)); mir_cslock lck(csContactCache); - for (int i = 0; i < arContactCache.getCount(); i++) { - CONTACTCE &cce = arContactCache[i]; - if (hContact != cce.hContact && (cce.flags & CI_CNFINFO) == 0) + for (auto &it : arContactCache) { + if (hContact != it->hContact && (it->flags & CI_CNFINFO) == 0) continue; - if ((isNick && (cce.flags & CI_NICK)) || - (isFirstName && (cce.flags & CI_FIRSTNAME)) || - (isLastName && (cce.flags & CI_LASTNAME)) || - (isEmail && (cce.flags & CI_EMAIL)) || - (isMyHandle && (cce.flags & CI_LISTNAME)) || - (cce.flags & CI_CNFINFO) != 0 || // lazy; always invalidate CNF info cache entries - (isUid && (cce.flags & CI_UNIQUEID))) + if ((isNick && (it->flags & CI_NICK)) || + (isFirstName && (it->flags & CI_FIRSTNAME)) || + (isLastName && (it->flags & CI_LASTNAME)) || + (isEmail && (it->flags & CI_EMAIL)) || + (isMyHandle && (it->flags & CI_LISTNAME)) || + (it->flags & CI_CNFINFO) != 0 || // lazy; always invalidate CNF info cache entries + (isUid && (it->flags & CI_UNIQUEID))) { /* remove from cache */ - mir_free(cce.tszContact); - arContactCache.remove(i); + mir_free(it->tszContact); + arContactCache.remove(it); break; } } @@ -347,8 +346,8 @@ int initContactModule() int deinitContactModule() { - for (int i = 0; i < arContactCache.getCount(); i++) - mir_free(arContactCache[i].tszContact); + for (auto &it : arContactCache) + mir_free(it->tszContact); arContactCache.destroy(); return 0; } diff --git a/plugins/Variables/src/parse_alias.cpp b/plugins/Variables/src/parse_alias.cpp index e90595a68e..aff5f9251c 100644 --- a/plugins/Variables/src/parse_alias.cpp +++ b/plugins/Variables/src/parse_alias.cpp @@ -36,9 +36,9 @@ static ALIASREGISTER* searchAliasRegister(wchar_t *szAlias) return nullptr; mir_cslock lck(csAliasRegister); - for (int i = 0; i < arAliases.getCount(); i++) - if (!mir_wstrcmp(arAliases[i]->szAlias, szAlias)) - return arAliases[i]; + for (auto &it : arAliases) + if (!mir_wstrcmp(it->szAlias, szAlias)) + return it; return nullptr; } @@ -93,8 +93,7 @@ static int addToAliasRegister(wchar_t *szAlias, unsigned int argc, wchar_t** arg return -1; mir_cslock lck(csAliasRegister); - for (int i = 0; i < arAliases.getCount(); i++) { - ALIASREGISTER *p = arAliases[i]; + for (auto &p : arAliases) { if (mir_wstrcmp(p->szAlias, szAlias)) continue; @@ -194,8 +193,7 @@ void registerAliasTokens() void unregisterAliasTokens() { - for (int i = 0; i < arAliases.getCount(); i++) { - ALIASREGISTER *p = arAliases[i]; + for (auto &p : arAliases) { for (unsigned j = 0; j < p->argc; j++) mir_free(p->argv[j]); mir_free(p->argv); diff --git a/plugins/Variables/src/tokenregister.cpp b/plugins/Variables/src/tokenregister.cpp index 11c2212449..77c6af4252 100644 --- a/plugins/Variables/src/tokenregister.cpp +++ b/plugins/Variables/src/tokenregister.cpp @@ -238,8 +238,7 @@ int initTokenRegister() int deinitTokenRegister() { - for (int i = 0; i < tokens.getCount(); i++) { - TokenRegisterEntry *tre = tokens[i]; + for (auto &tre : tokens) { if (!(tre->tr.flags & TRF_PARSEFUNC) && tre->tr.szService != nullptr) mir_free(tre->tr.szService); diff --git a/plugins/XSoundNotify/src/options.cpp b/plugins/XSoundNotify/src/options.cpp index 035772e93d..031729c561 100644 --- a/plugins/XSoundNotify/src/options.cpp +++ b/plugins/XSoundNotify/src/options.cpp @@ -317,22 +317,22 @@ static INT_PTR CALLBACK OptsProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM l NMHDR *hdr = (NMHDR *)lParam; switch (hdr->code) { case PSN_APPLY: - for (int i = 0; i < XSN_Users.getCount(); i++) { - if (mir_wstrcmpi(XSN_Users[i]->path, L"")) { + for (auto &it : XSN_Users) { + if (mir_wstrcmpi(it->path, L"")) { wchar_t shortpath[MAX_PATH]; - PathToRelativeW(XSN_Users[i]->path, shortpath); - if (XSN_Users[i]->iscontact) - db_set_ws(XSN_Users[i]->hContact, SETTINGSNAME, SETTINGSKEY, shortpath); + PathToRelativeW(it->path, shortpath); + if (it->iscontact) + db_set_ws(it->hContact, SETTINGSNAME, SETTINGSKEY, shortpath); else - db_set_ws(NULL, SETTINGSNAME, (LPCSTR)XSN_Users[i]->hContact, shortpath); + db_set_ws(NULL, SETTINGSNAME, (LPCSTR)it->hContact, shortpath); } - if (XSN_Users[i]->iscontact) - db_set_b(XSN_Users[i]->hContact, SETTINGSNAME, SETTINGSIGNOREKEY, XSN_Users[i]->ignore); + if (it->iscontact) + db_set_b(it->hContact, SETTINGSNAME, SETTINGSIGNOREKEY, it->ignore); else { - size_t value_max_len = mir_strlen((const char*)XSN_Users[i]->hContact) + 8; + size_t value_max_len = mir_strlen((const char*)it->hContact) + 8; char *value = (char *)mir_alloc(sizeof(char) * value_max_len); - mir_snprintf(value, value_max_len, "%s_ignore", (const char*)XSN_Users[i]->hContact); - db_set_b(NULL, SETTINGSNAME, value, XSN_Users[i]->ignore); + mir_snprintf(value, value_max_len, "%s_ignore", (const char*)it->hContact); + db_set_b(NULL, SETTINGSNAME, value, it->ignore); mir_free(value); } } diff --git a/plugins/YAPP/src/options.cpp b/plugins/YAPP/src/options.cpp index 423299490d..10da330778 100644 --- a/plugins/YAPP/src/options.cpp +++ b/plugins/YAPP/src/options.cpp @@ -451,8 +451,7 @@ static INT_PTR CALLBACK DlgProcOptsClasses(HWND hwndDlg, UINT msg, WPARAM wParam if (((LPNMHDR)lParam)->code == PSN_APPLY) { arClasses = arNewClasses; char setting[256]; - for (int i = 0; i < arClasses.getCount(); i++) { - POPUPCLASS *pc = arClasses[i]; + for (auto &pc : arClasses) { mir_snprintf(setting, "%s/Timeout", pc->pszName); db_set_w(0, MODULE, setting, pc->iSeconds); mir_snprintf(setting, "%s/TextCol", pc->pszName); diff --git a/plugins/YAPP/src/services.cpp b/plugins/YAPP/src/services.cpp index 71f68a7b05..87ef273df9 100644 --- a/plugins/YAPP/src/services.cpp +++ b/plugins/YAPP/src/services.cpp @@ -381,9 +381,9 @@ static INT_PTR CreateClassPopup(WPARAM wParam, LPARAM lParam) if (wParam) pc = (POPUPCLASS *)wParam; else { - for (int i = 0; i < arClasses.getCount(); i++) { - if (mir_strcmp(arClasses[i]->pszName, pdc->pszClassName) == 0) { - pc = arClasses[i]; + for (auto &it : arClasses) { + if (mir_strcmp(it->pszName, pdc->pszClassName) == 0) { + pc = it; break; } } @@ -446,6 +446,6 @@ void DeinitServices() { DestroyHookableEvent(hEventNotify); - for (int i = 0; i < arClasses.getCount(); i++) - FreePopupClass(arClasses[i]); + for (auto &it : arClasses) + FreePopupClass(it); } diff --git a/protocols/FacebookRM/src/messages.cpp b/protocols/FacebookRM/src/messages.cpp index 263f33a462..b502a1f471 100644 --- a/protocols/FacebookRM/src/messages.cpp +++ b/protocols/FacebookRM/src/messages.cpp @@ -320,8 +320,8 @@ HttpRequest* facebook_client::markMessageReadRequest(const LIST &ids) p->Url << INT_PARAM("__a", 1); - for (int i = 0; i < ids.getCount(); i++) { - std::string id_ = ids[i]; + for (auto &it : ids) { + std::string id_ = it; // NOTE: Remove "id." prefix as here we need to give threadFbId and not threadId if (id_.substr(0, 3) == "id.") id_ = id_.substr(3); diff --git a/protocols/FacebookRM/src/stdafx.h b/protocols/FacebookRM/src/stdafx.h index 83efa47cf7..ea411d908f 100644 --- a/protocols/FacebookRM/src/stdafx.h +++ b/protocols/FacebookRM/src/stdafx.h @@ -86,6 +86,6 @@ extern DWORD g_mirandaVersion; template __inline static void FreeList(const LIST &lst) { - for (int i = 0; i < lst.getCount(); i++) - mir_free(lst[i]); + for (auto &it : lst) + mir_free(it); } \ No newline at end of file diff --git a/protocols/FacebookRM/src/theme.cpp b/protocols/FacebookRM/src/theme.cpp index 70c0835308..91d7931076 100644 --- a/protocols/FacebookRM/src/theme.cpp +++ b/protocols/FacebookRM/src/theme.cpp @@ -75,9 +75,9 @@ static FacebookProto * GetInstanceByHContact(MCONTACT hContact) if (!proto) return nullptr; - for (int i = 0; i < g_Instances.getCount(); i++) - if (!mir_strcmp(proto, g_Instances[i].m_szModuleName)) - return &g_Instances[i]; + for (auto &it : g_Instances) + if (!mir_strcmp(proto, it->m_szModuleName)) + return it; return nullptr; } diff --git a/protocols/Gadu-Gadu/src/avatar.cpp b/protocols/Gadu-Gadu/src/avatar.cpp index 65e71a7456..ab7356ec0a 100644 --- a/protocols/Gadu-Gadu/src/avatar.cpp +++ b/protocols/Gadu-Gadu/src/avatar.cpp @@ -291,14 +291,14 @@ void __cdecl GaduProto::avatarrequestthread(void*) gg_sleep(100, FALSE, "avatarrequestthread", 101, 1); } - for (int i = 0; i < avatar_requests.getCount(); i++) - mir_free(avatar_requests[i]); - - for (int k = 0; k < avatar_transfers.getCount(); k++) - mir_free(avatar_transfers[k]); - + for (auto &it : avatar_requests) + mir_free(it); avatar_requests.destroy(); + + for (auto &it : avatar_transfers) + mir_free(it); avatar_transfers.destroy(); + debugLogA("avatarrequestthread(): end. Avatar Request Thread Ending"); } diff --git a/protocols/Gadu-Gadu/src/gg.cpp b/protocols/Gadu-Gadu/src/gg.cpp index 1d7c253dc5..bb7855c744 100644 --- a/protocols/Gadu-Gadu/src/gg.cpp +++ b/protocols/Gadu-Gadu/src/gg.cpp @@ -222,9 +222,9 @@ static GaduProto* gg_getprotoinstance(MCONTACT hContact) if (szProto == nullptr) return nullptr; - for (int i = 0; i < g_Instances.getCount(); i++) - if (mir_strcmp(szProto, g_Instances[i]->m_szModuleName) == 0) - return g_Instances[i]; + for (auto &it : g_Instances) + if (mir_strcmp(szProto, it->m_szModuleName) == 0) + return it; return nullptr; } diff --git a/protocols/Gadu-Gadu/src/links.cpp b/protocols/Gadu-Gadu/src/links.cpp index 02e4986236..295e9dbcf2 100644 --- a/protocols/Gadu-Gadu/src/links.cpp +++ b/protocols/Gadu-Gadu/src/links.cpp @@ -60,15 +60,13 @@ static INT_PTR gg_parselink(WPARAM, LPARAM lParam) GaduProto *gg = nullptr; int items = 0; - for (int i = 0; i < g_Instances.getCount(); i++) { - gg = g_Instances[i]; - - if (gg->m_iStatus > ID_STATUS_OFFLINE) { + for (auto &it : g_Instances) { + gg = it; + if (it->m_iStatus > ID_STATUS_OFFLINE) { ++items; - Menu_ModifyItem(gg->hInstanceMenuItem, nullptr, Skin_LoadProtoIcon(gg->m_szModuleName, gg->m_iStatus)); + Menu_ModifyItem(it->hInstanceMenuItem, nullptr, Skin_LoadProtoIcon(it->m_szModuleName, it->m_iStatus)); } - else - Menu_ShowItem(gg->hInstanceMenuItem, false); + else Menu_ShowItem(it->hInstanceMenuItem, false); } if (items > 1) { diff --git a/protocols/Gadu-Gadu/src/oauth.cpp b/protocols/Gadu-Gadu/src/oauth.cpp index da0df144b6..cfe7942297 100644 --- a/protocols/Gadu-Gadu/src/oauth.cpp +++ b/protocols/Gadu-Gadu/src/oauth.cpp @@ -82,7 +82,6 @@ char *oauth_uri_escape(const char *str) char *oauth_generate_signature(LIST ¶ms, const char *httpmethod, const char *url) { char *res; - OAUTHPARAMETER *p; int ix = 0; if (httpmethod == nullptr || url == nullptr || !params.getCount()) return mir_strdup(""); @@ -103,10 +102,9 @@ char *oauth_generate_signature(LIST ¶ms, const char *httpmet mir_free(urlnorm); int size = (int)mir_strlen(httpmethod) + (int)mir_strlen(urlenc) + 1 + 2; - for (int i = 0; i < params.getCount(); i++) { - p = params[i]; + for (auto &p : params) { if (!mir_strcmp(p->name, "oauth_signature")) continue; - if (i > 0) size += 3; + if (p != params[0]) size += 3; size += (int)mir_strlen(p->name) + (int)mir_strlen(p->value) + 3; } @@ -117,10 +115,9 @@ char *oauth_generate_signature(LIST ¶ms, const char *httpmet mir_free(urlenc); mir_strcat(res, "&"); - for (int i = 0; i < params.getCount(); i++) { - p = params[i]; + for (auto &p : params) { if (!mir_strcmp(p->name, "oauth_signature")) continue; - if (i > 0) mir_strcat(res, "%26"); + if (p != params[0]) mir_strcat(res, "%26"); mir_strcat(res, p->name); mir_strcat(res, "%3D"); mir_strcat(res, p->value); @@ -136,11 +133,9 @@ char *oauth_getparam(LIST ¶ms, const char *name) if (name == nullptr) return nullptr; - for (int i = 0; i < params.getCount(); i++) { - p = params[i]; + for (auto &p : params) if (!mir_strcmp(p->name, name)) return p->value; - } return nullptr; } @@ -152,14 +147,12 @@ void oauth_setparam(LIST ¶ms, const char *name, const char * if (name == nullptr) return; - for (int i = 0; i < params.getCount(); i++) { - p = params[i]; + for (auto &p : params) if (!mir_strcmp(p->name, name)) { mir_free(p->value); p->value = oauth_uri_escape(value); return; } - } p = (OAUTHPARAMETER*)mir_alloc(sizeof(OAUTHPARAMETER)); p->name = oauth_uri_escape(name); @@ -169,10 +162,7 @@ void oauth_setparam(LIST ¶ms, const char *name, const char * void oauth_freeparams(LIST ¶ms) { - OAUTHPARAMETER *p; - - for (int i = 0; i < params.getCount(); i++) { - p = params[i]; + for (auto &p : params) { mir_free(p->name); mir_free(p->value); } @@ -236,8 +226,6 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD const char *consumer_key, const char *consumer_secret, const char *token, const char *token_secret) { - char *res, timestamp[22]; - if (httpmethod == nullptr || url == nullptr) return nullptr; @@ -257,6 +245,8 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD oauth_setparam(oauth_parameters, "oauth_signature_method", "PLAINTEXT"); break; }; + + char timestamp[22]; mir_snprintf(timestamp, "%ld", time(nullptr)); oauth_setparam(oauth_parameters, "oauth_timestamp", timestamp); oauth_setparam(oauth_parameters, "oauth_nonce", ptrA(oauth_generate_nonce())); @@ -268,27 +258,18 @@ char *oauth_auth_header(const char *httpmethod, const char *url, OAUTHSIGNMETHOD return nullptr; } - int size = 7; - for (int i = 0; i < oauth_parameters.getCount(); i++) { - OAUTHPARAMETER *p = oauth_parameters[i]; - if (i > 0) size++; - size += (int)mir_strlen(p->name) + (int)mir_strlen(p->value) + 3; - } - - res = (char *)mir_alloc(size); - mir_strcpy(res, "OAuth "); - - for (int i = 0; i < oauth_parameters.getCount(); i++) { - OAUTHPARAMETER *p = oauth_parameters[i]; - if (i > 0) mir_strcat(res, ","); - mir_strcat(res, p->name); - mir_strcat(res, "=\""); - mir_strcat(res, p->value); - mir_strcat(res, "\""); + CMStringA res("OAuth "); + for (auto &p : oauth_parameters) { + if (res.GetLength() > 6) + res.AppendChar(','); + res.Append(p->name); + res.Append("=\""); + res.Append(p->value); + res.Append("\""); } oauth_freeparams(oauth_parameters); - return res; + return res.Detach(); } int GaduProto::oauth_receivetoken() diff --git a/protocols/MRA/src/MraProto.cpp b/protocols/MRA/src/MraProto.cpp index 980313d4fd..03cd7f2336 100644 --- a/protocols/MRA/src/MraProto.cpp +++ b/protocols/MRA/src/MraProto.cpp @@ -2,8 +2,8 @@ static int MraExtraIconsApplyAll(WPARAM, LPARAM) { - for (int i = 0; i < g_Instances.getCount(); i++) - g_Instances[i]->MraExtraIconsApply(0, 0); + for (auto &it : g_Instances) + it->MraExtraIconsApply(0, 0); return 0; } diff --git a/protocols/MRA/src/Mra_functions.cpp b/protocols/MRA/src/Mra_functions.cpp index dd1768c5c3..7acb2c8b80 100644 --- a/protocols/MRA/src/Mra_functions.cpp +++ b/protocols/MRA/src/Mra_functions.cpp @@ -47,14 +47,14 @@ static DWORD GetParamValue(const CMStringA &szData, LPCSTR szParamName, DWORD dw LPSTR lpszParamDataStart = strstr(tmp, szParamName); if (lpszParamDataStart) - if ((*((WORD*)(lpszParamDataStart + dwParamNameSize))) == (*((WORD*)"=\""))) { - lpszParamDataStart += dwParamNameSize + 2; - LPSTR lpszParamDataEnd = strchr(lpszParamDataStart, '"'); - if (lpszParamDataEnd) { - szParamValue = CMStringA(szData.c_str() + (lpszParamDataStart - tmp), lpszParamDataEnd - lpszParamDataStart); - return NO_ERROR; + if ((*((WORD*)(lpszParamDataStart + dwParamNameSize))) == (*((WORD*)"=\""))) { + lpszParamDataStart += dwParamNameSize + 2; + LPSTR lpszParamDataEnd = strchr(lpszParamDataStart, '"'); + if (lpszParamDataEnd) { + szParamValue = CMStringA(szData.c_str() + (lpszParamDataStart - tmp), lpszParamDataEnd - lpszParamDataStart); + return NO_ERROR; + } } - } return ERROR_NOT_FOUND; } @@ -66,10 +66,10 @@ CMStringA MraGetVersionStringFromFormatted(const CMStringA &szUserAgentFormatted CMStringA res, tmp; if (!GetParamValue(szUserAgentFormatted, "name", 4, tmp)) - if (tmp == "Miranda IM" || tmp == "Miranda NG") { - GetParamValue(szUserAgentFormatted, "title", 5, res); - return res; - } + if (tmp == "Miranda IM" || tmp == "Miranda NG") { + GetParamValue(szUserAgentFormatted, "title", 5, res); + return res; + } if (!GetParamValue(szUserAgentFormatted, "client", 6, tmp)) { if (tmp == "wmagent") @@ -184,7 +184,7 @@ void MraAddrListFree(MRA_ADDR_LIST *pmalAddrList) bool DB_GetStaticStringA(MCONTACT hContact, LPCSTR lpszModule, LPCSTR lpszValueName, LPSTR lpszRetBuff, size_t dwRetBuffSize, size_t *pdwRetBuffSize) { bool bRet = false; - + DBVARIANT dbv = { 0 }; if (db_get_ws(hContact, lpszModule, lpszValueName, &dbv) == 0) { size_t dwRetBuffSizeLocal, dwReadedStringLen = mir_wstrlen(dbv.pwszVal); @@ -217,7 +217,7 @@ bool DB_GetStaticStringW(MCONTACT hContact, LPCSTR lpszModule, LPCSTR lpszValueN if (db_get_ws(hContact, lpszModule, lpszValueName, &dbv) == 0) { dwReadedStringLen = mir_wstrlen(dbv.pwszVal); if (lpwszRetBuff && (dwRetBuffSize > dwReadedStringLen)) { - memcpy(lpwszRetBuff, dbv.pszVal, (dwReadedStringLen*sizeof(WCHAR)));//include null terminated + memcpy(lpwszRetBuff, dbv.pszVal, (dwReadedStringLen * sizeof(WCHAR)));//include null terminated (*((WCHAR*)(lpwszRetBuff + dwReadedStringLen))) = 0; bRet = true; } @@ -307,11 +307,11 @@ DWORD CMraProto::MraMoveContactToGroup(MCONTACT hContact, DWORD dwGroupID, LPCTS { MraGroupItem *p = NULL; - for (int i = 0; i < m_groups.getCount(); i++) - if (m_groups[i].m_name == ptszName) { - p = &m_groups[i]; - break; - } + for (auto &it : m_groups) + if (it->m_name == ptszName) { + p = it; + break; + } if (p == NULL) { if (m_groups.getCount() == 20) @@ -319,8 +319,8 @@ DWORD CMraProto::MraMoveContactToGroup(MCONTACT hContact, DWORD dwGroupID, LPCTS DWORD id; for (id = 0; id < 20; id++) - if (m_groups.find((MraGroupItem*)&id) == NULL) - break; + if (m_groups.find((MraGroupItem*)&id) == NULL) + break; DWORD dwContactFlags = CONTACT_FLAG_UNICODE_NAME | CONTACT_FLAG_GROUP | (id << 24); p = new MraGroupItem(id, dwContactFlags, ptszName); @@ -346,8 +346,8 @@ DWORD CMraProto::GetContactFlags(MCONTACT hContact) CMStringA szEmail; if (mraGetStringA(hContact, "e-mail", szEmail)) - if (IsEMailChatAgent(szEmail)) - dwRet |= CONTACT_FLAG_MULTICHAT; + if (IsEMailChatAgent(szEmail)) + dwRet |= CONTACT_FLAG_MULTICHAT; if (db_get_b(hContact, "CList", "Hidden", 0)) dwRet |= CONTACT_FLAG_SHADOW; @@ -512,12 +512,12 @@ MCONTACT CMraProto::MraHContactFromEmail(const CMStringA &szEmail, BOOL bAddIfNe CMStringA szEMailLocal; for (hContact = db_find_first(m_szModuleName); hContact; hContact = db_find_next(hContact, m_szModuleName)) { if (mraGetStringA(hContact, "e-mail", szEMailLocal)) - if (szEMailLocal == szEmail) { - if (bTemporary == FALSE) - db_unset(hContact, "CList", "NotOnList"); - bFound = true; - break; - } + if (szEMailLocal == szEmail) { + if (bTemporary == FALSE) + db_unset(hContact, "CList", "NotOnList"); + bFound = true; + break; + } } if (!bFound && bAddIfNeeded) { @@ -557,14 +557,14 @@ MCONTACT CMraProto::MraHContactFromEmail(const CMStringA &szEmail, BOOL bAddIfNe bool CMraProto::MraUpdateContactInfo(MCONTACT hContact) { if (m_bLoggedIn && hContact) - if (IsContactMra(hContact)) { - CMStringA szEmail; - if (mraGetStringA(hContact, "e-mail", szEmail)) { - MraAvatarsQueueGetAvatarSimple(hAvatarsQueueHandle, GAIF_FORCE, hContact); - if (MraWPRequestByEMail(hContact, ACKTYPE_GETINFO, szEmail)) - return true; + if (IsContactMra(hContact)) { + CMStringA szEmail; + if (mraGetStringA(hContact, "e-mail", szEmail)) { + MraAvatarsQueueGetAvatarSimple(hAvatarsQueueHandle, GAIF_FORCE, hContact); + if (MraWPRequestByEMail(hContact, ACKTYPE_GETINFO, szEmail)) + return true; + } } - } return false; } @@ -671,7 +671,7 @@ void CMraProto::MraUpdateEmailStatus(const CMStringA &pszFrom, const CMStringA & else MraPopupShowFromAgentW(MRA_POPUP_TYPE_EMAIL_STATUS, szStatusText); } else { - if ( !force_display && getByte("IncrementalNewMailNotify", MRA_DEFAULT_INC_NEW_MAIL_NOTIFY)) { + if (!force_display && getByte("IncrementalNewMailNotify", MRA_DEFAULT_INC_NEW_MAIL_NOTIFY)) { if (bTrayIconNewMailNotify) pcli->pfnRemoveEvent(0, (LPARAM)m_szModuleName); PUDeletePopup(hWndEMailPopupStatus); @@ -707,8 +707,8 @@ bool IsContactMraProto(MCONTACT hContact) if (lpszProto) { CMStringW szBuff; if (DB_GetStringW(hContact, lpszProto, "AvatarLastCheckTime", szBuff)) - if (DB_GetStringW(hContact, lpszProto, "AvatarLastModifiedTime", szBuff)) - return true; + if (DB_GetStringW(hContact, lpszProto, "AvatarLastModifiedTime", szBuff)) + return true; } return false; } @@ -719,8 +719,8 @@ bool CMraProto::IsEMailMy(const CMStringA &szEmail) CMStringA szEmailMy; if (mraGetStringA(NULL, "e-mail", szEmailMy)) { if (szEmail.GetLength() == szEmailMy.GetLength()) - if (!_stricmp(szEmail, szEmailMy)) - return true; + if (!_stricmp(szEmail, szEmailMy)) + return true; } } return false; @@ -752,9 +752,9 @@ bool IsEMailMR(const CMStringA &szEmail) for (int i = 0; lpcszMailRuDomains[i]; i++) { size_t dwDomainLen = mir_strlen(lpcszMailRuDomains[i]); if (dwDomainLen < szEmail.GetLength()) - if (!_stricmp(lpcszMailRuDomains[i], szEmail.c_str() + szEmail.GetLength() - dwDomainLen)) - if (szEmail[szEmail.GetLength() - (int)dwDomainLen - 1] == '@') - return true; + if (!_stricmp(lpcszMailRuDomains[i], szEmail.c_str() + szEmail.GetLength() - dwDomainLen)) + if (szEmail[szEmail.GetLength() - (int)dwDomainLen - 1] == '@') + return true; } } return false; @@ -819,10 +819,10 @@ bool GetContactFirstEMailParam(MCONTACT hContact, BOOL bMRAOnly, LPSTR lpszModul CMStringA szEmail; if (DB_GetStringA(hContact, lpszModule, lpszValueName, szEmail)) - if (bMRAOnly == FALSE || IsEMailMR(szEmail)) { - res = szEmail; - return true; - } + if (bMRAOnly == FALSE || IsEMailMR(szEmail)) { + res = szEmail; + return true; + } for (int i = 0; true; i++) { char szBuff[100]; @@ -874,7 +874,7 @@ static void FakeThread(void* param) { Thread_SetName("MRA: ProtoBroadcastAckAsync"); Sleep(100); - + ACKDATA *ack = (ACKDATA*)param; ProtoBroadcastAck(ack->szModule, ack->hContact, ack->type, ack->result, ack->hProcess, ack->lParam); mir_free(param); @@ -937,20 +937,20 @@ void EnableControlsArray(HWND hWndDlg, WORD *pwControlsList, size_t dwControlsLi static LRESULT CALLBACK MessageEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { if (msg == WM_CHAR) - if (GetKeyState(VK_CONTROL) & 0x8000) { - if (wParam == '\n') { - PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); - return 0; - } - if (wParam == 1) { // ctrl-a - SendMessage(hwnd, EM_SETSEL, 0, -1); - return 0; - } - if (wParam == 23) { // ctrl-w - SendMessage(GetParent(hwnd), WM_CLOSE, 0, 0); - return 0; + if (GetKeyState(VK_CONTROL) & 0x8000) { + if (wParam == '\n') { + PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); + return 0; + } + if (wParam == 1) { // ctrl-a + SendMessage(hwnd, EM_SETSEL, 0, -1); + return 0; + } + if (wParam == 23) { // ctrl-w + SendMessage(GetParent(hwnd), WM_CLOSE, 0, 0); + return 0; + } } - } return mir_callNextSubclass(hwnd, MessageEditSubclassProc, msg, wParam, lParam); } @@ -1109,7 +1109,7 @@ INT_PTR CALLBACK SendReplyBlogStatusDlgProc(HWND hWndDlg, UINT message, WPARAM w DWORD dwTime = dat->ppro->getDword(dat->hContact, DBSETTING_BLOGSTATUSTIME, 0); if (dwTime && MakeLocalSystemTimeFromTime32(dwTime, &stBlogStatusTime)) szBuff.Format(L"%s: %04ld.%02ld.%02ld %02ld:%02ld", TranslateT("Written"), - stBlogStatusTime.wYear, stBlogStatusTime.wMonth, stBlogStatusTime.wDay, stBlogStatusTime.wHour, stBlogStatusTime.wMinute); + stBlogStatusTime.wYear, stBlogStatusTime.wMonth, stBlogStatusTime.wDay, stBlogStatusTime.wHour, stBlogStatusTime.wMinute); else szBuff.Empty(); @@ -1202,8 +1202,8 @@ DWORD GetYears(CONST PSYSTEMTIME pcstSystemTime) // др в этом месяце if (stTime.wMonth == pcstSystemTime->wMonth) // ещё только будет, не сегодня - if (stTime.wDay < pcstSystemTime->wDay) - dwRet--; + if (stTime.wDay < pcstSystemTime->wDay) + dwRet--; } } return dwRet; @@ -1225,10 +1225,10 @@ DWORD FindFile(LPWSTR lpszFolder, DWORD dwFolderLen, LPWSTR lpszFileName, DWORD dwRecDeepCurPos = 0; dwRecDeepAllocated = RECURSION_DATA_STACK_ITEMS_MIN; - prdsiItems = (RECURSION_DATA_STACK_ITEM*)mir_calloc(dwRecDeepAllocated*sizeof(RECURSION_DATA_STACK_ITEM)); + prdsiItems = (RECURSION_DATA_STACK_ITEM*)mir_calloc(dwRecDeepAllocated * sizeof(RECURSION_DATA_STACK_ITEM)); if (prdsiItems) { dwPathLen = dwFolderLen; - memcpy(szPath, lpszFolder, (dwPathLen*sizeof(WCHAR))); + memcpy(szPath, lpszFolder, (dwPathLen * sizeof(WCHAR))); if (szPath[(dwPathLen - 1)] != '\\') { szPath[dwPathLen] = '\\'; dwPathLen++; @@ -1246,35 +1246,35 @@ DWORD FindFile(LPWSTR lpszFolder, DWORD dwFolderLen, LPWSTR lpszFileName, DWORD while (dwRetErrorCode == ERROR_FILE_NOT_FOUND && FindNextFile(prdsiItems[dwRecDeepCurPos].hFind, &prdsiItems[dwRecDeepCurPos].w32fdFindFileData)) { if (prdsiItems[dwRecDeepCurPos].w32fdFindFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) {// folder if (CompareString(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName, -1, L".", 1) != CSTR_EQUAL) - if (CompareString(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName, -1, L"..", 2) != CSTR_EQUAL) { - prdsiItems[dwRecDeepCurPos].dwFileNameLen = (int)mir_wstrlen(prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName) + 1; - memcpy((szPath + dwPathLen), prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName, (prdsiItems[dwRecDeepCurPos].dwFileNameLen*sizeof(WCHAR))); - mir_wstrcat(szPath, L"\\*.*"); - dwPathLen += prdsiItems[dwRecDeepCurPos].dwFileNameLen; - - dwRecDeepCurPos++; - if (dwRecDeepCurPos == dwRecDeepAllocated) { // need more space - dwRecDeepAllocated += RECURSION_DATA_STACK_ITEMS_MIN; - prdsiItems = (RECURSION_DATA_STACK_ITEM*)mir_realloc(prdsiItems, dwRecDeepAllocated*sizeof(RECURSION_DATA_STACK_ITEM)); - if (prdsiItems == NULL) { - dwRecDeepCurPos = 0; - dwRetErrorCode = GetLastError(); - break; + if (CompareString(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName, -1, L"..", 2) != CSTR_EQUAL) { + prdsiItems[dwRecDeepCurPos].dwFileNameLen = (int)mir_wstrlen(prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName) + 1; + memcpy((szPath + dwPathLen), prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName, (prdsiItems[dwRecDeepCurPos].dwFileNameLen * sizeof(WCHAR))); + mir_wstrcat(szPath, L"\\*.*"); + dwPathLen += prdsiItems[dwRecDeepCurPos].dwFileNameLen; + + dwRecDeepCurPos++; + if (dwRecDeepCurPos == dwRecDeepAllocated) { // need more space + dwRecDeepAllocated += RECURSION_DATA_STACK_ITEMS_MIN; + prdsiItems = (RECURSION_DATA_STACK_ITEM*)mir_realloc(prdsiItems, dwRecDeepAllocated * sizeof(RECURSION_DATA_STACK_ITEM)); + if (prdsiItems == NULL) { + dwRecDeepCurPos = 0; + dwRetErrorCode = GetLastError(); + break; + } } + prdsiItems[dwRecDeepCurPos].hFind = FindFirstFileEx(szPath, FindExInfoStandard, &prdsiItems[dwRecDeepCurPos].w32fdFindFileData, FindExSearchNameMatch, NULL, 0); } - prdsiItems[dwRecDeepCurPos].hFind = FindFirstFileEx(szPath, FindExInfoStandard, &prdsiItems[dwRecDeepCurPos].w32fdFindFileData, FindExSearchNameMatch, NULL, 0); - } } else {// file if (CompareString(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), NORM_IGNORECASE, prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName, -1, lpszFileName, dwFileNameLen) == CSTR_EQUAL) { prdsiItems[dwRecDeepCurPos].dwFileNameLen = (int)mir_wstrlen(prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName); - memcpy((szPath + dwPathLen), prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName, ((prdsiItems[dwRecDeepCurPos].dwFileNameLen + 1)*sizeof(WCHAR))); + memcpy((szPath + dwPathLen), prdsiItems[dwRecDeepCurPos].w32fdFindFileData.cFileName, ((prdsiItems[dwRecDeepCurPos].dwFileNameLen + 1) * sizeof(WCHAR))); dwFilePathLen = (dwPathLen + prdsiItems[dwRecDeepCurPos].dwFileNameLen); if (pdwRetFilePathLen) (*pdwRetFilePathLen) = dwFilePathLen; if (lpszRetFilePathName && dwRetFilePathLen) { dwFilePathLen = min(dwFilePathLen, dwRetFilePathLen); - memcpy(lpszRetFilePathName, szPath, ((dwFilePathLen + 1)*sizeof(WCHAR))); + memcpy(lpszRetFilePathName, szPath, ((dwFilePathLen + 1) * sizeof(WCHAR))); } dwRetErrorCode = NO_ERROR; @@ -1284,8 +1284,7 @@ DWORD FindFile(LPWSTR lpszFolder, DWORD dwFolderLen, LPWSTR lpszFileName, DWORD if (prdsiItems) FindClose(prdsiItems[dwRecDeepCurPos].hFind); dwRecDeepCurPos--; - } - while (dwRecDeepCurPos != -1); + } while (dwRecDeepCurPos != -1); } mir_free(prdsiItems); } @@ -1309,43 +1308,43 @@ bool CMraProto::GetPassDB(CMStringA &res) CMStringA szEmail; if (mraGetContactSettingBlob(NULL, "pCryptData", btRandomData, sizeof(btRandomData), &dwRandomDataSize)) - if (dwRandomDataSize == sizeof(btRandomData)) - if (mraGetContactSettingBlob(NULL, "pCryptPass", btCryptedPass, sizeof(btCryptedPass), &dwCryptedPass)) - if (dwCryptedPass == sizeof(btCryptedPass)) - if (mraGetStringA(NULL, "e-mail", szEmail)) { - mir_hmac_sha1(bthmacSHA1, (BYTE*)szEmail.c_str(), szEmail.GetLength(), btRandomData, sizeof(btRandomData)); - - if (storageType == 2) { - RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE); - CopyMemoryReverseDWORD(btCryptedPass, btCryptedPass, sizeof(btCryptedPass)); - RC4(btCryptedPass, sizeof(btCryptedPass), btRandomData, dwRandomDataSize); - RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE); - - dwPassSize = btCryptedPass[0]; - SHA1GetDigest(&btCryptedPass[(1 + MIR_SHA1_HASH_SIZE)], dwPassSize, btRandomData); - if (0 != memcmp(&btCryptedPass[1], btRandomData, MIR_SHA1_HASH_SIZE)) - return false; - - res = CMStringA((char*)&btCryptedPass[(1 + MIR_SHA1_HASH_SIZE)], (int)dwPassSize); - } - else if (storageType == 1) { - RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE); - CopyMemoryReverseDWORD(btCryptedPass, btCryptedPass, sizeof(btCryptedPass)); - RC4(btCryptedPass, sizeof(btCryptedPass), btRandomData, dwRandomDataSize); - RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE); - - dwPassSize = (*btCryptedPass); - btCryptedPass[dwPassSize + 1 + MIR_SHA1_HASH_SIZE] = 0; - - size_t dwDecodedSize; - mir_ptr pDecoded((PBYTE)mir_base64_decode((LPCSTR)&btCryptedPass[1 + MIR_SHA1_HASH_SIZE], &dwDecodedSize)); - SHA1GetDigest(pDecoded, dwDecodedSize, btRandomData); - if (0 != memcmp(&btCryptedPass[1], btRandomData, MIR_SHA1_HASH_SIZE)) - return false; - res = CMStringA((LPSTR)(PBYTE)pDecoded, dwDecodedSize); - } - else return false; - } + if (dwRandomDataSize == sizeof(btRandomData)) + if (mraGetContactSettingBlob(NULL, "pCryptPass", btCryptedPass, sizeof(btCryptedPass), &dwCryptedPass)) + if (dwCryptedPass == sizeof(btCryptedPass)) + if (mraGetStringA(NULL, "e-mail", szEmail)) { + mir_hmac_sha1(bthmacSHA1, (BYTE*)szEmail.c_str(), szEmail.GetLength(), btRandomData, sizeof(btRandomData)); + + if (storageType == 2) { + RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE); + CopyMemoryReverseDWORD(btCryptedPass, btCryptedPass, sizeof(btCryptedPass)); + RC4(btCryptedPass, sizeof(btCryptedPass), btRandomData, dwRandomDataSize); + RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE); + + dwPassSize = btCryptedPass[0]; + SHA1GetDigest(&btCryptedPass[(1 + MIR_SHA1_HASH_SIZE)], dwPassSize, btRandomData); + if (0 != memcmp(&btCryptedPass[1], btRandomData, MIR_SHA1_HASH_SIZE)) + return false; + + res = CMStringA((char*)&btCryptedPass[(1 + MIR_SHA1_HASH_SIZE)], (int)dwPassSize); + } + else if (storageType == 1) { + RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE); + CopyMemoryReverseDWORD(btCryptedPass, btCryptedPass, sizeof(btCryptedPass)); + RC4(btCryptedPass, sizeof(btCryptedPass), btRandomData, dwRandomDataSize); + RC4(btCryptedPass, sizeof(btCryptedPass), bthmacSHA1, MIR_SHA1_HASH_SIZE); + + dwPassSize = (*btCryptedPass); + btCryptedPass[dwPassSize + 1 + MIR_SHA1_HASH_SIZE] = 0; + + size_t dwDecodedSize; + mir_ptr pDecoded((PBYTE)mir_base64_decode((LPCSTR)&btCryptedPass[1 + MIR_SHA1_HASH_SIZE], &dwDecodedSize)); + SHA1GetDigest(pDecoded, dwDecodedSize, btRandomData); + if (0 != memcmp(&btCryptedPass[1], btRandomData, MIR_SHA1_HASH_SIZE)) + return false; + res = CMStringA((LPSTR)(PBYTE)pDecoded, dwDecodedSize); + } + else return false; + } delSetting("pCryptData"); delSetting("pCryptPass"); @@ -1376,12 +1375,12 @@ static DWORD ReplaceInBuff(LPVOID lpInBuff, size_t dwInBuffSize, size_t dwReplac while (dwFoundCount) { for (i = 0; i < dwReplaceItemsCount; i++) - if (plpbtFounded[i] && (plpbtFounded[i] < plpbtFounded[dwFirstFoundIndex] || plpbtFounded[dwFirstFoundIndex] == NULL)) - dwFirstFoundIndex = i; + if (plpbtFounded[i] && (plpbtFounded[i] < plpbtFounded[dwFirstFoundIndex] || plpbtFounded[dwFirstFoundIndex] == NULL)) + dwFirstFoundIndex = i; if (plpbtFounded[dwFirstFoundIndex]) {// in found dwMemPartToCopy = (plpbtFounded[dwFirstFoundIndex] - lpbtInBuffCurPrev); - if (lpbtOutBuffMax>(lpbtOutBuffCur + (dwMemPartToCopy + pdwInReplaceItemsCounts[dwFirstFoundIndex]))) { + if (lpbtOutBuffMax > (lpbtOutBuffCur + (dwMemPartToCopy + pdwInReplaceItemsCounts[dwFirstFoundIndex]))) { memmove(lpbtOutBuffCur, lpbtInBuffCurPrev, dwMemPartToCopy); lpbtOutBuffCur += dwMemPartToCopy; memmove(lpbtOutBuffCur, plpOutReplaceItems[dwFirstFoundIndex], pdwOutReplaceItemsCounts[dwFirstFoundIndex]); lpbtOutBuffCur += pdwOutReplaceItemsCounts[dwFirstFoundIndex]; lpbtInBuffCurPrev = (plpbtFounded[dwFirstFoundIndex] + pdwInReplaceItemsCounts[dwFirstFoundIndex]); @@ -1426,7 +1425,7 @@ static const size_t dwXMLSymbolsCount[] = { sizeof(wchar_t), sizeof(wchar_t), si CMStringW DecodeXML(const CMStringW &lptszMessage) { CMStringW ret('\0', (lptszMessage.GetLength() * 4)); - ReplaceInBuff((void*)lptszMessage.GetString(), lptszMessage.GetLength()*sizeof(wchar_t), _countof(lpszXMLTags), (LPVOID*)lpszXMLTags, (size_t*)dwXMLTagsCount, (LPVOID*)lpszXMLSymbols, (size_t*)dwXMLSymbolsCount, ret); + ReplaceInBuff((void*)lptszMessage.GetString(), lptszMessage.GetLength() * sizeof(wchar_t), _countof(lpszXMLTags), (LPVOID*)lpszXMLTags, (size_t*)dwXMLTagsCount, (LPVOID*)lpszXMLSymbols, (size_t*)dwXMLSymbolsCount, ret); return ret; } @@ -1434,6 +1433,6 @@ CMStringW DecodeXML(const CMStringW &lptszMessage) CMStringW EncodeXML(const CMStringW &lptszMessage) { CMStringW ret('\0', (lptszMessage.GetLength() * 4)); - ReplaceInBuff((void*)lptszMessage.GetString(), lptszMessage.GetLength()*sizeof(wchar_t), _countof(lpszXMLTags), (LPVOID*)lpszXMLSymbols, (size_t*)dwXMLSymbolsCount, (LPVOID*)lpszXMLTags, (size_t*)dwXMLTagsCount, ret); + ReplaceInBuff((void*)lptszMessage.GetString(), lptszMessage.GetLength() * sizeof(wchar_t), _countof(lpszXMLTags), (LPVOID*)lpszXMLSymbols, (size_t*)dwXMLSymbolsCount, (LPVOID*)lpszXMLTags, (size_t*)dwXMLTagsCount, ret); return ret; } diff --git a/protocols/MRA/src/Mra_svcs.cpp b/protocols/MRA/src/Mra_svcs.cpp index 430bc38a1b..d06d267532 100644 --- a/protocols/MRA/src/Mra_svcs.cpp +++ b/protocols/MRA/src/Mra_svcs.cpp @@ -642,10 +642,9 @@ int CMraProto::OnGroupChanged(WPARAM hContact, LPARAM lParam) return 0; MraGroupItem *pGrp = nullptr; - for (int i = 0; i < m_groups.getCount(); i++) { - MraGroupItem &p = m_groups[i]; - if (!mir_wstrcmp(p.m_name, cgc->pszOldName)) { - pGrp = &p; + for (auto &it : m_groups) { + if (!mir_wstrcmp(it->m_name, cgc->pszOldName)) { + pGrp = it; break; } } diff --git a/protocols/Steam/src/steam_accounts.cpp b/protocols/Steam/src/steam_accounts.cpp index 43ec787c5f..8fedcc6181 100644 --- a/protocols/Steam/src/steam_accounts.cpp +++ b/protocols/Steam/src/steam_accounts.cpp @@ -27,9 +27,9 @@ CSteamProto* CSteamProto::GetContactAccount(MCONTACT hContact) if (proto == nullptr) return nullptr; - for (int i = 0; i < Accounts.getCount(); i++) - if (!mir_strcmp(proto, Accounts[i]->m_szModuleName)) - return Accounts[i]; + for (auto &it : Accounts) + if (!mir_strcmp(proto, it->m_szModuleName)) + return it; return nullptr; } \ No newline at end of file diff --git a/protocols/Tox/src/tox_accounts.cpp b/protocols/Tox/src/tox_accounts.cpp index 866a0dbd3b..ad948974a8 100644 --- a/protocols/Tox/src/tox_accounts.cpp +++ b/protocols/Tox/src/tox_accounts.cpp @@ -23,9 +23,10 @@ int CToxProto::UninitAccount(CToxProto *proto) CToxProto* CToxProto::GetContactAccount(MCONTACT hContact) { - for (int i = 0; i < Accounts.getCount(); i++) - if (mir_strcmpi(GetContactProto(hContact), Accounts[i]->m_szModuleName) == 0) - return Accounts[i]; + for (auto &it : Accounts) + if (mir_strcmpi(GetContactProto(hContact), it->m_szModuleName) == 0) + return it; + return nullptr; } diff --git a/protocols/Tox/src/tox_utils.cpp b/protocols/Tox/src/tox_utils.cpp index 130e08eaec..d7c2d1408b 100644 --- a/protocols/Tox/src/tox_utils.cpp +++ b/protocols/Tox/src/tox_utils.cpp @@ -150,9 +150,9 @@ INT_PTR CToxProto::ParseToxUri(WPARAM, LPARAM lParam) return 1; CToxProto *proto = nullptr; - for (int i = 0; i < Accounts.getCount(); i++) { - if (Accounts[i]->IsOnline()) { - proto = Accounts[i]; + for (auto &it : Accounts) { + if (it->IsOnline()) { + proto = it; break; } } diff --git a/protocols/Twitter/src/theme.cpp b/protocols/Twitter/src/theme.cpp index c7e7c69f55..ca6338edc7 100644 --- a/protocols/Twitter/src/theme.cpp +++ b/protocols/Twitter/src/theme.cpp @@ -63,9 +63,9 @@ static TwitterProto* GetInstanceByHContact(MCONTACT hContact) if (!proto) return nullptr; - for (int i = 0; i < g_Instances.getCount(); i++) - if (!mir_strcmp(proto, g_Instances[i].m_szModuleName)) - return &g_Instances[i]; + for (auto &it : g_Instances) + if (!mir_strcmp(proto, it->m_szModuleName)) + return it; return nullptr; } -- cgit v1.2.3