diff --git a/src/helper.hpp b/src/helper.hpp index cf5bd3f5..c6ff36f1 100644 --- a/src/helper.hpp +++ b/src/helper.hpp @@ -17,8 +17,8 @@ void _app_dereferencerule (PVOID pdata); void _app_dereferenceruleconfig (PVOID pdata); void _app_dereferencestring (PVOID pdata); -UINT _app_gettab_id (HWND hwnd, UINT page_id = UINT (-1)); -void _app_settab_id (HWND hwnd, UINT page_id); +INT _app_gettab_id (HWND hwnd, INT page_id = INVALID_INT); +void _app_settab_id (HWND hwnd, INT page_id); bool _app_initinterfacestate (HWND hwnd); void _app_restoreinterfacestate (HWND hwnd, bool is_enabled); @@ -34,9 +34,9 @@ void _app_freeobjects_vec (OBJECTS_VEC& ptr_vec, OBJECT_CLEANUP_CALLBACK cleanup void _app_freethreadpool (THREADS_VEC* ptr_pool); void _app_freelogstack (); -void _app_getappicon (ITEM_APP* ptr_app, bool is_small, size_t* picon_id, HICON* picon); +void _app_getappicon (ITEM_APP* ptr_app, bool is_small, PINT picon_id, HICON* picon); void _app_getdisplayname (size_t app_hash, ITEM_APP* ptr_app, LPWSTR* extracted_name); -bool _app_getfileicon (LPCWSTR path, bool is_small, size_t* picon_id, HICON* picon); +bool _app_getfileicon (LPCWSTR path, bool is_small, PINT picon_id, HICON* picon); rstring _app_getshortcutpath (HWND hwnd, LPCWSTR path); PR_OBJECT _app_getsignatureinfo (size_t app_hash, PITEM_APP ptr_app); PR_OBJECT _app_getversioninfo (size_t app_hash, PITEM_APP ptr_app); @@ -53,7 +53,7 @@ void _app_generate_rulesmenu (HMENU hsubmenu, size_t app_hash); bool _app_item_get (EnumDataType type, size_t app_hash, rstring* display_name, rstring* real_path, PBYTE* lpdata); INT CALLBACK _app_listviewcompare_callback (LPARAM lp1, LPARAM lp2, LPARAM lparam); -void _app_listviewsort (HWND hwnd, UINT listview_id, INT column = -1, bool is_notifycode = false); +void _app_listviewsort (HWND hwnd, INT listview_id, INT column_id = INVALID_INT, bool is_notifycode = false); void _app_refreshstatus (HWND hwnd); @@ -66,10 +66,10 @@ bool _app_parserulestring (rstring rule, PITEM_ADDRESS ptr_addr); bool _app_resolveaddress (ADDRESS_FAMILY af, LPVOID paddr, LPWSTR* pbuffer); void _app_resolvefilename (rstring& path); -UINT _app_getlistview_id (EnumDataType type); +INT _app_getlistview_id (EnumDataType type); -size_t _app_getposition (HWND hwnd, UINT listview_id, size_t lparam); -void _app_showitem (HWND hwnd, UINT listview_id, size_t item, INT scroll_pos = -1); +INT _app_getposition (HWND hwnd, INT listview_id, size_t lparam); +void _app_showitem (HWND hwnd, INT listview_id, INT item, INT scroll_pos = -1); HBITMAP _app_bitmapfromico (HICON hicon, INT icon_size); HBITMAP _app_bitmapfrompng (HINSTANCE hinst, LPCWSTR name, INT icon_size); diff --git a/src/log.cpp b/src/log.cpp index 616dc4ca..8316ce90 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -864,7 +864,7 @@ UINT WINAPI LogThread (LPVOID lparam) _r_fastlock_releaseshared (&lock_logbusy); - UINT app_listview_id = 0; + INT app_listview_id = 0; if (_app_getappinfo (app_hash, InfoListviewId, &app_listview_id, sizeof (app_listview_id)) && app_listview_id == _app_gettab_id (hwnd)) _app_listviewsort (hwnd, app_listview_id); diff --git a/src/main.cpp b/src/main.cpp index 1321df04..81ecd0d7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,7 +45,7 @@ EXTERN_C const IID IID_IImageList2; const UINT WM_FINDMSGSTRING = RegisterWindowMessage (FINDMSGSTRING); -void _app_listviewresize (HWND hwnd, UINT listview_id, bool is_forced = false) +void _app_listviewresize (HWND hwnd, INT listview_id, bool is_forced = false) { if (!listview_id || (!is_forced && !app.ConfigGet (L"AutoSizeColumns", true).AsBool ())) return; @@ -59,8 +59,8 @@ void _app_listviewresize (HWND hwnd, UINT listview_id, bool is_forced = false) const HWND hlistview = GetDlgItem (hwnd, listview_id); const HWND hheader = (HWND)SendMessage (hlistview, LVM_GETHEADER, 0, 0); - const UINT column_count = _r_listview_getcolumncount (hwnd, listview_id); - const size_t item_count = _r_listview_getitemcount (hwnd, listview_id); + const INT column_count = _r_listview_getcolumncount (hwnd, listview_id); + const INT item_count = _r_listview_getitemcount (hwnd, listview_id); const bool is_tableview = (SendMessage (hlistview, LVM_GETVIEW, 0, 0) == LV_VIEW_DETAILS); const HDC hdc_listview = GetDC (hlistview); @@ -77,7 +77,7 @@ void _app_listviewresize (HWND hwnd, UINT listview_id, bool is_forced = false) INT column_width; INT calculated_width = 0; - for (UINT i = column_count - 1; i != UINT (-1); i--) + for (INT i = column_count - 1; i != -1; i--) { if (i == 0) { @@ -97,7 +97,7 @@ void _app_listviewresize (HWND hwnd, UINT listview_id, bool is_forced = false) if (is_tableview) { - for (size_t j = 0; j < item_count; j++) + for (INT j = 0; j < item_count; j++) { const rstring item_text = _r_listview_getitemtext (hwnd, listview_id, j, i); const INT text_width = _r_dc_fontwidth (hdc_listview, item_text, item_text.GetLength ()) + caption_spacing; @@ -119,7 +119,7 @@ void _app_listviewresize (HWND hwnd, UINT listview_id, bool is_forced = false) ReleaseDC (hheader, hdc_header); } -void _app_listviewsetview (HWND hwnd, UINT listview_id) +void _app_listviewsetview (HWND hwnd, INT listview_id) { const bool is_mainview = (listview_id != IDC_APPS_LV) && (listview_id != IDC_NETWORK); const bool is_tableview = !is_mainview || app.ConfigGet (L"IsTableView", true).AsBool (); @@ -207,7 +207,7 @@ bool _app_listviewinitfont (PLOGFONT plf) return true; } -void _app_listviewsetfont (HWND hwnd, UINT ctrl_id, bool is_redraw) +void _app_listviewsetfont (HWND hwnd, INT listview_id, bool is_redraw) { LOGFONT lf = {0}; @@ -225,7 +225,7 @@ void _app_listviewsetfont (HWND hwnd, UINT ctrl_id, bool is_redraw) } if (config.hfont) - SendDlgItemMessage (hwnd, ctrl_id, WM_SETFONT, (WPARAM)config.hfont, TRUE); + SendDlgItemMessage (hwnd, listview_id, WM_SETFONT, (WPARAM)config.hfont, TRUE); } COLORREF _app_getcolorvalue (size_t color_hash) @@ -256,7 +256,7 @@ COLORREF _app_getcolorvalue (size_t color_hash) return 0; } -COLORREF _app_getcolor (UINT listview_id, size_t app_hash) +COLORREF _app_getcolor (INT listview_id, size_t app_hash) { rstring color_value; @@ -396,9 +396,9 @@ UINT WINAPI NetworkMonitorThread (LPVOID lparam) if (ptr_network) { - const size_t item = _r_listview_getitemcount (hwnd, network_listview_id); + const INT item = _r_listview_getitemcount (hwnd, network_listview_id); - _r_listview_additem (hwnd, network_listview_id, item, 0, _r_path_extractfile (ptr_network->path), ptr_network->icon_id, LAST_VALUE, p.first); + _r_listview_additem (hwnd, network_listview_id, item, 0, _r_path_extractfile (ptr_network->path), ptr_network->icon_id, INVALID_INT, p.first); _r_listview_setitem (hwnd, network_listview_id, item, 1, ptr_network->local_fmt); _r_listview_setitem (hwnd, network_listview_id, item, 2, ptr_network->remote_fmt); @@ -408,16 +408,16 @@ UINT WINAPI NetworkMonitorThread (LPVOID lparam) // redraw listview item if (app.ConfigGet (L"IsHighlightConnection", true, L"colors").AsBool ()) { - UINT app_listview_id = 0; + INT app_listview_id = 0; if (_app_getappinfo (ptr_network->app_hash, InfoListviewId, &app_listview_id, sizeof (app_listview_id))) { if (IsWindowVisible (GetDlgItem (hwnd, app_listview_id))) { - const size_t app_item = _app_getposition (hwnd, app_listview_id, ptr_network->app_hash); + const INT item_pos = _app_getposition (hwnd, app_listview_id, ptr_network->app_hash); - if (app_item != LAST_VALUE) - _r_listview_redraw (hwnd, app_listview_id, app_item, app_item); + if (item_pos != INVALID_INT) + _r_listview_redraw (hwnd, app_listview_id, item_pos, item_pos); } } } @@ -428,7 +428,7 @@ UINT WINAPI NetworkMonitorThread (LPVOID lparam) is_refresh = true; } - for (size_t i = _r_listview_getitemcount (hwnd, network_listview_id) - 1; i != LAST_VALUE; i--) + for (INT i = _r_listview_getitemcount (hwnd, network_listview_id) - 1; i != INVALID_INT; i--) { const size_t network_hash = _r_listview_getitemlparam (hwnd, network_listview_id, i); @@ -440,16 +440,16 @@ UINT WINAPI NetworkMonitorThread (LPVOID lparam) if (app.ConfigGet (L"IsHighlightConnection", true, L"colors").AsBool ()) { size_t app_hash = _app_getnetworkapp (network_hash); - UINT app_listview_id = 0; + INT app_listview_id = 0; if (_app_getappinfo (app_hash, InfoListviewId, &app_listview_id, sizeof (app_listview_id))) { if (IsWindowVisible (GetDlgItem (hwnd, app_listview_id))) { - const size_t app_item = _app_getposition (hwnd, app_listview_id, app_hash); + const INT item_pos = _app_getposition (hwnd, app_listview_id, app_hash); - if (app_item != LAST_VALUE) - _r_listview_redraw (hwnd, app_listview_id, app_item, app_item); + if (item_pos != INVALID_INT) + _r_listview_redraw (hwnd, app_listview_id, item_pos, item_pos); } } } @@ -461,7 +461,7 @@ UINT WINAPI NetworkMonitorThread (LPVOID lparam) if (is_refresh) { - const UINT current_listview_id = _app_gettab_id (hwnd); + const INT current_listview_id = _app_gettab_id (hwnd); if (current_listview_id != network_listview_id) { @@ -490,7 +490,7 @@ bool _app_changefilters (HWND hwnd, bool is_install, bool is_forced) if (_wfp_isfiltersapplying ()) return false; - const UINT listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); _app_listviewsort (hwnd, listview_id); @@ -822,7 +822,7 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) // apps (apply to) { - size_t item = 0; + INT item = 0; _r_fastlock_acquireshared (&lock_access); @@ -858,7 +858,7 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_fastlock_acquireshared (&lock_checkbox); - _r_listview_additem (hwnd, IDC_APPS_LV, item, 0, _r_path_extractfile (ptr_app->display_name), ptr_app->icon_id, LAST_VALUE, p.first); + _r_listview_additem (hwnd, IDC_APPS_LV, item, 0, _r_path_extractfile (ptr_app->display_name), ptr_app->icon_id, INVALID_INT, p.first); _r_listview_setitemcheck (hwnd, IDC_APPS_LV, item, is_enabled); _r_fastlock_releaseshared (&lock_checkbox); @@ -1063,7 +1063,7 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (_r_fastlock_islocked (&lock_checkbox)) break; - const bool is_havechecks = _r_listview_getitemcount (hwnd, IDC_APPS_LV, true); + const bool is_havechecks = !!_r_listview_getitemcount (hwnd, IDC_APPS_LV, true); CheckRadioButton (hwnd, IDC_DISABLE_CHK, IDC_ENABLEFORAPPS_CHK, is_havechecks ? IDC_ENABLEFORAPPS_CHK : IDC_DISABLE_CHK); _app_listviewsort (hwnd, IDC_APPS_LV); @@ -1077,9 +1077,9 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (_r_fastlock_tryacquireshared (&lock_access)) { LPNMLVGETINFOTIP lpnmlv = (LPNMLVGETINFOTIP)lparam; - const size_t idx = (size_t)_r_listview_getitemlparam (hwnd, (UINT)lpnmlv->hdr.idFrom, lpnmlv->iItem); + const size_t idx = _r_listview_getitemlparam (hwnd, (INT)lpnmlv->hdr.idFrom, lpnmlv->iItem); - StringCchCopy (lpnmlv->pszText, lpnmlv->cchTextMax, _app_gettooltip ((UINT)lpnmlv->hdr.idFrom, idx)); + StringCchCopy (lpnmlv->pszText, lpnmlv->cchTextMax, _app_gettooltip ((INT)lpnmlv->hdr.idFrom, idx)); _r_fastlock_releaseshared (&lock_access); } @@ -1118,11 +1118,11 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_UNCHECK: { const bool new_val = (LOWORD (wparam) == IDM_CHECK) ? true : false; - size_t item = LAST_VALUE; + INT item = INVALID_INT; _r_fastlock_acquireshared (&lock_checkbox); - while ((item = (size_t)SendDlgItemMessage (hwnd, IDC_APPS_LV, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) + while ((item = (INT)SendDlgItemMessage (hwnd, IDC_APPS_LV, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != INVALID_INT) _r_listview_setitemcheck (hwnd, IDC_APPS_LV, item, new_val); _r_fastlock_releaseshared (&lock_checkbox); @@ -1236,9 +1236,9 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) const bool is_enable = (IsDlgButtonChecked (hwnd, IDC_ENABLE_CHK) != BST_CHECKED); - for (size_t i = 0; i < _r_listview_getitemcount (hwnd, IDC_APPS_LV); i++) + for (INT i = 0; i < _r_listview_getitemcount (hwnd, IDC_APPS_LV); i++) { - const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, IDC_APPS_LV, i); + const size_t app_hash = _r_listview_getitemlparam (hwnd, IDC_APPS_LV, i); if (_app_isappfound (app_hash)) { @@ -1281,7 +1281,7 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) return FALSE; } -void _app_config_apply (HWND hwnd, UINT ctrl_id) +void _app_config_apply (HWND hwnd, INT ctrl_id) { bool new_val; @@ -1628,6 +1628,8 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam _r_listview_addcolumn (hwnd, IDC_COLORS, 0, app.LocaleString (IDS_NAME, nullptr), 0, LVCFMT_LEFT); + INT item = 0; + for (size_t i = 0; i < colors.size (); i++) { PR_OBJECT ptr_color_object = _r_obj_reference (colors.at (i)); @@ -1642,10 +1644,12 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam _r_fastlock_acquireshared (&lock_checkbox); - _r_listview_additem (hwnd, IDC_COLORS, i, 0, app.LocaleString (ptr_clr->locale_id, nullptr), config.icon_id, LAST_VALUE, i); - _r_listview_setitemcheck (hwnd, IDC_COLORS, i, app.ConfigGet (ptr_clr->pcfg_name, ptr_clr->is_enabled, L"colors").AsBool ()); + _r_listview_additem (hwnd, IDC_COLORS, item, 0, app.LocaleString (ptr_clr->locale_id, nullptr), config.icon_id, INVALID_INT, i); + _r_listview_setitemcheck (hwnd, IDC_COLORS, item, app.ConfigGet (ptr_clr->pcfg_name, ptr_clr->is_enabled, L"colors").AsBool ()); _r_fastlock_releaseshared (&lock_checkbox); + + item += 1; } _r_obj_dereference (ptr_color_object, &_app_dereferencecolor); @@ -1790,9 +1794,9 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam SetDlgItemText (hwnd, IDC_COLORS_HINT, app.LocaleString (IDS_COLORS_HINT, nullptr)); - for (size_t i = 0; i < _r_listview_getitemcount (hwnd, IDC_COLORS); i++) + for (INT i = 0; i < _r_listview_getitemcount (hwnd, IDC_COLORS); i++) { - const size_t clr_idx = (size_t)_r_listview_getitemlparam (hwnd, IDC_COLORS, i); + const size_t clr_idx = _r_listview_getitemlparam (hwnd, IDC_COLORS, i); PR_OBJECT ptr_clr_object = _r_obj_reference (colors.at (clr_idx)); if (ptr_clr_object) @@ -1800,7 +1804,11 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam PITEM_COLOR ptr_clr = (PITEM_COLOR)ptr_clr_object->pdata; if (ptr_clr) + { + _r_fastlock_acquireshared (&lock_checkbox); _r_listview_setitem (hwnd, IDC_COLORS, i, 0, app.LocaleString (ptr_clr->locale_id, nullptr)); + _r_fastlock_releaseshared (&lock_checkbox); + } _r_obj_dereference (ptr_clr_object, &_app_dereferencecolor); } @@ -1945,7 +1953,7 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam if (lpnmlv->iItem == -1 || nmlp->idFrom != IDC_COLORS) break; - const size_t idx = (size_t)_r_listview_getitemlparam (hwnd, (UINT)nmlp->idFrom, lpnmlv->iItem); + const size_t idx = _r_listview_getitemlparam (hwnd, (INT)nmlp->idFrom, lpnmlv->iItem); PR_OBJECT ptr_clr_object_current = _r_obj_reference (colors.at (idx)); PITEM_COLOR ptr_clr_current = nullptr; @@ -2355,7 +2363,7 @@ void _app_resizewindow (HWND hwnd, INT width, INT height) _r_wnd_resize (&hdefer, GetDlgItem (hwnd, IDC_TAB), nullptr, 0, rebar_height, width, height - rebar_height - statusbar_height, 0); { - const UINT listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); if (listview_id) { @@ -2392,39 +2400,39 @@ void _app_tabs_init (HWND hwnd) const HINSTANCE hinst = app.GetHINSTANCE (); const DWORD listview_ex_style = LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_CHECKBOXES | LVS_EX_HEADERINALLVIEWS; const DWORD listview_style = WS_CHILD | WS_TABSTOP | LVS_SHOWSELALWAYS | LVS_REPORT | LVS_SHAREIMAGELISTS | LVS_AUTOARRANGE; - UINT tabs_count = 0; + INT tabs_count = 0; CreateWindow (WC_LISTVIEW, nullptr, listview_style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU)IDC_APPS_PROFILE, hinst, nullptr); - _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TAB_APPS, nullptr), LAST_VALUE, IDC_APPS_PROFILE); + _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TAB_APPS, nullptr), INVALID_INT, IDC_APPS_PROFILE); CreateWindow (WC_LISTVIEW, nullptr, listview_style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU)IDC_APPS_SERVICE, hinst, nullptr); - _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TAB_SERVICES, nullptr), LAST_VALUE, IDC_APPS_SERVICE); + _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TAB_SERVICES, nullptr), INVALID_INT, IDC_APPS_SERVICE); // uwp apps (win8+) if (_r_sys_validversion (6, 2)) { CreateWindow (WC_LISTVIEW, nullptr, listview_style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU)IDC_APPS_UWP, hinst, nullptr); - _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TAB_PACKAGES, nullptr), LAST_VALUE, IDC_APPS_UWP); + _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TAB_PACKAGES, nullptr), INVALID_INT, IDC_APPS_UWP); } CreateWindow (WC_LISTVIEW, nullptr, listview_style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU)IDC_RULES_BLOCKLIST, hinst, nullptr); - _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TRAY_SYSTEM_RULES, nullptr), LAST_VALUE, IDC_RULES_BLOCKLIST); + _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TRAY_SYSTEM_RULES, nullptr), INVALID_INT, IDC_RULES_BLOCKLIST); CreateWindow (WC_LISTVIEW, nullptr, listview_style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU)IDC_RULES_SYSTEM, hinst, nullptr); - _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TRAY_SYSTEM_RULES, nullptr), LAST_VALUE, IDC_RULES_SYSTEM); + _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TRAY_SYSTEM_RULES, nullptr), INVALID_INT, IDC_RULES_SYSTEM); CreateWindow (WC_LISTVIEW, nullptr, listview_style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU)IDC_RULES_CUSTOM, hinst, nullptr); - _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TRAY_USER_RULES, nullptr), LAST_VALUE, IDC_RULES_CUSTOM); + _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TRAY_USER_RULES, nullptr), INVALID_INT, IDC_RULES_CUSTOM); CreateWindow (WC_LISTVIEW, nullptr, listview_style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, (HMENU)IDC_NETWORK, hinst, nullptr); - _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TAB_NETWORK, nullptr), LAST_VALUE, IDC_NETWORK); + _r_tab_additem (hwnd, IDC_TAB, tabs_count++, app.LocaleString (IDS_TAB_NETWORK, nullptr), INVALID_INT, IDC_NETWORK); RECT rect = {0}; GetClientRect (hwnd, &rect); - for (UINT i = 0; i < tabs_count; i++) + for (INT i = 0; i < tabs_count; i++) { - const UINT listview_id = _app_gettab_id (hwnd, i); + const INT listview_id = _app_gettab_id (hwnd, i); if (!listview_id) continue; @@ -2710,12 +2718,12 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else if ((lpfr->Flags & FR_FINDNEXT) != 0) { - const UINT listview_id = _app_gettab_id (hwnd); - const size_t total_count = _r_listview_getitemcount (hwnd, listview_id); + const INT listview_id = _app_gettab_id (hwnd); + const INT total_count = _r_listview_getitemcount (hwnd, listview_id); const INT selected_item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, (WPARAM)-1, LVNI_SELECTED) + 1; - for (size_t i = selected_item; i < total_count; i++) + for (INT i = selected_item; i < total_count; i++) { const rstring text = _r_listview_getitemtext (hwnd, listview_id, i, 0); @@ -3049,9 +3057,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } // localize tabs - for (UINT i = 0; i < (UINT)SendDlgItemMessage (hwnd, IDC_TAB, TCM_GETITEMCOUNT, 0, 0); i++) + for (INT i = 0; i < (INT)SendDlgItemMessage (hwnd, IDC_TAB, TCM_GETITEMCOUNT, 0, 0); i++) { - const UINT listview_id = _app_gettab_id (hwnd, i); + const INT listview_id = _app_gettab_id (hwnd, i); UINT locale_id; @@ -3086,7 +3094,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_listview_setcolumn (hwnd, listview_id, 0, app.LocaleString (IDS_NAME, nullptr), 0); _r_listview_setcolumn (hwnd, listview_id, 1, app.LocaleString (IDS_ADDED, nullptr), 0); - for (size_t j = 0; j < _r_listview_getitemcount (hwnd, listview_id); j++) + for (INT j = 0; j < _r_listview_getitemcount (hwnd, listview_id); j++) { const size_t app_hash = _r_listview_getitemlparam (hwnd, listview_id, j); PR_OBJECT ptr_app_object = _app_getappitem (app_hash); @@ -3112,7 +3120,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_listview_setcolumn (hwnd, listview_id, 1, app.LocaleString (IDS_PROTOCOL, nullptr), 0); _r_listview_setcolumn (hwnd, listview_id, 2, app.LocaleString (IDS_DIRECTION, nullptr), 0); - for (size_t j = 0; j < _r_listview_getitemcount (hwnd, listview_id); j++) + for (INT j = 0; j < _r_listview_getitemcount (hwnd, listview_id); j++) { const size_t rule_idx = _r_listview_getitemlparam (hwnd, listview_id, j); PR_OBJECT ptr_rule_object = _app_getrulebyid (rule_idx); @@ -3274,7 +3282,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _app_refreshstatus (hwnd); { - UINT app_listview_id = 0; + INT app_listview_id = 0; if (_app_getappinfo (app_hash, InfoListviewId, &app_listview_id, sizeof (app_listview_id))) { @@ -3307,7 +3315,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) for (UINT i = 0; i < tab_count; i++) { - const UINT current_id = _app_gettab_id (hwnd, i); + const INT current_id = _app_gettab_id (hwnd, i); if (current_id) _r_wnd_resize (&hdefer, GetDlgItem (hwnd, current_id), nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW); @@ -3315,7 +3323,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) EndDeferWindowPos (hdefer); - const UINT listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); if (IsWindowVisible (GetDlgItem (hwnd, listview_id))) break; @@ -3381,9 +3389,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (_r_fastlock_tryacquireshared (&lock_access)) { LPNMLVGETINFOTIP lpnmlv = (LPNMLVGETINFOTIP)lparam; - const size_t idx = (size_t)_r_listview_getitemlparam (hwnd, (UINT)lpnmlv->hdr.idFrom, lpnmlv->iItem); + const size_t idx = _r_listview_getitemlparam (hwnd, (INT)lpnmlv->hdr.idFrom, lpnmlv->iItem); - StringCchCopy (lpnmlv->pszText, lpnmlv->cchTextMax, _app_gettooltip ((UINT)lpnmlv->hdr.idFrom, idx)); + StringCchCopy (lpnmlv->pszText, lpnmlv->cchTextMax, _app_gettooltip ((INT)lpnmlv->hdr.idFrom, idx)); _r_fastlock_releaseshared (&lock_access); } @@ -3397,12 +3405,12 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (IsWindowVisible (lpnmlv->hdr.hwndFrom) && (lpnmlv->uChanged & LVIF_STATE) && (lpnmlv->uNewState == 8192 || lpnmlv->uNewState == 4096) && lpnmlv->uNewState != lpnmlv->uOldState) { - const UINT listview_id = _app_gettab_id (hwnd); - bool is_changed = false; - if (_r_fastlock_islocked (&lock_checkbox)) break; + const INT listview_id = (INT)lpnmlv->hdr.idFrom; + bool is_changed = false; + const bool new_val = (lpnmlv->uNewState == 8192) ? true : false; if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) @@ -3444,9 +3452,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else if (listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM) { - const size_t rule_idx = lpnmlv->lParam; OBJECTS_VEC rules; + const size_t rule_idx = lpnmlv->lParam; PR_OBJECT ptr_rule_object = _app_getrulebyid (rule_idx); if (!ptr_rule_object) @@ -3978,12 +3986,12 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else if ((LOWORD (wparam) >= IDX_RULES_SPECIAL && LOWORD (wparam) <= IDX_RULES_SPECIAL + rules_arr.size ())) { - const UINT app_listview_id = _app_gettab_id (hwnd); + const INT app_listview_id = _app_gettab_id (hwnd); if (!SendDlgItemMessage (hwnd, app_listview_id, LVM_GETSELECTEDCOUNT, 0, 0)) return FALSE; - size_t item = LAST_VALUE; + INT item = INVALID_INT; BOOL is_remove = (BOOL)-1; const size_t rule_idx = (LOWORD (wparam) - IDX_RULES_SPECIAL); @@ -3996,9 +4004,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_rule) { - while ((item = (size_t)SendDlgItemMessage (hwnd, app_listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) + while ((item = (INT)SendDlgItemMessage (hwnd, app_listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != INVALID_INT) { - const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, app_listview_id, item); + const size_t app_hash = _r_listview_getitemlparam (hwnd, app_listview_id, item); if (ptr_rule->is_forservices && (app_hash == config.ntoskrnl_hash || app_hash == config.svchost_hash)) continue; @@ -4039,13 +4047,18 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_obj_dereference (ptr_app_object, &_app_dereferenceapp); } - const UINT rule_listview_id = _app_getlistview_id (ptr_rule->type); + const INT rule_listview_id = _app_getlistview_id (ptr_rule->type); if (rule_listview_id) { - _r_fastlock_acquireshared (&lock_checkbox); - _app_setruleiteminfo (hwnd, rule_listview_id, _app_getposition (hwnd, rule_listview_id, rule_idx), ptr_rule, true); - _r_fastlock_releaseshared (&lock_checkbox); + const INT item_pos = _app_getposition (hwnd, rule_listview_id, rule_idx); + + if (item_pos != INVALID_INT) + { + _r_fastlock_acquireshared (&lock_checkbox); + _app_setruleiteminfo (hwnd, rule_listview_id, item_pos, ptr_rule, true); + _r_fastlock_releaseshared (&lock_checkbox); + } } OBJECTS_VEC rules; @@ -4065,19 +4078,19 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else if ((LOWORD (wparam) >= IDX_TIMER && LOWORD (wparam) <= IDX_TIMER + timers.size ())) { - const UINT listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); if (!SendDlgItemMessage (hwnd, listview_id, LVM_GETSELECTEDCOUNT, 0, 0)) return FALSE; const size_t timer_idx = (LOWORD (wparam) - IDX_TIMER); const time_t seconds = timers.at (timer_idx); - size_t item = LAST_VALUE; + INT item = INVALID_INT; OBJECTS_VEC rules; - while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) + while ((item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != INVALID_INT) { - const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + const size_t app_hash = _r_listview_getitemlparam (hwnd, listview_id, item); _r_fastlock_acquireshared (&lock_access); PR_OBJECT ptr_app_object = _app_getappitem (app_hash); @@ -4273,13 +4286,13 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { _app_getdisplayname (app_hash, ptr_app, &ptr_app->display_name); - const UINT listview_id = _app_getlistview_id (ptr_app->type); + const INT listview_id = _app_getlistview_id (ptr_app->type); if (listview_id) { - const size_t item_pos = _app_getposition (hwnd, listview_id, app_hash); + const INT item_pos = _app_getposition (hwnd, listview_id, app_hash); - if (item_pos != LAST_VALUE) + if (item_pos != INVALID_INT) { _r_fastlock_acquireshared (&lock_checkbox); _app_setappiteminfo (hwnd, listview_id, item_pos, app_hash, ptr_app); @@ -4320,13 +4333,13 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_app) { - const UINT listview_id = _app_getlistview_id (ptr_app->type); + const INT listview_id = _app_getlistview_id (ptr_app->type); if (listview_id) { - const size_t item_pos = _app_getposition (hwnd, listview_id, app_hash); + const INT item_pos = _app_getposition (hwnd, listview_id, app_hash); - if (item_pos != LAST_VALUE) + if (item_pos != INVALID_INT) { _r_fastlock_acquireshared (&lock_checkbox); _app_setappiteminfo (hwnd, listview_id, item_pos, app_hash, ptr_app); @@ -4350,13 +4363,13 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_rule) { - const UINT listview_id = _app_getlistview_id (ptr_rule->type); + const INT listview_id = _app_getlistview_id (ptr_rule->type); if (listview_id) { - const size_t item_pos = _app_getposition (hwnd, listview_id, i); + const INT item_pos = _app_getposition (hwnd, listview_id, i); - if (item_pos != LAST_VALUE) + if (item_pos != INVALID_INT) { _r_fastlock_acquireshared (&lock_checkbox); _app_setruleiteminfo (hwnd, listview_id, item_pos, ptr_rule, false); @@ -4371,6 +4384,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_fastlock_releaseshared (&lock_access); _app_listviewsort (hwnd, _app_gettab_id (hwnd)); + _app_refreshstatus (hwnd); break; } @@ -4379,7 +4393,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_ICONSLARGE: case IDM_ICONSEXTRALARGE: { - const UINT listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); INT icon_size; @@ -4410,7 +4424,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) CheckMenuItem (GetMenu (hwnd), LOWORD (wparam), MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); app.ConfigSet (L"IsTableView", new_val); - const UINT listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); _app_listviewsetview (hwnd, listview_id); _app_listviewresize (hwnd, listview_id); @@ -4441,13 +4455,13 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_app) { - const UINT listview_id = _app_getlistview_id (ptr_app->type); + const INT listview_id = _app_getlistview_id (ptr_app->type); if (listview_id) { - const size_t item_pos = _app_getposition (hwnd, listview_id, app_hash); + const INT item_pos = _app_getposition (hwnd, listview_id, app_hash); - if (item_pos != LAST_VALUE) + if (item_pos != INVALID_INT) { _r_fastlock_acquireshared (&lock_checkbox); _app_setappiteminfo (hwnd, listview_id, item_pos, app_hash, ptr_app); @@ -4489,7 +4503,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) config.hfont = nullptr; } - for (UINT i = 0; i < (UINT)SendDlgItemMessage (hwnd, IDC_TAB, TCM_GETITEMCOUNT, 0, 0); i++) + for (INT i = 0; i < (INT)SendDlgItemMessage (hwnd, IDC_TAB, TCM_GETITEMCOUNT, 0, 0); i++) _app_listviewsetfont (hwnd, _app_gettab_id (hwnd, i), false); _app_listviewresize (hwnd, _app_gettab_id (hwnd)); @@ -4780,7 +4794,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } { - UINT app_listview_id = 0; + INT app_listview_id = 0; if (_app_getappinfo (app_hash, InfoListviewId, &app_listview_id, sizeof (app_listview_id))) { @@ -4802,8 +4816,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_DISABLETIMER: case IDM_EXPLORE: { - const UINT listview_id = _app_gettab_id (hwnd); - const UINT ctrl_id = LOWORD (wparam); + const INT listview_id = _app_gettab_id (hwnd); + const INT ctrl_id = LOWORD (wparam); if ( listview_id != IDC_APPS_PROFILE && @@ -4816,16 +4830,16 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) break; } - size_t item = LAST_VALUE; + INT item = INVALID_INT; BOOL new_val = BOOL (-1); - while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) + while ((item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != INVALID_INT) { size_t app_hash = 0; if (listview_id == IDC_NETWORK) { - const size_t network_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + const size_t network_hash = _r_listview_getitemlparam (hwnd, listview_id, item); PR_OBJECT ptr_network_object = _app_getnetworkitem (network_hash); if (!ptr_network_object) @@ -4850,7 +4864,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else { - app_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + app_hash = _r_listview_getitemlparam (hwnd, listview_id, item); } _r_fastlock_acquireshared (&lock_access); @@ -4909,20 +4923,20 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_COPY: case IDM_COPY2: { - const UINT listview_id = _app_gettab_id (hwnd); - size_t item = LAST_VALUE; + const INT listview_id = _app_gettab_id (hwnd); + INT item = INVALID_INT; - const UINT lv_column_count = _r_listview_getcolumncount (hwnd, listview_id); - const size_t lv_column_current = lparam; + const INT lv_column_count = _r_listview_getcolumncount (hwnd, listview_id); + const INT lv_column_current = (INT)lparam; const rstring divider = _r_fmt (L"%c ", DIVIDER_COPY); rstring buffer; - while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) + while ((item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != INVALID_INT) { if (LOWORD (wparam) == IDM_COPY) { - for (UINT column_id = 0; column_id < lv_column_count; column_id++) + for (INT column_id = 0; column_id < lv_column_count; column_id++) buffer.Append (_r_listview_getitemtext (hwnd, listview_id, item, column_id)).Append (divider); } else @@ -4943,8 +4957,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_CHECK: case IDM_UNCHECK: { - const UINT listview_id = _app_gettab_id (hwnd); - const UINT ctrl_id = LOWORD (wparam); + const INT listview_id = _app_gettab_id (hwnd); + const INT ctrl_id = LOWORD (wparam); const bool new_val = (LOWORD (wparam) == IDM_CHECK) ? true : false; @@ -4953,11 +4967,11 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) { OBJECTS_VEC rules; - size_t item = LAST_VALUE; + INT item = INVALID_INT; - while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) + while ((item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != INVALID_INT) { - const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + const size_t app_hash = _r_listview_getitemlparam (hwnd, listview_id, item); PR_OBJECT ptr_app_object = _app_getappitem (app_hash); if (!ptr_app_object) @@ -5000,11 +5014,11 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) else if (listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM) { OBJECTS_VEC rules; - size_t item = LAST_VALUE; + INT item = INVALID_INT; - while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) + while ((item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != INVALID_INT) { - const size_t rule_idx = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + const size_t rule_idx = _r_listview_getitemlparam (hwnd, listview_id, item); PR_OBJECT ptr_rule_object = _app_getrulebyid (rule_idx); if (!ptr_rule_object) @@ -5066,15 +5080,15 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) ptr_rule->type = DataRuleCustom; ptr_rule->is_block = false; - const UINT listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) { - size_t item = LAST_VALUE; + INT item = INVALID_INT; - while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) + while ((item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != INVALID_INT) { - const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + const size_t app_hash = _r_listview_getitemlparam (hwnd, listview_id, item); if (app_hash) ptr_rule->apps[app_hash] = true; @@ -5082,16 +5096,16 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else if (listview_id == IDC_NETWORK) { - size_t item = LAST_VALUE; + INT item = INVALID_INT; rstring rule_remote; rstring rule_local; ptr_rule->is_block = true; - while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) + while ((item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != INVALID_INT) { - const size_t network_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + const size_t network_hash = _r_listview_getitemlparam (hwnd, listview_id, item); PR_OBJECT ptr_network_object = _app_getnetworkitem (network_hash); if (!ptr_network_object) @@ -5156,11 +5170,11 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_fastlock_releaseexclusive (&lock_access); - const UINT listview_rules_id = _app_getlistview_id (DataRuleCustom); + const INT listview_rules_id = _app_getlistview_id (DataRuleCustom); if (listview_rules_id) { - const size_t new_item = _r_listview_getitemcount (hwnd, listview_rules_id); + const INT new_item = _r_listview_getitemcount (hwnd, listview_rules_id); _r_fastlock_acquireshared (&lock_checkbox); @@ -5185,10 +5199,10 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_PROPERTIES: { - const UINT listview_id = _app_gettab_id (hwnd); - const size_t item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, (WPARAM)-1, LVNI_SELECTED); + const INT listview_id = _app_gettab_id (hwnd); + const INT item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, (WPARAM)-1, LVNI_SELECTED); - if (item == LAST_VALUE) + if (item == INVALID_INT) break; if (listview_id >= IDC_APPS_PROFILE && listview_id <= IDC_APPS_UWP) @@ -5197,7 +5211,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else if (listview_id >= IDC_RULES_BLOCKLIST && listview_id <= IDC_RULES_CUSTOM) { - const size_t rule_idx = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + const size_t rule_idx = _r_listview_getitemlparam (hwnd, listview_id, item); PR_OBJECT ptr_rule_object = _app_getrulebyid (rule_idx); if (!ptr_rule_object) @@ -5224,7 +5238,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else if (listview_id == IDC_NETWORK) { - const size_t network_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + const size_t network_hash = _r_listview_getitemlparam (hwnd, listview_id, item); PR_OBJECT ptr_network_object = _app_getnetworkitem (network_hash); if (!ptr_network_object) @@ -5238,15 +5252,15 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (!_app_isappfound (app_hash)) { - _r_fastlock_acquireexclusive (&lock_access); + _r_fastlock_acquireshared (&lock_access); _app_addapplication (hwnd, ptr_network->path, 0, 0, 0, false, false, true); - _r_fastlock_releaseexclusive (&lock_access); + _r_fastlock_releaseshared (&lock_access); _app_refreshstatus (hwnd); _app_profile_save (); } - UINT app_listview_id = 0; + INT app_listview_id = 0; if (_app_getappinfo (app_hash, InfoListviewId, &app_listview_id, sizeof (app_listview_id))) { @@ -5263,22 +5277,22 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_NETWORK_CLOSE: { - const UINT listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); if (listview_id != IDC_NETWORK) break; - const UINT selected = (UINT)SendDlgItemMessage (hwnd, listview_id, LVM_GETSELECTEDCOUNT, 0, 0); + const INT selected = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETSELECTEDCOUNT, 0, 0); if (!selected) break; - size_t item = LAST_VALUE; + INT item = INVALID_INT; MIB_TCPROW tcprow; - while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) + while ((item = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != INVALID_INT) { - const size_t network_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + const size_t network_hash = _r_listview_getitemlparam (hwnd, listview_id, item); PR_OBJECT ptr_network_object = _r_obj_reference (network_map[network_hash]); if (!ptr_network_object) @@ -5318,27 +5332,27 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_DELETE: { - const UINT listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); if (listview_id != IDC_APPS_PROFILE && listview_id != IDC_RULES_CUSTOM) break; - const UINT selected = (UINT)SendDlgItemMessage (hwnd, listview_id, LVM_GETSELECTEDCOUNT, 0, 0); + const INT selected = (INT)SendDlgItemMessage (hwnd, listview_id, LVM_GETSELECTEDCOUNT, 0, 0); if (!selected || _r_msg (hwnd, MB_YESNO | MB_ICONEXCLAMATION, APP_NAME, nullptr, app.LocaleString (IDS_QUESTION_DELETE, nullptr), selected) != IDYES) break; - const size_t count = _r_listview_getitemcount (hwnd, listview_id) - 1; + const INT count = _r_listview_getitemcount (hwnd, listview_id) - 1; GUIDS_VEC guids; - for (size_t i = count; i != LAST_VALUE; i--) + for (INT i = count; i != INVALID_INT; i--) { if (ListView_GetItemState (GetDlgItem (hwnd, listview_id), i, LVNI_SELECTED)) { if (listview_id == IDC_APPS_PROFILE) { - const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, i); + const size_t app_hash = _r_listview_getitemlparam (hwnd, listview_id, i); PR_OBJECT ptr_app_object = _app_getappitem (app_hash); if (!ptr_app_object) @@ -5368,7 +5382,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } else if (listview_id == IDC_RULES_CUSTOM) { - const size_t rule_idx = (size_t)_r_listview_getitemlparam (hwnd, listview_id, i); + const size_t rule_idx = _r_listview_getitemlparam (hwnd, listview_id, i); PR_OBJECT ptr_rule_object = _app_getrulebyid (rule_idx); if (!ptr_rule_object) @@ -5410,13 +5424,18 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_app) { - const UINT app_listview_id = _app_getlistview_id (ptr_app->type); + const INT app_listview_id = _app_getlistview_id (ptr_app->type); if (app_listview_id) { - _r_fastlock_acquireshared (&lock_checkbox); - _app_setappiteminfo (hwnd, app_listview_id, _app_getposition (hwnd, app_listview_id, app_hash), app_hash, ptr_app); - _r_fastlock_releaseshared (&lock_checkbox); + const INT item_pos = _app_getposition (hwnd, app_listview_id, app_hash); + + if (item_pos != INVALID_INT) + { + _r_fastlock_acquireshared (&lock_checkbox); + _app_setappiteminfo (hwnd, app_listview_id, item_pos, app_hash, ptr_app); + _r_fastlock_releaseshared (&lock_checkbox); + } } } @@ -5455,14 +5474,14 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_app && !ptr_app->is_undeletable && (!_app_isappexists (ptr_app) || ((ptr_app->type != DataAppService && ptr_app->type != DataAppUWP) && !_app_isappused (ptr_app, app_hash)))) { - const UINT app_listview_id = _app_getlistview_id (ptr_app->type); + const INT app_listview_id = _app_getlistview_id (ptr_app->type); if (app_listview_id) { - const size_t item = _app_getposition (hwnd, app_listview_id, app_hash); + const INT item_pos = _app_getposition (hwnd, app_listview_id, app_hash); - if (item != LAST_VALUE) - SendDlgItemMessage (hwnd, app_listview_id, LVM_DELETEITEM, item, 0); + if (item_pos != INVALID_INT) + SendDlgItemMessage (hwnd, app_listview_id, LVM_DELETEITEM, item_pos, 0); } _app_timer_reset (hwnd, ptr_app); diff --git a/src/main.hpp b/src/main.hpp index 2ca04bf1..5f01e3cb 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -272,9 +272,9 @@ struct STATIC_DATA size_t tmp_length = 0; size_t wd_length = 0; - size_t icon_id = 0; - size_t icon_service_id = 0; - size_t icon_uwp_id = 0; + INT icon_id = 0; + INT icon_service_id = 0; + INT icon_uwp_id = 0; bool is_notifytimeout = false; bool is_notifymouse = false; @@ -291,7 +291,7 @@ typedef struct tagITEM_APP SAFE_DELETE_ARRAY (pdata); - _r_obj_dereference (pnotification , &_app_dereferencelog); + _r_obj_dereference (pnotification, &_app_dereferencelog); } GUIDS_VEC guids; @@ -309,7 +309,7 @@ typedef struct tagITEM_APP time_t timer = 0; time_t last_notify = 0; - size_t icon_id = 0; + INT icon_id = 0; EnumDataType type = DataUnknown; @@ -341,6 +341,15 @@ typedef struct tagITEM_APP_HELPER SAFE_DELETE_ARRAY (display_name); SAFE_DELETE_ARRAY (service_name); SAFE_DELETE_ARRAY (real_path); + + if (type == DataAppService) + { + SAFE_DELETE_ARRAY (PSECURITY_DESCRIPTOR (pdata)); + } + else if (type == DataAppUWP) + { + SAFE_DELETE_ARRAY (PSID (pdata)); + } } time_t timestamp = 0; @@ -511,7 +520,7 @@ typedef struct tagITEM_NETWORK IN6_ADDR local_addr6; }; - size_t icon_id = 0; + INT icon_id = 0; DWORD state = 0; diff --git a/src/notifications.cpp b/src/notifications.cpp index 7fcacc1b..aa755650 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -195,8 +195,8 @@ bool _app_notifycommand (HWND hwnd, UINT button_id, time_t seconds) OBJECTS_VEC rules; - const UINT listview_id = _app_getlistview_id (ptr_app->type); - const size_t item = _app_getposition (app.GetHWND (), listview_id, app_hash); + const INT listview_id = _app_getlistview_id (ptr_app->type); + const INT item_pos = _app_getposition (app.GetHWND (), listview_id, app_hash); if (button_id == IDC_ALLOW_BTN || button_id == IDC_BLOCK_BTN) { @@ -209,10 +209,10 @@ bool _app_notifycommand (HWND hwnd, UINT button_id, time_t seconds) } else { - if (item != LAST_VALUE) + if (item_pos != INVALID_INT) { _r_fastlock_acquireshared (&lock_checkbox); - _app_setappiteminfo (app.GetHWND (), listview_id, item, app_hash, ptr_app); + _app_setappiteminfo (app.GetHWND (), listview_id, item_pos, app_hash, ptr_app); _r_fastlock_releaseshared (&lock_checkbox); } } @@ -321,7 +321,7 @@ size_t _app_notifyget_id (HWND hwnd, size_t current_id) { size_t app_hash_current = (size_t)GetWindowLongPtr (hwnd, GWLP_USERDATA); - if (current_id == LAST_VALUE) + if (current_id == INVALID_SIZE_T) { for (auto &p : apps) { @@ -454,7 +454,7 @@ bool _app_notifyshow (HWND hwnd, PR_OBJECT ptr_log_object, bool is_forced, bool _r_ctrl_enable (hwnd, IDC_ALLOW_BTN, !is_safety); _r_ctrl_enable (hwnd, IDC_BLOCK_BTN, !is_safety); - ShowWindow (GetDlgItem (hwnd, IDC_NEXT_BTN), _app_notifyget_id (hwnd, LAST_VALUE) ? SW_SHOW : SW_HIDE); + ShowWindow (GetDlgItem (hwnd, IDC_NEXT_BTN), _app_notifyget_id (hwnd, INVALID_SIZE_T) ? SW_SHOW : SW_HIDE); _r_ctrl_settext (hwnd, IDC_RULES_BTN, app.LocaleString (IDS_TRAY_RULES, nullptr)); _r_ctrl_settext (hwnd, IDC_ALLOW_BTN, app.LocaleString (IDS_ACTION_ALLOW, nullptr)); @@ -532,7 +532,7 @@ void _app_notifyrefresh (HWND hwnd, bool is_safety) if (!app.ConfigGet (L"IsNotificationsEnabled", true).AsBool () || !IsWindowVisible (hwnd)) _app_notifyhide (config.hnotification); - PR_OBJECT ptr_log_object = _app_notifyget_obj (_app_notifyget_id (hwnd, LAST_VALUE)); + PR_OBJECT ptr_log_object = _app_notifyget_obj (_app_notifyget_id (hwnd, INVALID_SIZE_T)); if (!ptr_log_object) { @@ -957,28 +957,28 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp _app_ruleenable (ptr_rule, true); } - const UINT listview_id = _app_gettab_id (app.GetHWND ()); - const UINT app_listview_id = _app_getlistview_id (ptr_app->type); - const UINT rule_listview_id = _app_getlistview_id (ptr_rule->type); + const INT listview_id = _app_gettab_id (app.GetHWND ()); + const INT app_listview_id = _app_getlistview_id (ptr_app->type); + const INT rule_listview_id = _app_getlistview_id (ptr_rule->type); { - const size_t app_item = _app_getposition (app.GetHWND (), app_listview_id, ptr_log->app_hash); + const INT item_pos = _app_getposition (app.GetHWND (), app_listview_id, ptr_log->app_hash); - if (app_item != LAST_VALUE) + if (item_pos != INVALID_INT) { _r_fastlock_acquireshared (&lock_checkbox); - _app_setappiteminfo (app.GetHWND (), app_listview_id, app_item, ptr_log->app_hash, ptr_app); + _app_setappiteminfo (app.GetHWND (), app_listview_id, item_pos, ptr_log->app_hash, ptr_app); _r_fastlock_releaseshared (&lock_checkbox); } } { - const size_t rule_item = _app_getposition (app.GetHWND (), rule_listview_id, rule_idx); + const INT item_pos = _app_getposition (app.GetHWND (), rule_listview_id, rule_idx); - if (rule_item != LAST_VALUE) + if (item_pos != INVALID_INT) { _r_fastlock_acquireshared (&lock_checkbox); - _app_setruleiteminfo (app.GetHWND (), rule_listview_id, rule_item, ptr_rule, false); + _app_setruleiteminfo (app.GetHWND (), rule_listview_id, item_pos, ptr_rule, false); _r_fastlock_releaseshared (&lock_checkbox); } } @@ -1043,7 +1043,7 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp if (ptr_app) { - const UINT listview_id = _app_getlistview_id (ptr_app->type); + const INT listview_id = _app_getlistview_id (ptr_app->type); if (listview_id) _app_showitem (app.GetHWND (), listview_id, _app_getposition (app.GetHWND (), listview_id, ptr_log->app_hash)); @@ -1082,7 +1082,7 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp case IDC_NEXT_BTN: { - PR_OBJECT ptr_log_object = _app_notifyget_obj (_app_notifyget_id (hwnd, LAST_VALUE)); + PR_OBJECT ptr_log_object = _app_notifyget_obj (_app_notifyget_id (hwnd, INVALID_SIZE_T)); if (ptr_log_object) { @@ -1167,15 +1167,15 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp _r_fastlock_releaseexclusive (&lock_access); - const UINT listview_id = _app_gettab_id (app.GetHWND ()); + const INT listview_id = _app_gettab_id (app.GetHWND ()); // set rule information { - const UINT rules_listview_id = _app_getlistview_id (ptr_rule->type); + const INT rules_listview_id = _app_getlistview_id (ptr_rule->type); if (rules_listview_id) { - const size_t new_item = _r_listview_getitemcount (hwnd, rules_listview_id); + const INT new_item = _r_listview_getitemcount (hwnd, rules_listview_id); _r_fastlock_acquireshared (&lock_checkbox); @@ -1199,13 +1199,18 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp if (ptr_app) { - const UINT app_listview_id = _app_getlistview_id (ptr_app->type); + const INT app_listview_id = _app_getlistview_id (ptr_app->type); if (app_listview_id) { - _r_fastlock_acquireshared (&lock_checkbox); - _app_setappiteminfo (app.GetHWND (), app_listview_id, _app_getposition (app.GetHWND (), app_listview_id, app_hash), app_hash, ptr_app); - _r_fastlock_releaseshared (&lock_checkbox); + const INT item_pos = _app_getposition (app.GetHWND (), app_listview_id, app_hash); + + if (item_pos != INVALID_INT) + { + _r_fastlock_acquireshared (&lock_checkbox); + _app_setappiteminfo (app.GetHWND (), app_listview_id, item_pos, app_hash, ptr_app); + _r_fastlock_releaseshared (&lock_checkbox); + } if (app_listview_id == listview_id) _app_listviewsort (app.GetHWND (), listview_id); diff --git a/src/profile.cpp b/src/profile.cpp index 8f990873..dffc0aa4 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -31,7 +31,7 @@ bool _app_getappinfo (size_t app_hash, EnumInfo info_key, LPVOID presult, size_t } else if (info_key == InfoListviewId) { - UINT v = _app_getlistview_id (ptr_app->type); + INT v = _app_getlistview_id (ptr_app->type); CopyMemory (presult, &v, size); } } @@ -189,11 +189,11 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t ti // insert item if (hwnd) { - const UINT listview_id = _app_getlistview_id (ptr_app->type); + const INT listview_id = _app_getlistview_id (ptr_app->type); if (listview_id) { - const size_t item = _r_listview_getitemcount (hwnd, listview_id); + const INT item = _r_listview_getitemcount (hwnd, listview_id); _r_fastlock_acquireshared (&lock_checkbox); @@ -217,7 +217,7 @@ PR_OBJECT _app_getappitem (size_t app_hash) PR_OBJECT _app_getrulebyid (size_t idx) { - if (idx == LAST_VALUE || idx >= rules_arr.size ()) + if (idx == INVALID_SIZE_T || idx >= rules_arr.size ()) return nullptr; return _r_obj_reference (rules_arr.at (idx)); @@ -306,13 +306,18 @@ void _app_freeapplication (size_t app_hash) ptr_rule->is_haveerrors = false; } - const UINT rule_listview_id = _app_getlistview_id (ptr_rule->type); + const INT rule_listview_id = _app_getlistview_id (ptr_rule->type); if (rule_listview_id) { - _r_fastlock_acquireshared (&lock_checkbox); - _app_setruleiteminfo (app.GetHWND (), rule_listview_id, _app_getposition (app.GetHWND (), rule_listview_id, i), ptr_rule, false); - _r_fastlock_releaseshared (&lock_checkbox); + const INT item_pos = _app_getposition (app.GetHWND (), rule_listview_id, i); + + if (item_pos != INVALID_INT) + { + _r_fastlock_acquireshared (&lock_checkbox); + _app_setruleiteminfo (app.GetHWND (), rule_listview_id, item_pos, ptr_rule, false); + _r_fastlock_releaseshared (&lock_checkbox); + } } } } @@ -386,10 +391,10 @@ void _app_getcount (PITEM_STATUS ptr_status) } } -size_t _app_getappgroup (size_t app_hash, PITEM_APP ptr_app) +INT _app_getappgroup (size_t app_hash, PITEM_APP ptr_app) { // if(!app.ConfigGet (L"IsEnableGroups", false).AsBool ()) - // return LAST_VALUE; + // return INVALID_INT; if (!ptr_app) return 2; @@ -401,10 +406,10 @@ size_t _app_getappgroup (size_t app_hash, PITEM_APP ptr_app) return ptr_app->is_enabled ? 0 : 2; } -size_t _app_getrulegroup (PITEM_RULE ptr_rule) +INT _app_getrulegroup (PITEM_RULE ptr_rule) { // if(!app.ConfigGet (L"IsEnableGroups", false).AsBool ()) - // return LAST_VALUE; + // return INVALID_INT; if (!ptr_rule || !ptr_rule->is_enabled) return 2; @@ -415,7 +420,7 @@ size_t _app_getrulegroup (PITEM_RULE ptr_rule) return 0; } -size_t _app_getruleicon (PITEM_RULE ptr_rule) +INT _app_getruleicon (PITEM_RULE ptr_rule) { if (!ptr_rule) return 0; @@ -423,7 +428,7 @@ size_t _app_getruleicon (PITEM_RULE ptr_rule) return ptr_rule->is_block ? 1 : 0; } -rstring _app_gettooltip (UINT listview_id, size_t idx) +rstring _app_gettooltip (INT listview_id, size_t lparam) { rstring result; @@ -431,20 +436,20 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) { if (listview_id == IDC_NETWORK) { - PR_OBJECT ptr_network_object = _app_getnetworkitem (idx); + PR_OBJECT ptr_network_object = _app_getnetworkitem (lparam); if (ptr_network_object) { PITEM_NETWORK ptr_network = (PITEM_NETWORK)ptr_network_object->pdata; if (ptr_network) - idx = ptr_network->app_hash; + lparam = ptr_network->app_hash; _r_obj_dereference (ptr_network_object, &_app_dereferencenetwork); } } - PR_OBJECT ptr_app_object = _app_getappitem (idx); + PR_OBJECT ptr_app_object = _app_getappitem (lparam); if (ptr_app_object) { @@ -458,7 +463,7 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) if (ptr_app->type == DataAppRegular) { rstring display_name; - PR_OBJECT ptr_version_object = _app_getversioninfo (idx, ptr_app); + PR_OBJECT ptr_version_object = _app_getversioninfo (lparam, ptr_app); if (ptr_version_object) { @@ -476,21 +481,21 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) { rstring display_name; - if (_app_item_get (ptr_app->type, idx, &display_name, nullptr, nullptr)) + if (_app_item_get (ptr_app->type, lparam, &display_name, nullptr, nullptr)) result.AppendFormat (L"\r\n%s:\r\n" SZ_TAB L"%s\r\n" SZ_TAB L"%s" SZ_TAB, app.LocaleString (IDS_FILE, nullptr).GetString (), ptr_app->original_path, display_name.GetString ()); } else if (ptr_app->type == DataAppUWP) { rstring display_name; - if (_app_item_get (ptr_app->type, idx, &display_name, nullptr, nullptr)) + if (_app_item_get (ptr_app->type, lparam, &display_name, nullptr, nullptr)) result.AppendFormat (L"\r\n%s:\r\n" SZ_TAB L"%s" SZ_TAB, app.LocaleString (IDS_FILE, nullptr).GetString (), display_name.GetString ()); } // signature information if (app.ConfigGet (L"IsCertificatesEnabled", false).AsBool () && ptr_app->is_signed) { - PR_OBJECT ptr_signature_object = _app_getsignatureinfo (idx, ptr_app); + PR_OBJECT ptr_signature_object = _app_getsignatureinfo (lparam, ptr_app); if (ptr_signature_object) { @@ -512,7 +517,7 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) if (!_app_isappexists (ptr_app)) buffer.AppendFormat (SZ_TAB L"%s\r\n", app.LocaleString (IDS_HIGHLIGHT_INVALID, nullptr).GetString ()); - if (listview_id != IDC_NETWORK && _app_isapphaveconnection (idx)) + if (listview_id != IDC_NETWORK && _app_isapphaveconnection (lparam)) buffer.AppendFormat (SZ_TAB L"%s\r\n", app.LocaleString (IDS_HIGHLIGHT_CONNECTION, nullptr).GetString ()); if (ptr_app->is_silent) @@ -553,7 +558,7 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) listview_id == IDC_RULES_CUSTOM ) { - PR_OBJECT ptr_rule_object = _app_getrulebyid (idx); + PR_OBJECT ptr_rule_object = _app_getrulebyid (lparam); if (ptr_rule_object) { @@ -567,7 +572,7 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) rule_remote = rule_remote.IsEmpty () ? app.LocaleString (IDS_STATUS_EMPTY, nullptr) : rule_remote.Replace (DIVIDER_RULE, L"\r\n" SZ_TAB); rule_local = rule_local.IsEmpty () ? app.LocaleString (IDS_STATUS_EMPTY, nullptr) : rule_local.Replace (DIVIDER_RULE, L"\r\n" SZ_TAB); - result.Format (L"%s (#%d)\r\n%s:\r\n%s%s\r\n%s:\r\n%s%s", ptr_rule->pname, idx, app.LocaleString (IDS_RULE, L" (" SZ_LOG_REMOTE_ADDRESS L")").GetString (), SZ_TAB, rule_remote.GetString (), app.LocaleString (IDS_RULE, L" (" SZ_LOG_LOCAL_ADDRESS L")").GetString (), SZ_TAB, rule_local.GetString ()); + result.Format (L"%s (#%d)\r\n%s:\r\n%s%s\r\n%s:\r\n%s%s", ptr_rule->pname, lparam, app.LocaleString (IDS_RULE, L" (" SZ_LOG_REMOTE_ADDRESS L")").GetString (), SZ_TAB, rule_remote.GetString (), app.LocaleString (IDS_RULE, L" (" SZ_LOG_LOCAL_ADDRESS L")").GetString (), SZ_TAB, rule_local.GetString ()); if (ptr_rule->is_forservices || !ptr_rule->apps.empty ()) result.AppendFormat (L"\r\n%s:\r\n%s%s", app.LocaleString (IDS_FILEPATH, nullptr).GetString (), SZ_TAB, _app_rulesexpand (ptr_rule, true, L"\r\n" SZ_TAB).GetString ()); @@ -580,9 +585,9 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) return result; } -void _app_setappiteminfo (HWND hwnd, UINT listview_id, size_t item, size_t app_hash, PITEM_APP ptr_app) +void _app_setappiteminfo (HWND hwnd, INT listview_id, INT item, size_t app_hash, PITEM_APP ptr_app) { - if (!ptr_app || !listview_id || item == LAST_VALUE) + if (!ptr_app || !listview_id || item == INVALID_INT) return; _app_getappicon (ptr_app, true, &ptr_app->icon_id, nullptr); @@ -593,9 +598,9 @@ void _app_setappiteminfo (HWND hwnd, UINT listview_id, size_t item, size_t app_h _r_listview_setitemcheck (hwnd, listview_id, item, ptr_app->is_enabled); } -void _app_setruleiteminfo (HWND hwnd, UINT listview_id, size_t item, PITEM_RULE ptr_rule, bool include_apps) +void _app_setruleiteminfo (HWND hwnd, INT listview_id, INT item, PITEM_RULE ptr_rule, bool include_apps) { - if (!ptr_rule || !listview_id || item == LAST_VALUE) + if (!ptr_rule || !listview_id || item == INVALID_INT) return; _r_listview_setitem (hwnd, listview_id, item, 0, ptr_rule->type == DataRuleCustom && ptr_rule->is_readonly ? _r_fmt (L"%s" SZ_READONLY_RULE, ptr_rule->pname) : ptr_rule->pname, _app_getruleicon (ptr_rule), _app_getrulegroup (ptr_rule)); @@ -618,9 +623,15 @@ void _app_setruleiteminfo (HWND hwnd, UINT listview_id, size_t item, PITEM_RULE if (ptr_app) { - const UINT app_listview_id = _app_getlistview_id (ptr_app->type); + const INT app_listview_id = _app_getlistview_id (ptr_app->type); - _app_setappiteminfo (hwnd, app_listview_id, _app_getposition (hwnd, app_listview_id, app_hash), app_hash, ptr_app); + if (app_listview_id) + { + const INT item_pos = _app_getposition (app.GetHWND (), app_listview_id, app_hash); + + if (item_pos != INVALID_INT) + _app_setappiteminfo (hwnd, app_listview_id, item_pos, app_hash, ptr_app); + } } _r_obj_dereference (ptr_app_object, &_app_dereferenceapp); @@ -753,7 +764,7 @@ void _app_ruleblocklistset (HWND hwnd, INT spy_state, INT update_state, INT extr { OBJECTS_VEC rules; - const UINT listview_id = _app_getlistview_id (DataRuleBlocklist); + const INT listview_id = _app_getlistview_id (DataRuleBlocklist); size_t changes_count = 0; for (size_t i = 0; i < rules_arr.size (); i++) @@ -782,12 +793,12 @@ void _app_ruleblocklistset (HWND hwnd, INT spy_state, INT update_state, INT extr if (hwnd) { - const size_t pos = _app_getposition (hwnd, listview_id, i); + const INT item_pos = _app_getposition (hwnd, listview_id, i); - if (pos != LAST_VALUE) + if (item_pos != INVALID_INT) { _r_fastlock_acquireshared (&lock_checkbox); - _app_setruleiteminfo (hwnd, listview_id, pos, ptr_rule, false); + _app_setruleiteminfo (hwnd, listview_id, item_pos, ptr_rule, false); _r_fastlock_releaseshared (&lock_checkbox); } } @@ -1002,12 +1013,12 @@ bool _app_isrulehost (LPCWSTR rule) for (size_t i = 0; i < _r_str_length (rule); i++) { if ( - rule[i] == L'#'|| - rule[i] == L'%'|| - rule[i] == L'&'|| - rule[i] == L'*'|| - rule[i] == L'@'|| - rule[i] == L')'|| + rule[i] == L'#' || + rule[i] == L'%' || + rule[i] == L'&' || + rule[i] == L'*' || + rule[i] == L'@' || + rule[i] == L')' || rule[i] == L'(' ) return false; @@ -1343,14 +1354,14 @@ void _app_profile_load_internal (LPCWSTR path, LPCWSTR path_backup, time_t * pti void _app_profile_load (HWND hwnd, LPCWSTR path_custom) { - const UINT current_listview_id = _app_gettab_id (hwnd); - const size_t selected_item = (size_t)SendDlgItemMessage (hwnd, current_listview_id, LVM_GETNEXTITEM, (WPARAM)-1, LVNI_SELECTED); + const INT current_listview_id = _app_gettab_id (hwnd); + const INT selected_item = (INT)SendDlgItemMessage (hwnd, current_listview_id, LVM_GETNEXTITEM, (WPARAM)-1, LVNI_SELECTED); const INT scroll_pos = GetScrollPos (GetDlgItem (hwnd, current_listview_id), SB_VERT); // clean listview if (hwnd) { - for (UINT i = IDC_APPS_PROFILE; i <= IDC_RULES_CUSTOM; i++) + for (INT i = IDC_APPS_PROFILE; i <= IDC_RULES_CUSTOM; i++) _r_listview_deleteallitems (hwnd, i); } @@ -1542,21 +1553,18 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_custom) if (ptr_app) { - const UINT listview_id = _app_getlistview_id (ptr_app->type); + const INT listview_id = _app_getlistview_id (ptr_app->type); if (listview_id) { - const size_t item = _r_listview_getitemcount (hwnd, listview_id); + const INT item = _r_listview_getitemcount (hwnd, listview_id); - if (item != LAST_VALUE) - { - _r_fastlock_acquireshared (&lock_checkbox); + _r_fastlock_acquireshared (&lock_checkbox); - _r_listview_additem (hwnd, listview_id, item, 0, ptr_app->display_name, ptr_app->icon_id, _app_getappgroup (app_hash, ptr_app), app_hash); - _app_setappiteminfo (hwnd, listview_id, item, app_hash, ptr_app); + _r_listview_additem (hwnd, listview_id, item, 0, ptr_app->display_name, ptr_app->icon_id, _app_getappgroup (app_hash, ptr_app), app_hash); + _app_setappiteminfo (hwnd, listview_id, item, app_hash, ptr_app); - _r_fastlock_releaseshared (&lock_checkbox); - } + _r_fastlock_releaseshared (&lock_checkbox); } // install timer @@ -1595,11 +1603,11 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_custom) if (ptr_rule) { - const UINT listview_id = _app_getlistview_id (ptr_rule->type); + const INT listview_id = _app_getlistview_id (ptr_rule->type); if (listview_id) { - const size_t item = _r_listview_getitemcount (hwnd, listview_id); + const INT item = _r_listview_getitemcount (hwnd, listview_id); _r_fastlock_acquireshared (&lock_checkbox); @@ -1618,7 +1626,7 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_custom) if (hwnd && current_listview_id) { - const UINT new_listview_id = _app_gettab_id (hwnd); + const INT new_listview_id = _app_gettab_id (hwnd); _app_listviewsort (hwnd, new_listview_id); diff --git a/src/profile.hpp b/src/profile.hpp index ee98bbfe..ad50e293 100644 --- a/src/profile.hpp +++ b/src/profile.hpp @@ -18,14 +18,14 @@ void _app_freeapplication (size_t hash); void _app_getcount (PITEM_STATUS ptr_status); -size_t _app_getappgroup (size_t app_hash, PITEM_APP ptr_app); -size_t _app_getrulegroup (PITEM_RULE ptr_rule); -size_t _app_getruleicon (PITEM_RULE ptr_rule); +INT _app_getappgroup (size_t app_hash, PITEM_APP ptr_app); +INT _app_getrulegroup (PITEM_RULE ptr_rule); +INT _app_getruleicon (PITEM_RULE ptr_rule); -rstring _app_gettooltip (UINT listview_id, size_t idx); +rstring _app_gettooltip (INT listview_id, size_t lparam); -void _app_setappiteminfo (HWND hwnd, UINT listview_id, size_t item, size_t app_hash, PITEM_APP ptr_app); -void _app_setruleiteminfo (HWND hwnd, UINT listview_id, size_t item, PITEM_RULE ptr_rule, bool include_apps); +void _app_setappiteminfo (HWND hwnd, INT listview_id, INT item, size_t app_hash, PITEM_APP ptr_app); +void _app_setruleiteminfo (HWND hwnd, INT listview_id, INT item, PITEM_RULE ptr_rule, bool include_apps); void _app_ruleenable (PITEM_RULE ptr_rule, bool is_enable); void _app_ruleenable2 (PITEM_RULE ptr_rule, bool is_enable); diff --git a/src/timer.cpp b/src/timer.cpp index 2edd79b1..d41723f3 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -53,15 +53,15 @@ bool _app_timer_set (HWND hwnd, PITEM_APP ptr_app, time_t seconds) } } - const UINT listview_id = _app_getlistview_id (ptr_app->type); - const size_t item = _app_getposition (hwnd, listview_id, app_hash); + const INT listview_id = _app_getlistview_id (ptr_app->type); + const INT item_pos = _app_getposition (hwnd, listview_id, app_hash); - if (item != LAST_VALUE) + if (item_pos != INVALID_INT) { _r_fastlock_acquireshared (&lock_checkbox); - _r_listview_setitem (hwnd, listview_id, item, 0, nullptr, LAST_VALUE, _app_getappgroup (app_hash, ptr_app)); - _r_listview_setitemcheck (hwnd, listview_id, item, ptr_app->is_enabled); + _r_listview_setitem (hwnd, listview_id, item_pos, 0, nullptr, INVALID_INT, _app_getappgroup (app_hash, ptr_app)); + _r_listview_setitemcheck (hwnd, listview_id, item_pos, ptr_app->is_enabled); _r_fastlock_releaseshared (&lock_checkbox); } @@ -89,16 +89,16 @@ bool _app_timer_reset (HWND hwnd, PITEM_APP ptr_app) ptr_app->timer = 0; const size_t app_hash = _r_str_hash (ptr_app->original_path); // note: be carefull (!) - const UINT listview_id = _app_getlistview_id (ptr_app->type); + const INT listview_id = _app_getlistview_id (ptr_app->type); if (listview_id) { - const size_t item = _app_getposition (hwnd, listview_id, app_hash); + const INT item_pos = _app_getposition (hwnd, listview_id, app_hash); - if (item != LAST_VALUE) + if (item_pos != INVALID_INT) { _r_fastlock_acquireshared (&lock_checkbox); - _app_setappiteminfo (hwnd, listview_id, item, app_hash, ptr_app); + _app_setappiteminfo (hwnd, listview_id, item_pos, app_hash, ptr_app); _r_fastlock_releaseshared (&lock_checkbox); } } @@ -166,7 +166,7 @@ void CALLBACK _app_timer_callback (PVOID lparam, BOOLEAN) _app_timer_reset (hwnd, ptr_app); _wfp_create3filters (rules, __LINE__); - const UINT listview_id = _app_gettab_id (hwnd); + const INT listview_id = _app_gettab_id (hwnd); _app_listviewsort (hwnd, listview_id);