diff --git a/src/global.hpp b/src/global.hpp index c8cece39..ec9c3a01 100644 --- a/src/global.hpp +++ b/src/global.hpp @@ -32,7 +32,7 @@ typedef std::vector MFILTER_RULES; typedef std::vector MTHREADPOOL; typedef std::unordered_map MAPPS_MAP; typedef std::unordered_map MCACHE_MAP; -typedef std::unordered_map MCACHETYPES_MAP; +typedef std::unordered_map MCACHETYPES_MAP; #include "helper.hpp" #include "log.hpp" diff --git a/src/helper.cpp b/src/helper.cpp index 4a162f6a..487cde80 100644 --- a/src/helper.cpp +++ b/src/helper.cpp @@ -9,14 +9,22 @@ UINT _app_gettab_id (HWND hwnd, size_t page_id) tci.mask = TCIF_PARAM; - SendDlgItemMessage (hwnd, IDC_TAB, TCM_GETITEM, ((page_id == LAST_VALUE) ? SendDlgItemMessage (hwnd, IDC_TAB, TCM_GETCURSEL, 0, 0) : page_id), (LPARAM)& tci); + if (page_id == LAST_VALUE) + { + page_id = (size_t)SendDlgItemMessage (hwnd, IDC_TAB, TCM_GETCURSEL, 0, 0); + + if (page_id == LAST_VALUE) + page_id = 0; + } + + SendDlgItemMessage (hwnd, IDC_TAB, TCM_GETITEM, page_id, (LPARAM)& tci); return (UINT)tci.lParam; } void _app_settab_id (HWND hwnd, size_t page_id) { - if (_app_gettab_id (hwnd) == page_id && IsWindowVisible (GetDlgItem (hwnd, (UINT)page_id))) + if (!page_id || (_app_gettab_id (hwnd) == page_id && IsWindowVisible (GetDlgItem (hwnd, (UINT)page_id)))) return; for (size_t i = 0; i < (size_t)SendDlgItemMessage (hwnd, IDC_TAB, TCM_GETITEMCOUNT, 0, 0); i++) @@ -30,6 +38,7 @@ void _app_settab_id (HWND hwnd, size_t page_id) NMHDR hdr = {0}; hdr.code = TCN_SELCHANGE; + hdr.hwndFrom = hwnd; hdr.idFrom = IDC_TAB; SendMessage (hwnd, WM_NOTIFY, 0, (LPARAM)& hdr); @@ -46,7 +55,10 @@ bool _app_initinterfacestate () const bool is_enabled = SendDlgItemMessage (config.hrebar, IDC_TOOLBAR, TB_ISBUTTONENABLED, IDM_TRAY_START, 0); if (is_enabled) + { SendDlgItemMessage (config.hrebar, IDC_TOOLBAR, TB_ENABLEBUTTON, IDM_TRAY_START, MAKELPARAM (false, 0)); + _r_status_settext (app.GetHWND (), IDC_STATUSBAR, 0, app.LocaleString (IDS_STATUS_FILTERS_PROCESSING, L"...")); + } return is_enabled; } @@ -54,15 +66,23 @@ bool _app_initinterfacestate () void _app_restoreinterfacestate (bool is_enabled) { if (is_enabled) + { SendDlgItemMessage (config.hrebar, IDC_TOOLBAR, TB_ENABLEBUTTON, IDM_TRAY_START, MAKELPARAM (true, 0)); + _r_status_settext (app.GetHWND (), IDC_STATUSBAR, 0, app.LocaleString (_wfp_isfiltersinstalled () ? IDS_STATUS_FILTERS_ACTIVE : IDS_STATUS_FILTERS_INACTIVE, nullptr)); + } } void _app_setinterfacestate (HWND hwnd) { const bool is_filtersinstalled = _wfp_isfiltersinstalled (); - SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM)app.GetSharedImage (app.GetHINSTANCE (), is_filtersinstalled ? IDI_ACTIVE : IDI_INACTIVE, GetSystemMetrics (SM_CXSMICON))); - SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM)app.GetSharedImage (app.GetHINSTANCE (), is_filtersinstalled ? IDI_ACTIVE : IDI_INACTIVE, GetSystemMetrics (SM_CXICON))); + const HICON hico_big = app.GetSharedImage (app.GetHINSTANCE (), is_filtersinstalled ? IDI_ACTIVE : IDI_INACTIVE, GetSystemMetrics (SM_CXICON)); + const HICON hico_sm = app.GetSharedImage (app.GetHINSTANCE (), is_filtersinstalled ? IDI_ACTIVE : IDI_INACTIVE, GetSystemMetrics (SM_CXSMICON)); + + SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM)hico_big); + SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hico_sm); + + //SendDlgItemMessage (hwnd, IDC_STATUSBAR, SB_SETICON, 0, (LPARAM)hico_sm); _r_toolbar_setbuttoninfo (config.hrebar, IDC_TOOLBAR, IDM_TRAY_START, app.LocaleString (is_filtersinstalled ? IDS_TRAY_STOP : IDS_TRAY_START, nullptr), BTNS_BUTTON | BTNS_AUTOSIZE | BTNS_SHOWTEXT, 0, is_filtersinstalled ? 3 : 2); @@ -95,15 +115,18 @@ bool _app_formataddress (ADDRESS_FAMILY af, PVOID const ptr_addr, UINT16 port, L if (InetNtop (af, ptr_addr, formatted_address, _countof (formatted_address))) { if (af == AF_INET) - result = !IN4_IS_ADDR_UNSPECIFIED ((PIN_ADDR)ptr_addr) && !IN4_IS_ADDR_LOOPBACK ((PIN_ADDR)ptr_addr); + result = !IN4_IS_ADDR_UNSPECIFIED ((PIN_ADDR)ptr_addr); else if (af == AF_INET6) - result = !IN6_IS_ADDR_UNSPECIFIED ((PIN6_ADDR)ptr_addr) && !IN6_IS_ADDR_LOOPBACK ((PIN6_ADDR)ptr_addr); + result = !IN6_IS_ADDR_UNSPECIFIED ((PIN6_ADDR)ptr_addr); + + if (!result) + formatted_address[0] = 0; } } if (port) - StringCchCat (formatted_address, _countof (formatted_address), _r_fmt (L":%d", port)); + StringCchCat (formatted_address, _countof (formatted_address), _r_fmt (formatted_address[0] ? L":%d" : L"%d", port)); if (result && is_appenddns && app.ConfigGet (L"IsNetworkResolutionsEnabled", false).AsBool () && config.is_wsainit) { @@ -139,7 +162,6 @@ bool _app_formataddress (ADDRESS_FAMILY af, PVOID const ptr_addr, UINT16 port, L _r_fastlock_acquireexclusive (&lock_cache); _app_freecache (&cache_hosts); - cache_hosts[hash] = cache_ptr; _r_fastlock_releaseexclusive (&lock_cache); @@ -149,7 +171,7 @@ bool _app_formataddress (ADDRESS_FAMILY af, PVOID const ptr_addr, UINT16 port, L _r_str_alloc (ptr_dest, _r_str_length (formatted_address), formatted_address); - return result; + return formatted_address[0] != 0; } void _app_freearray (std::vector * ptr) @@ -224,7 +246,7 @@ void _app_getappicon (ITEM_APP const *ptr_app, bool is_small, size_t * picon_id, { const bool is_iconshidden = app.ConfigGet (L"IsIconsHidden", false).AsBool (); - if (ptr_app->type == AppRegular || ptr_app->type == AppService) + if (ptr_app->type == DataAppRegular || ptr_app->type == DataAppService) { if (is_iconshidden || !_app_getfileicon (ptr_app->real_path, is_small, picon_id, picon)) { @@ -235,7 +257,7 @@ void _app_getappicon (ITEM_APP const *ptr_app, bool is_small, size_t * picon_id, *picon = CopyIcon (is_small ? config.hicon_small : config.hicon_large); } } - else if (ptr_app->type == AppPackage) + else if (ptr_app->type == DataAppPackage) { if (picon_id) *picon_id = config.icon_package_id; @@ -258,11 +280,11 @@ void _app_getdisplayname (size_t hash, ITEM_APP const *ptr_app, LPWSTR * extract if (!extracted_name) return; - if (ptr_app->type == AppService) + if (ptr_app->type == DataAppService) { _r_str_alloc (extracted_name, _r_str_length (ptr_app->original_path), ptr_app->original_path); } - else if (ptr_app->type == AppPackage) + else if (ptr_app->type == DataAppPackage) { rstring name; @@ -404,7 +426,6 @@ bool _app_getsignatureinfo (size_t hash, LPCWSTR path, LPWSTR * psigner) _r_fastlock_acquireshared (&lock_cache); LPCWSTR ptr_text = cache_signatures[hash]; - _r_str_alloc (psigner, _r_str_length (ptr_text), ptr_text); _r_fastlock_releaseshared (&lock_cache); @@ -416,7 +437,7 @@ bool _app_getsignatureinfo (size_t hash, LPCWSTR path, LPWSTR * psigner) cache_signatures[hash] = nullptr; - const HANDLE hfile = CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OPEN_REPARSE_POINT, nullptr); + const HANDLE hfile = CreateFile (path, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OPEN_REPARSE_POINT, nullptr); if (hfile != INVALID_HANDLE_VALUE) { @@ -505,7 +526,6 @@ bool _app_getversioninfo (size_t hash, LPCWSTR path, LPWSTR * pinfo) _r_fastlock_acquireshared (&lock_cache); LPCWSTR ptr_text = cache_versions[hash]; - _r_str_alloc (pinfo, _r_str_length (ptr_text), ptr_text); _r_fastlock_releaseshared (&lock_cache); @@ -640,6 +660,47 @@ rstring _app_getprotoname (UINT8 proto) return SZ_EMPTY; } +rstring _app_getstatename (DWORD state) +{ + if(state== MIB_TCP_STATE_CLOSED) + return L"Closed"; + + else if (state == MIB_TCP_STATE_LISTEN) + return L"Listen"; + + else if (state == MIB_TCP_STATE_SYN_SENT) + return L"SYN sent"; + + else if (state == MIB_TCP_STATE_SYN_RCVD) + return L"SYN received"; + + else if (state == MIB_TCP_STATE_ESTAB) + return L"Established"; + + else if (state == MIB_TCP_STATE_FIN_WAIT1) + return L"FIN wait 1"; + + else if (state == MIB_TCP_STATE_FIN_WAIT2) + return L"FIN wait 2"; + + else if (state == MIB_TCP_STATE_CLOSE_WAIT) + return L"Close wait"; + + else if (state == MIB_TCP_STATE_CLOSING) + return L"Closing"; + + else if (state == MIB_TCP_STATE_LAST_ACK) + return L"Last ACK"; + + else if (state == MIB_TCP_STATE_TIME_WAIT) + return L"Time wait"; + + else if (state == MIB_TCP_STATE_DELETE_TCB) + return L"Delete TCB"; + + return L""; +} + rstring getprocname (DWORD pid) { WCHAR real_path[MAX_PATH] = {0}; @@ -702,9 +763,7 @@ void _app_generate_connections () ( IN4_IS_ADDR_UNSPECIFIED (&ptr_network->remote_addr) && IN4_IS_ADDR_UNSPECIFIED (&ptr_network->local_addr) - || - IN4_IS_ADDR_LOOPBACK (&ptr_network->remote_addr) && - IN4_IS_ADDR_LOOPBACK (&ptr_network->local_addr)) && + ) && !tcp4Table->table[i].dwRemotePort && !tcp4Table->table[i].dwLocalPort ) @@ -727,6 +786,8 @@ void _app_generate_connections () ptr_network->remote_port = (UINT16)tcp4Table->table[i].dwRemotePort; ptr_network->local_port = (UINT16)tcp4Table->table[i].dwLocalPort; + ptr_network->state = tcp4Table->table[i].dwState; + network_arr.push_back (ptr_network); } } @@ -751,11 +812,7 @@ void _app_generate_connections () if ( ( IN6_IS_ADDR_UNSPECIFIED ((PIN6_ADDR)tcp6Table->table[i].ucRemoteAddr) && - IN6_IS_ADDR_UNSPECIFIED ((PIN6_ADDR)tcp6Table->table[i].ucLocalAddr) - || - IN6_IS_ADDR_LOOPBACK ((PIN6_ADDR)tcp6Table->table[i].ucRemoteAddr) && - IN6_IS_ADDR_LOOPBACK ((PIN6_ADDR)tcp6Table->table[i].ucLocalAddr) - ) && + IN6_IS_ADDR_UNSPECIFIED ((PIN6_ADDR)tcp6Table->table[i].ucLocalAddr)) && !tcp6Table->table[i].dwRemotePort && !tcp6Table->table[i].dwLocalPort ) @@ -780,6 +837,8 @@ void _app_generate_connections () ptr_network->remote_port = (UINT16)tcp6Table->table[i].dwRemotePort; ptr_network->local_port = (UINT16)tcp6Table->table[i].dwLocalPort; + ptr_network->state = tcp6Table->table[i].dwState; + network_arr.push_back (ptr_network); } } @@ -804,6 +863,17 @@ void _app_generate_connections () PITEM_NETWORK ptr_network = new ITEM_NETWORK; + ptr_network->local_addr.S_un.S_addr = udp4Table->table[i].dwLocalAddr; + + if ( + IN4_IS_ADDR_UNSPECIFIED (&ptr_network->local_addr) && + !udp4Table->table[i].dwLocalPort + ) + { + SAFE_DELETE (ptr_network); + continue; + } + WCHAR path_name[MAX_PATH] = {0}; StringCchCopy (path_name, _countof (path_name), getprocname (udp4Table->table[i].dwOwningPid)); @@ -815,9 +885,10 @@ void _app_generate_connections () ptr_network->protocol = IPPROTO_UDP; ptr_network->hash = _r_str_hash (ptr_network->path); - ptr_network->local_addr.S_un.S_addr = udp4Table->table[i].dwLocalAddr; ptr_network->local_port = (UINT16)udp4Table->table[i].dwLocalPort; + ptr_network->state = 0; + network_arr.push_back (ptr_network); } } @@ -840,9 +911,7 @@ void _app_generate_connections () continue; if ( - (IN6_IS_ADDR_UNSPECIFIED ((PIN6_ADDR)udp6Table->table[i].ucLocalAddr) - || - IN6_IS_ADDR_LOOPBACK ((PIN6_ADDR)udp6Table->table[i].ucLocalAddr)) && + IN6_IS_ADDR_UNSPECIFIED ((PIN6_ADDR)udp6Table->table[i].ucLocalAddr) && !udp6Table->table[i].dwLocalPort ) continue; @@ -864,6 +933,8 @@ void _app_generate_connections () ptr_network->local_port = (UINT16)udp6Table->table[i].dwLocalPort; + ptr_network->state = 0; + network_arr.push_back (ptr_network); } } @@ -954,7 +1025,7 @@ void _app_generate_packages () if (RegQueryInfoKey (hsubkey, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, &ft) == ERROR_SUCCESS) ptr_item->timestamp = _r_unixtime_from_filetime (&ft); - ptr_item->type = AppPackage; + ptr_item->type = DataAppPackage; _r_str_alloc (&ptr_item->sid, package_sid_string.GetLength (), package_sid_string); _r_str_alloc (&ptr_item->display_name, _r_str_length (display_name), display_name); @@ -1129,7 +1200,6 @@ void _app_generate_services () LPCWSTR display_name = psvc->lpDisplayName; LPCWSTR service_name = psvc->lpServiceName; - WCHAR buffer[MAX_PATH] = {0}; WCHAR real_path[MAX_PATH] = {0}; time_t timestamp = 0; @@ -1206,18 +1276,13 @@ void _app_generate_services () } UNICODE_STRING serviceNameUs = {0}; + RtlInitUnicodeString (&serviceNameUs, (PWSTR)service_name); - serviceNameUs.Buffer = buffer; - serviceNameUs.Length = (USHORT)(_r_str_length (service_name) * sizeof (WCHAR)); - serviceNameUs.MaximumLength = serviceNameUs.Length; - - StringCchCopy (buffer, _countof (buffer), service_name); + rstring sidstring; SID *serviceSid = nullptr; ULONG serviceSidLength = 0; - rstring sidstring; - // get service security identifier if (RtlCreateServiceSid (&serviceNameUs, serviceSid, &serviceSidLength) == 0xC0000023 /*STATUS_BUFFER_TOO_SMALL*/) { @@ -1242,7 +1307,7 @@ void _app_generate_services () ptr_item->hash = _r_str_hash (service_name); ptr_item->timestamp = timestamp; - ptr_item->type = AppService; + ptr_item->type = DataAppService; _r_str_alloc (&ptr_item->service_name, _r_str_length (service_name), service_name); _r_str_alloc (&ptr_item->display_name, _r_str_length (display_name), display_name); @@ -1330,7 +1395,7 @@ void _app_generate_rulesmenu (HMENU hsubmenu, size_t app_hash) const bool is_global = (ptr_rule->is_enabled && ptr_rule->apps.empty ()); const bool is_enabled = is_global || (ptr_rule->is_enabled && (ptr_rule->apps.find (app_hash) != ptr_rule->apps.end ())); - if (ptr_rule->type != TypeCustom || (type == 0 && (!ptr_rule->is_readonly || is_global)) || (type == 1 && (ptr_rule->is_readonly || is_global)) || (type == 2 && !is_global)) + if (ptr_rule->type != DataRuleCustom || (type == 0 && (!ptr_rule->is_readonly || is_global)) || (type == 1 && (ptr_rule->is_readonly || is_global)) || (type == 2 && !is_global)) continue; if ((loop == 0 && !is_enabled) || (loop == 1 && is_enabled)) @@ -1366,7 +1431,7 @@ void _app_generate_rulesmenu (HMENU hsubmenu, size_t app_hash) AppendMenu (hsubmenu, MF_STRING, IDM_OPENRULESEDITOR, app.LocaleString (IDS_OPENRULESEDITOR, L"...")); } -bool _app_item_get (EnumAppType type, size_t hash, rstring * display_name, rstring * real_path, PSID * lpsid, PSECURITY_DESCRIPTOR * lpsd, rstring * /*description*/) +bool _app_item_get (EnumDataType type, size_t hash, rstring * display_name, rstring * real_path, PSID * lpsid, PSECURITY_DESCRIPTOR * lpsd, rstring * /*description*/) { for (size_t i = 0; i < items.size (); i++) { @@ -1439,150 +1504,78 @@ bool _app_item_get (EnumAppType type, size_t hash, rstring * display_name, rstri return false; } -INT CALLBACK _app_listviewcompare_abc (LPARAM item1, LPARAM item2, LPARAM lparam) +INT CALLBACK _app_listviewcompare_callback (LPARAM item1, LPARAM item2, LPARAM lparam) { - HWND hwnd = GetParent ((HWND)lparam); - const UINT ctrl_id = GetDlgCtrlID ((HWND)lparam); + const HWND hwnd = GetParent ((HWND)lparam); + const UINT listview_id = GetDlgCtrlID ((HWND)lparam); - const bool is_checked1 = _r_listview_isitemchecked (hwnd, ctrl_id, (size_t)item1); - const bool is_checked2 = _r_listview_isitemchecked (hwnd, ctrl_id, (size_t)item2); + const rstring cfg_name = _r_fmt (L"listview\\%04x", listview_id); - if ((is_checked1 || is_checked2) && (is_checked1 != is_checked2)) - { - if (is_checked1 && !is_checked2) - return -1; - - if (!is_checked1 && is_checked2) - return 1; - } - - const rstring str1 = _r_listview_getitemtext (hwnd, ctrl_id, (size_t)item1, 0); - const rstring str2 = _r_listview_getitemtext (hwnd, ctrl_id, (size_t)item2, 0); - - return StrCmpLogicalW (str1, str2); -} - -INT CALLBACK _app_listviewcompare_apps (LPARAM lp1, LPARAM lp2, LPARAM lparam) -{ - const UINT column_id = LOWORD (lparam); - const BOOL is_descend = HIWORD (lparam); - - const size_t hash1 = static_cast(lp1); - const size_t hash2 = static_cast(lp2); + const UINT column_id = app.ConfigGet (L"SortColumn", 0, cfg_name).AsUint (); + const bool is_descend = app.ConfigGet (L"SortIsDescending", false, cfg_name).AsBool (); INT result = 0; - PITEM_APP const ptr_app1 = _app_getapplication (hash1); - PITEM_APP const ptr_app2 = _app_getapplication (hash2); - - if (!ptr_app1 || !ptr_app2) - return 0; - - if (column_id == 0) + if ((GetWindowLongPtr ((HWND)lparam, GWL_EXSTYLE) & LVS_EX_CHECKBOXES) != 0) { - // file - result = StrCmpLogicalW (ptr_app1->display_name, ptr_app2->display_name); + const bool is_checked1 = _r_listview_isitemchecked (hwnd, listview_id, (size_t)item1); + const bool is_checked2 = _r_listview_isitemchecked (hwnd, listview_id, (size_t)item2); + + if ((is_checked1 || is_checked2) && (is_checked1 != is_checked2)) + { + if (is_checked1 && !is_checked2) + result = is_descend ? 1 : -1; + + if (!is_checked1 && is_checked2) + result = is_descend ? -1 : 1; + } } - else if (column_id == 1) + + if (!result) { - // timestamp - if (ptr_app1->timestamp == ptr_app2->timestamp) - result = 0; + const rstring str1 = _r_listview_getitemtext (hwnd, listview_id, (size_t)item1, column_id); + const rstring str2 = _r_listview_getitemtext (hwnd, listview_id, (size_t)item2, column_id); - else if (ptr_app1->timestamp < ptr_app2->timestamp) - result = -1; - - else if (ptr_app1->timestamp > ptr_app2->timestamp) - result = 1; + result = StrCmpLogicalW (str1, str2); } return is_descend ? -result : result; } -INT CALLBACK _app_listviewcompare_rules (LPARAM item1, LPARAM item2, LPARAM lparam) +void _app_listviewsort (HWND hwnd, UINT listview_id, INT subitem, bool is_notifycode) { - const UINT listview_id = (UINT)lparam; + if (!listview_id) + return; - const UINT column_id = app.ConfigGet (L"SortColumnRules", 0).AsUint (); - const bool is_descend = app.ConfigGet (L"IsSortDescendingRules", false).AsBool (); + const rstring cfg_name = _r_fmt (L"listview\\%04x", listview_id); - const rstring str1 = _r_listview_getitemtext (app.GetHWND (), listview_id, (size_t)item1, column_id); - const rstring str2 = _r_listview_getitemtext (app.GetHWND (), listview_id, (size_t)item2, column_id); + bool is_descend = app.ConfigGet (L"SortIsDescending", false, cfg_name).AsBool (); - const INT result = StrCmpLogicalW (str1, str2); + if (is_notifycode) + is_descend = !is_descend; - return is_descend ? -result : result; -} + if (subitem == -1) + subitem = app.ConfigGet (L"SortColumn", 0, cfg_name).AsBool (); -void _app_listviewsort (HWND hwnd, UINT ctrl_id, INT subitem, bool is_notifycode) -{ - _r_fastlock_acquireshared (&lock_access); - - for (INT i = 0; i < _r_listview_getcolumncount (hwnd, ctrl_id); i++) - _r_listview_setcolumnsortindex (hwnd, ctrl_id, i, 0); - - if ( - ctrl_id == IDC_APPS_PROFILE || - ctrl_id == IDC_APPS_SERVICE || - ctrl_id == IDC_APPS_PACKAGE - ) + if (is_notifycode) { - bool is_descend = app.ConfigGet (L"IsSortDescending", true).AsBool (); - - if (is_notifycode) - is_descend = !is_descend; - - if (subitem == -1) - subitem = app.ConfigGet (L"SortColumn", 1).AsBool (); - - const WPARAM wparam = MAKEWPARAM (subitem, is_descend); - - if (is_notifycode) - { - app.ConfigSet (L"IsSortDescending", is_descend); - app.ConfigSet (L"SortColumn", (DWORD)subitem); - } - - _r_listview_setcolumnsortindex (hwnd, ctrl_id, subitem, is_descend ? -1 : 1); - - SendDlgItemMessage (hwnd, ctrl_id, LVM_SORTITEMS, wparam, (LPARAM)& _app_listviewcompare_apps); - - _app_refreshstatus (hwnd); - } - else if ( - ctrl_id == IDC_RULES_BLOCKLIST || - ctrl_id == IDC_RULES_SYSTEM || - ctrl_id == IDC_RULES_CUSTOM - ) - { - bool is_descend = app.ConfigGet (L"IsSortDescendingRules", false).AsBool (); - - if (is_notifycode) - is_descend = !is_descend; - - if (subitem == -1) - subitem = app.ConfigGet (L"SortColumnRules", 0).AsUint (); - - if (is_notifycode) - { - app.ConfigSet (L"IsSortDescendingRules", is_descend); - app.ConfigSet (L"SortColumnRules", (DWORD)subitem); - } - - _r_listview_setcolumnsortindex (hwnd, ctrl_id, subitem, is_descend ? -1 : 1); - - SendDlgItemMessage (hwnd, ctrl_id, LVM_SORTITEMSEX, (WPARAM)ctrl_id, (LPARAM)& _app_listviewcompare_rules); - } - else - { - SendDlgItemMessage (hwnd, ctrl_id, LVM_SORTITEMSEX, (WPARAM)GetDlgItem (hwnd, ctrl_id), (LPARAM)& _app_listviewcompare_abc); + app.ConfigSet (L"SortIsDescending", is_descend, cfg_name); + app.ConfigSet (L"SortColumn", (DWORD)subitem, cfg_name); } - _r_fastlock_releaseshared (&lock_access); + for (INT i = 0; i < _r_listview_getcolumncount (hwnd, listview_id); i++) + _r_listview_setcolumnsortindex (hwnd, listview_id, i, 0); + + _r_listview_setcolumnsortindex (hwnd, listview_id, subitem, is_descend ? -1 : 1); + + SendDlgItemMessage (hwnd, listview_id, LVM_SORTITEMSEX, (WPARAM)GetDlgItem (hwnd, listview_id), (LPARAM)& _app_listviewcompare_callback); } void _app_refreshstatus (HWND hwnd) { + ITEM_STATUS stat = {0}; + _app_getcount (&stat); + const HWND hstatus = GetDlgItem (hwnd, IDC_STATUSBAR); const HDC hdc = GetDC (hstatus); @@ -1592,26 +1585,20 @@ void _app_refreshstatus (HWND hwnd) SelectObject (hdc, (HFONT)SendMessage (hstatus, WM_GETFONT, 0, 0)); // fix static const UINT parts_count = 3; + static const UINT padding = app.GetDPI (8); rstring text[parts_count]; INT parts[parts_count] = {0}; LONG size[parts_count] = {0}; LONG lay = 0; - _r_fastlock_acquireshared (&lock_access); - - ITEM_STATUS stat = {0}; - _app_getcount (&stat); - - _r_fastlock_releaseshared (&lock_access); - for (UINT i = 0; i < parts_count; i++) { switch (i) { case 0: { - text[i].Format (app.LocaleString (IDS_STATUS_TOTAL, nullptr), stat.apps_count); + text[i] = app.LocaleString (_wfp_isfiltersinstalled () ? IDS_STATUS_FILTERS_ACTIVE : IDS_STATUS_FILTERS_INACTIVE, nullptr); break; } @@ -1628,7 +1615,7 @@ void _app_refreshstatus (HWND hwnd) } } - size[i] = _r_dc_fontwidth (hdc, text[i], text[i].GetLength ()) + 10; + size[i] = _r_dc_fontwidth (hdc, text[i], text[i].GetLength ()) + padding; if (i) lay += size[i]; @@ -1637,14 +1624,17 @@ void _app_refreshstatus (HWND hwnd) RECT rc = {0}; GetClientRect (hstatus, &rc); - parts[0] = _R_RECT_WIDTH (&rc) - lay - GetSystemMetrics (SM_CXSMICON); + parts[0] = _R_RECT_WIDTH (&rc) - lay - GetSystemMetrics (SM_CXVSCROLL); parts[1] = parts[0] + size[1]; parts[2] = parts[1] + size[2]; SendMessage (hstatus, SB_SETPARTS, parts_count, (LPARAM)parts); for (UINT i = 0; i < parts_count; i++) + { SendMessage (hstatus, SB_SETTEXT, MAKEWPARAM (i, 0), (LPARAM)text[i].GetString ()); + SendMessage (hstatus, SB_SETTIPTEXT, i, (LPARAM)text[i].GetString ()); + } ReleaseDC (hstatus, hdc); } @@ -1840,7 +1830,7 @@ rstring _app_parsehostaddress_wsa (LPCWSTR hostname, USHORT port) struct sockaddr_in *sock_in4 = (struct sockaddr_in *)current->ai_addr; PIN_ADDR addr4 = &(sock_in4->sin_addr); - if (IN4_IS_ADDR_UNSPECIFIED (addr4) || IN4_IS_ADDR_LOOPBACK (addr4)) + if (IN4_IS_ADDR_UNSPECIFIED (addr4)) continue; InetNtop (current->ai_family, addr4, printableIP, _countof (printableIP)); @@ -1850,7 +1840,7 @@ rstring _app_parsehostaddress_wsa (LPCWSTR hostname, USHORT port) struct sockaddr_in6 *sock_in6 = (struct sockaddr_in6 *)current->ai_addr; PIN6_ADDR addr6 = &(sock_in6->sin6_addr); - if (IN6_IS_ADDR_UNSPECIFIED (addr6) || IN6_IS_ADDR_LOOPBACK (addr6)) + if (IN6_IS_ADDR_UNSPECIFIED (addr6)) continue; InetNtop (current->ai_family, addr6, printableIP, _countof (printableIP)); @@ -1983,7 +1973,7 @@ bool _app_parserulestring (rstring rule, PITEM_ADDRESS ptr_addr) if (rule.At (0) == L'*') return true; - EnumRuleItemType type = TypeRuleItemUnknown; + EnumDataType type = DataUnknown; const size_t range_pos = rule.Find (RULE_RANGE_CHAR); bool is_range = (range_pos != rstring::npos); @@ -2007,27 +1997,25 @@ bool _app_parserulestring (rstring rule, PITEM_ADDRESS ptr_addr) if (is_exists) { _r_fastlock_acquireshared (&lock_cache); - type = cache_types[hash]; - _r_fastlock_releaseshared (&lock_cache); } else { if (_app_isruleport (rule)) { - type = TypePort; + type = DataTypePort; } else if (is_range ? (_app_isruleip (range_start) && _app_isruleip (range_end)) : _app_isruleip (rule)) { - type = TypeIp; + type = DataTypeIp; } else if (_app_isrulehost (rule)) { - type = TypeHost; + type = DataTypeHost; } - if (type != TypeRuleItemUnknown) + if (type != DataUnknown) { _r_fastlock_acquireexclusive (&lock_cache); @@ -2041,23 +2029,23 @@ bool _app_parserulestring (rstring rule, PITEM_ADDRESS ptr_addr) } } - if (type == TypeRuleItemUnknown) + if (type == DataUnknown) return false; if (!ptr_addr) return true; - if (type == TypeHost) + if (type == DataTypeHost) is_range = false; ptr_addr->is_range = is_range; - if (type == TypePort) + if (type == DataTypePort) { if (!is_range) { // ...port - ptr_addr->type = TypePort; + ptr_addr->type = DataTypePort; ptr_addr->port = (UINT16)rule.AsUint (); return true; @@ -2065,7 +2053,7 @@ bool _app_parserulestring (rstring rule, PITEM_ADDRESS ptr_addr) else { // ...port range - ptr_addr->type = TypePort; + ptr_addr->type = DataTypePort; if (ptr_addr->prange) { @@ -2088,7 +2076,7 @@ bool _app_parserulestring (rstring rule, PITEM_ADDRESS ptr_addr) USHORT port2 = 0; - if (type == TypeIp && is_range) + if (type == DataTypeIp && is_range) { // ...ip range (start) if (_app_parsenetworkstring (range_start, &format, &port2, &addr4, &addr6, nullptr, 0)) @@ -2152,7 +2140,7 @@ bool _app_parserulestring (rstring rule, PITEM_ADDRESS ptr_addr) } ptr_addr->format = format; - ptr_addr->type = TypeIp; + ptr_addr->type = DataTypeIp; } else { @@ -2184,7 +2172,7 @@ bool _app_parserulestring (rstring rule, PITEM_ADDRESS ptr_addr) return false; } - ptr_addr->type = TypeIp; + ptr_addr->type = DataTypeIp; ptr_addr->format = format; if (port2) @@ -2263,45 +2251,25 @@ void _app_resolvefilename (rstring & path) } } -UINT _app_getapplistview_id (size_t hash) +UINT _app_getlistview_id (EnumDataType type) { - _r_fastlock_acquireshared (&lock_access); + if (type == DataAppService) + return IDC_APPS_SERVICE; - PITEM_APP ptr_app = _app_getapplication (hash); - const EnumAppType type = ptr_app ? ptr_app->type : AppRegular; + else if (type == DataAppPackage) + return IDC_APPS_PACKAGE; - _r_fastlock_releaseshared (&lock_access); + else if (type == DataAppRegular || type == DataAppDevice || type == DataAppNetwork || type == DataAppPico) + return IDC_APPS_PROFILE; - if (ptr_app) - { - if (type == AppService) - return IDC_APPS_SERVICE; + else if (type == DataRuleBlocklist) + return IDC_RULES_BLOCKLIST; - else if (type == AppPackage) - return IDC_APPS_PACKAGE; + else if (type == DataRuleSystem) + return IDC_RULES_SYSTEM; - else - return IDC_APPS_PROFILE; - } - - return 0; -} - -UINT _app_getrulelistview_id (const PITEM_RULE ptr_rule) -{ - const EnumRuleType type = ptr_rule->type; - - if (ptr_rule) - { - if (type == TypeBlocklist) - return IDC_RULES_BLOCKLIST; - - else if (type == TypeSystem) - return IDC_RULES_SYSTEM; - - else if (ptr_rule->type == TypeCustom) - return IDC_RULES_CUSTOM; - } + else if (type == DataRuleCustom) + return IDC_RULES_CUSTOM; return 0; } diff --git a/src/helper.hpp b/src/helper.hpp index 4adc07bd..2747fccb 100644 --- a/src/helper.hpp +++ b/src/helper.hpp @@ -26,6 +26,7 @@ bool _app_getsignatureinfo (size_t hash, LPCWSTR path, LPWSTR* psigner); bool _app_getversioninfo (size_t hash, LPCWSTR path, LPWSTR* pinfo); size_t _app_getposition (HWND hwnd, size_t hash); rstring _app_getprotoname (UINT8 proto); +rstring _app_getstatename (DWORD state); void _app_generate_connections (); void _app_generate_packages (); @@ -33,12 +34,10 @@ void _app_generate_services (); void _app_generate_rulesmenu (HMENU hsubmenu, size_t app_hash); -bool _app_item_get (EnumAppType type, size_t hash, rstring* display_name, rstring* real_path, PSID* lpsid, PSECURITY_DESCRIPTOR* lpsd, rstring* /*description*/); +bool _app_item_get (EnumDataType type, size_t hash, rstring* display_name, rstring* real_path, PSID* lpsid, PSECURITY_DESCRIPTOR* lpsd, rstring* /*description*/); -INT CALLBACK _app_listviewcompare_abc (LPARAM item1, LPARAM item2, LPARAM lparam); -INT CALLBACK _app_listviewcompare_apps (LPARAM lp1, LPARAM lp2, LPARAM lparam); -INT CALLBACK _app_listviewcompare_rules (LPARAM item1, LPARAM item2, LPARAM lparam); -void _app_listviewsort (HWND hwnd, UINT ctrl_id, INT subitem = -1, bool is_notifycode = false); +INT CALLBACK _app_listviewcompare_callback (LPARAM lp1, LPARAM lp2, LPARAM lparam); +void _app_listviewsort (HWND hwnd, UINT listview_id, INT subitem = -1, bool is_notifycode = false); void _app_refreshstatus (HWND hwnd); @@ -51,8 +50,7 @@ bool _app_parserulestring (rstring rule, PITEM_ADDRESS ptr_addr); bool _app_resolveaddress (ADDRESS_FAMILY af, LPVOID paddr, LPWSTR buffer, DWORD length); void _app_resolvefilename (rstring& path); -UINT _app_getapplistview_id (size_t hash); -UINT _app_getrulelistview_id (const PITEM_RULE ptr_rule); +UINT _app_getlistview_id (EnumDataType type); void _app_showitem (HWND hwnd, UINT listview_id, LPARAM lparam, INT scroll_pos = -1); diff --git a/src/log.cpp b/src/log.cpp index 9ad7a287..8074c3d7 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -76,7 +76,7 @@ bool _app_loginit (bool is_install) if (!is_install) return true; // already closed - // check if log enabled + // check if log enabled if (!app.ConfigGet (L"IsLogEnabled", false).AsBool ()) return false; @@ -86,7 +86,7 @@ bool _app_loginit (bool is_install) _r_fastlock_acquireexclusive (&lock_writelog); - config.hlogfile = CreateFile (path, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + config.hlogfile = CreateFile (path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (config.hlogfile == INVALID_HANDLE_VALUE) { @@ -130,7 +130,7 @@ void _app_logwrite (PITEM_LOG const ptr_log) if (ptr_app) { - if (ptr_app->type == AppPackage || ptr_app->type == AppService) + if (ptr_app->type == DataAppPackage || ptr_app->type == DataAppService) { if (ptr_app->real_path && ptr_app->real_path[0]) path = ptr_app->real_path; @@ -207,8 +207,6 @@ void _app_logclear () { const rstring path = _r_path_expand (app.ConfigGet (L"LogPath", LOG_PATH_DEFAULT)); - _r_fastlock_acquireexclusive (&lock_writelog); - if (config.hlogfile != nullptr && config.hlogfile != INVALID_HANDLE_VALUE) { _r_fs_setpos (config.hlogfile, 2, FILE_BEGIN); @@ -222,8 +220,6 @@ void _app_logclear () } _r_fs_delete (_r_fmt (L"%s.bak", path.GetString ()), false); - - _r_fastlock_releaseexclusive (&lock_writelog); } bool _wfp_logsubscribe () @@ -384,12 +380,6 @@ void CALLBACK _wfp_logcallback (UINT32 flags, FILETIME const *pft, UINT8 const * { PITEM_LOG ptr_log = new ITEM_LOG; - if (!ptr_log) - { - _aligned_free (ptr_entry); - return; - } - // get package id (win8+) rstring sidstring; @@ -397,7 +387,7 @@ void CALLBACK _wfp_logcallback (UINT32 flags, FILETIME const *pft, UINT8 const * { sidstring = _r_str_fromsid (package_id); - if (sidstring.IsEmpty () || !_app_item_get (AppPackage, sidstring.Hash (), nullptr, nullptr, nullptr, nullptr, nullptr)) + if (sidstring.IsEmpty () || !_app_item_get (DataAppPackage, sidstring.Hash (), nullptr, nullptr, nullptr, nullptr, nullptr)) sidstring.Clear (); } @@ -416,7 +406,7 @@ void CALLBACK _wfp_logcallback (UINT32 flags, FILETIME const *pft, UINT8 const * ptr_log->hash = path.Hash (); - _app_applycasestyle (ptr_log->path, _r_str_length (ptr_log->path)); // apply case-style + _app_applycasestyle (ptr_log->path, path.GetLength ()); // apply case-style } else { @@ -557,11 +547,11 @@ void CALLBACK _wfp_logcallback (UINT32 flags, FILETIME const *pft, UINT8 const * // check if thread has been terminated const LONG thread_count = InterlockedCompareExchange (&log_stack.thread_count, 0, 0); - if (!_r_fastlock_islocked (&lock_logthread) || ((_r_fastlock_islocked (&lock_logbusy) || InterlockedCompareExchange (&log_stack.item_count, 0, 0) >= NOTIFY_LIMIT_POOL_SIZE) && (thread_count >= 1 && thread_count < NOTIFY_LIMIT_THREAD_COUNT))) + if (!_r_fastlock_islocked (&lock_logthread) || (_r_fastlock_islocked (&lock_logbusy) && InterlockedCompareExchange (&log_stack.item_count, 0, 0) >= NOTIFY_LIMIT_POOL_SIZE && thread_count >= 1 && thread_count < NOTIFY_LIMIT_THREAD_COUNT)) { _r_fastlock_acquireexclusive (&lock_threadpool); - _app_freethreadpool (&threads_pool); + _r_fastlock_releaseexclusive (&lock_threadpool); const HANDLE hthread = _r_createthread (&LogThread, app.GetHWND (), true, THREAD_PRIORITY_BELOW_NORMAL); @@ -569,11 +559,12 @@ void CALLBACK _wfp_logcallback (UINT32 flags, FILETIME const *pft, UINT8 const * { InterlockedIncrement (&log_stack.thread_count); + _r_fastlock_acquireexclusive (&lock_threadpool); threads_pool.push_back (hthread); + _r_fastlock_releaseexclusive (&lock_threadpool); + ResumeThread (hthread); } - - _r_fastlock_releaseexclusive (&lock_threadpool); } } } @@ -833,22 +824,29 @@ UINT WINAPI LogThread (LPVOID lparam) const bool is_notificationenabled = app.ConfigGet (L"IsNotificationsEnabled", true).AsBool (); // apps collector - _r_fastlock_acquireshared (&lock_access); - const bool is_notexist = ptr_log->hash && ptr_log->path && !ptr_log->is_allow && apps.find (ptr_log->hash) == apps.end (); - _r_fastlock_releaseshared (&lock_access); + const bool is_notexist = ptr_log->hash && ptr_log->path && ptr_log->path[0] && !ptr_log->is_allow && apps.find (ptr_log->hash) == apps.end (); if (is_notexist) { _r_fastlock_acquireshared (&lock_logbusy); _r_fastlock_acquireexclusive (&lock_access); - _app_addapplication (hwnd, ptr_log->path, 0, 0, 0, false, false, true); + const size_t app_hash = _app_addapplication (hwnd, ptr_log->path, 0, 0, 0, false, false, true); _r_fastlock_releaseexclusive (&lock_access); _r_fastlock_releaseshared (&lock_logbusy); - _app_listviewsort (hwnd, IDC_APPS_PROFILE); - _app_profile_save (hwnd); + const PITEM_APP ptr_app = _app_getapplication (app_hash); + + if (ptr_app) + { + const UINT listview_id = _app_getlistview_id (ptr_app->type); + + if (_app_gettab_id (hwnd) == listview_id) + _app_listviewsort (hwnd, listview_id); + } + + _app_profile_save (); } bool is_added = false; @@ -872,7 +870,7 @@ UINT WINAPI LogThread (LPVOID lparam) if (!(ptr_log->is_blocklist && app.ConfigGet (L"IsExcludeBlocklist", true).AsBool ()) && !(ptr_log->is_custom && app.ConfigGet (L"IsExcludeCustomRules", true).AsBool ())) { // read app config - _r_fastlock_acquireexclusive (&lock_access); + _r_fastlock_acquireshared (&lock_access); PITEM_APP const ptr_app = _app_getapplication (ptr_log->hash); @@ -882,7 +880,7 @@ UINT WINAPI LogThread (LPVOID lparam) is_added = _app_notifyadd (config.hnotification, ptr_log, ptr_app); } - _r_fastlock_releaseexclusive (&lock_access); + _r_fastlock_releaseshared (&lock_access); } } } diff --git a/src/main.cpp b/src/main.cpp index 3a6159f3..8858bc85 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -131,8 +131,7 @@ void _app_listviewsetview (HWND hwnd, UINT listview_id) const bool is_mainview = (listview_id == IDC_APPS_PROFILE || listview_id == IDC_APPS_SERVICE || listview_id == IDC_APPS_PACKAGE); const bool is_tableview = !is_mainview || app.ConfigGet (L"IsTableView", true).AsBool (); - const INT icons_size = (is_mainview ? app.ConfigGet (L"IconSize", SHIL_SYSSMALL).AsInt () : SHIL_SYSSMALL); - + INT icons_size = SHIL_SYSSMALL; HIMAGELIST himg = nullptr; if ( @@ -145,6 +144,9 @@ void _app_listviewsetview (HWND hwnd, UINT listview_id) } else { + if (listview_id != IDC_APPS_LV) + icons_size = app.ConfigGet (L"IconSize", SHIL_SYSSMALL).AsInt (); + SHGetImageList (icons_size, IID_IImageList2, (void **)& himg); } @@ -154,29 +156,8 @@ void _app_listviewsetview (HWND hwnd, UINT listview_id) SendDlgItemMessage (hwnd, listview_id, LVM_SETIMAGELIST, LVSIL_SMALL, (LPARAM)himg); } - if (!is_mainview) - return; - SendDlgItemMessage (hwnd, listview_id, LVM_SCROLL, 0, GetScrollPos (GetDlgItem (hwnd, listview_id), SB_VERT)); // HACK!!! - SendDlgItemMessage (hwnd, listview_id, LVM_SETVIEW, is_tableview ? LV_VIEW_DETAILS : LV_VIEW_ICON, NULL); - - { - UINT menu_id; - - if (icons_size == SHIL_EXTRALARGE) - menu_id = IDM_ICONSEXTRALARGE; - - else if (icons_size == SHIL_LARGE) - menu_id = IDM_ICONSLARGE; - - else - menu_id = IDM_ICONSSMALL; - - CheckMenuRadioItem (GetMenu (hwnd), IDM_ICONSSMALL, IDM_ICONSEXTRALARGE, menu_id, MF_BYCOMMAND); - } - - CheckMenuItem (GetMenu (hwnd), IDM_ICONSISTABLEVIEW, MF_BYCOMMAND | (is_tableview ? MF_CHECKED : MF_UNCHECKED)); - CheckMenuItem (GetMenu (hwnd), IDM_ICONSISHIDDEN, MF_BYCOMMAND | (app.ConfigGet (L"IsIconsHidden", false).AsBool () ? MF_CHECKED : MF_UNCHECKED)); + SendDlgItemMessage (hwnd, listview_id, LVM_SETVIEW, is_tableview ? LV_VIEW_DETAILS : LV_VIEW_ICON, 0); } bool _app_listviewinitfont (PLOGFONT plf) @@ -272,10 +253,8 @@ COLORREF _app_getcolorvalue (size_t hash) return 0; } -COLORREF _app_getcolor (size_t app_hash, bool is_excludesilent) +COLORREF _app_getcolor (size_t app_hash, bool is_appslist) { - _r_fastlock_acquireshared (&lock_access); - rstring color_value; PITEM_APP const ptr_app = _app_getapplication (app_hash); @@ -290,27 +269,25 @@ COLORREF _app_getcolor (size_t app_hash, bool is_excludesilent) else if (app.ConfigGet (L"IsHighlightSpecial", true).AsBool () && _app_isapphaverule (app_hash)) color_value = L"ColorSpecial"; - else if (!is_excludesilent && ptr_app->is_silent && app.ConfigGet (L"IsHighlightSilent", true).AsBool ()) + else if (!is_appslist && ptr_app->is_silent && app.ConfigGet (L"IsHighlightSilent", true).AsBool ()) color_value = L"ColorSilent"; else if (ptr_app->is_signed && app.ConfigGet (L"IsHighlightSigned", true).AsBool () && app.ConfigGet (L"IsCertificatesEnabled", false).AsBool ()) color_value = L"ColorSigned"; - //else if ((ptr_app->type == AppService) && app.ConfigGet (L"IsHighlightService", true).AsBool ()) - // color_value = L"ColorService"; + else if (is_appslist && ptr_app->type == DataAppService && app.ConfigGet (L"IsHighlightService", true).AsBool ()) + color_value = L"ColorService"; - //else if ((ptr_app->type == AppPackage) && app.ConfigGet (L"IsHighlightPackage", true).AsBool ()) - // color_value = L"ColorPackage"; + else if (is_appslist && ptr_app->type == DataAppPackage && app.ConfigGet (L"IsHighlightPackage", true).AsBool ()) + color_value = L"ColorPackage"; - else if ((ptr_app->type == AppPico) && app.ConfigGet (L"IsHighlightPico", true).AsBool ()) + else if ((ptr_app->type == DataAppPico) && app.ConfigGet (L"IsHighlightPico", true).AsBool ()) color_value = L"ColorPico"; else if (ptr_app->is_system && app.ConfigGet (L"IsHighlightSystem", true).AsBool ()) color_value = L"ColorSystem"; } - _r_fastlock_releaseshared (&lock_access); - return _app_getcolorvalue (color_value.Hash ()); } @@ -342,8 +319,6 @@ UINT WINAPI ApplyThread (LPVOID lparam) if (config.is_neteventset) _wfp_logunsubscribe (); - _r_fastlock_acquireexclusive (&lock_access); - _app_initinterfacestate (); if (is_install) @@ -359,17 +334,14 @@ UINT WINAPI ApplyThread (LPVOID lparam) _wfp_uninitialize (true); } - _app_restoreinterfacestate (true); - - _r_fastlock_releaseexclusive (&lock_access); - // dropped packets logging (win7+) if (config.is_neteventset) _wfp_logsubscribe (); + _app_restoreinterfacestate (true); _app_setinterfacestate (app.GetHWND ()); - _app_profile_save (app.GetHWND ()); + _app_profile_save (); _r_listview_redraw (app.GetHWND (), _app_gettab_id (app.GetHWND ())); @@ -392,27 +364,30 @@ bool _app_changefilters (HWND hwnd, bool is_install, bool is_forced) if (!is_install || ((is_install && is_forced) || _wfp_isfiltersinstalled ())) { _r_fastlock_acquireshared (&lock_apply); - _r_fastlock_acquireexclusive (&lock_threadpool); _app_initinterfacestate (); + _r_fastlock_acquireexclusive (&lock_threadpool); _app_freethreadpool (&threads_pool); + _r_fastlock_releaseexclusive (&lock_threadpool); const HANDLE hthread = _r_createthread (&ApplyThread, (LPVOID)is_install, true, THREAD_PRIORITY_HIGHEST); if (hthread) { + _r_fastlock_acquireexclusive (&lock_threadpool); threads_pool.push_back (hthread); + _r_fastlock_releaseexclusive (&lock_threadpool); + ResumeThread (hthread); } - _r_fastlock_releaseexclusive (&lock_threadpool); _r_fastlock_releaseshared (&lock_apply); return true; } - _app_profile_save (hwnd); + _app_profile_save (); _r_listview_redraw (hwnd, listview_id); @@ -435,7 +410,7 @@ void addcolor (UINT locale_id, LPCWSTR config_name, bool is_enabled, LPCWSTR con ptr_clr->is_enabled = is_enabled; ptr_clr->locale_id = locale_id; ptr_clr->default_clr = default_clr; - ptr_clr->clr = app.ConfigGet (config_value, default_clr).AsUlong (); + ptr_clr->clr = app.ConfigGet (config_value, default_clr, L"colors").AsUlong (); colors.push_back (ptr_clr); } @@ -577,15 +552,17 @@ LONG _app_nmcustdraw (LPNMLVCUSTOMDRAW lpnmlv) if (app_hash) { - const COLORREF new_clr = (COLORREF)_app_getcolor (app_hash, (lpnmlv->nmcd.hdr.idFrom == IDC_APPS_LV)); + _r_fastlock_acquireshared (&lock_access); + const COLORREF clr = (COLORREF)_app_getcolor (app_hash, (lpnmlv->nmcd.hdr.idFrom == IDC_APPS_LV)); + _r_fastlock_releaseshared (&lock_access); - if (new_clr) + if (clr) { - lpnmlv->clrText = _r_dc_getcolorbrightness (new_clr); - lpnmlv->clrTextBk = new_clr; + lpnmlv->clrText = _r_dc_getcolorbrightness (clr); + lpnmlv->clrTextBk = clr; if (is_tableview) - _r_dc_fillrect (lpnmlv->nmcd.hdc, &lpnmlv->nmcd.rc, new_clr); + _r_dc_fillrect (lpnmlv->nmcd.hdc, &lpnmlv->nmcd.rc, clr); return CDRF_NEWFONT; } @@ -604,12 +581,16 @@ LONG _app_nmcustdraw (LPNMLVCUSTOMDRAW lpnmlv) { COLORREF clr = 0; + _r_fastlock_acquireshared (&lock_access); + if (ptr_rule->is_enabled && ptr_rule->is_haveerrors) clr = _app_getcolorvalue (_r_str_hash (L"ColorInvalid")); else if (ptr_rule->is_forservices || !ptr_rule->apps.empty ()) clr = _app_getcolorvalue (_r_str_hash (L"ColorSpecial")); + _r_fastlock_releaseshared (&lock_access); + if (clr) { lpnmlv->clrText = _r_dc_getcolorbrightness (clr); @@ -624,17 +605,19 @@ LONG _app_nmcustdraw (LPNMLVCUSTOMDRAW lpnmlv) } else if (lpnmlv->nmcd.hdr.idFrom == IDC_COLORS) { - PITEM_COLOR const ptr_clr = colors.at (lpnmlv->nmcd.lItemlParam); + _r_fastlock_acquireshared (&lock_access); + const COLORREF clr = colors.at (lpnmlv->nmcd.lItemlParam)->clr; + _r_fastlock_releaseshared (&lock_access); - if (ptr_clr) + if (clr) { - lpnmlv->clrText = _r_dc_getcolorbrightness (ptr_clr->clr); - lpnmlv->clrTextBk = ptr_clr->clr; + lpnmlv->clrText = _r_dc_getcolorbrightness (clr); + lpnmlv->clrTextBk = clr; _r_dc_fillrect (lpnmlv->nmcd.hdc, &lpnmlv->nmcd.rc, lpnmlv->clrTextBk); - } - return CDRF_NEWFONT; + return CDRF_NEWFONT; + } } break; @@ -654,6 +637,12 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { ptr_rule = (PITEM_RULE)lparam; + if (!ptr_rule) + { + EndDialog (hwnd, 0); + return FALSE; + } + #ifndef _APP_NO_DARKTHEME _r_wnd_setdarktheme (hwnd); #endif // _APP_NO_DARKTHEME @@ -665,12 +654,11 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM)app.GetSharedImage (app.GetHINSTANCE (), IDI_MAIN, GetSystemMetrics (SM_CXICON))); // localize window - SetWindowText (hwnd, (ptr_rule && ptr_rule->pname ? _r_fmt (L"%s - \"%s\"", app.LocaleString (IDS_EDITOR, nullptr).GetString (), ptr_rule->pname) : app.LocaleString (IDS_EDITOR, nullptr))); + SetWindowText (hwnd, app.LocaleString (IDS_EDITOR, ((ptr_rule->pname && ptr_rule->pname[0]) ? _r_fmt (L" - \"%s\"", ptr_rule->pname).GetString () : nullptr))); SetDlgItemText (hwnd, IDC_NAME, app.LocaleString (IDS_NAME, L":")); SetDlgItemText (hwnd, IDC_RULE_REMOTE, app.LocaleString (IDS_RULE, L" (" SZ_LOG_REMOTE_ADDRESS L"):")); SetDlgItemText (hwnd, IDC_RULE_LOCAL, app.LocaleString (IDS_RULE, L" (" SZ_LOG_LOCAL_ADDRESS L"):")); - SetDlgItemText (hwnd, IDC_REGION, app.LocaleString (IDS_REGION, L":")); SetDlgItemText (hwnd, IDC_DIRECTION, app.LocaleString (IDS_DIRECTION, L":")); SetDlgItemText (hwnd, IDC_PROTOCOL, app.LocaleString (IDS_PROTOCOL, L":")); SetDlgItemText (hwnd, IDC_PORTVERSION, app.LocaleString (IDS_PORTVERSION, L":")); @@ -687,21 +675,21 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) // configure listview _r_listview_setstyle (hwnd, IDC_APPS_LV, LVS_EX_DOUBLEBUFFER | LVS_EX_FULLROWSELECT | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_CHECKBOXES); - _r_listview_addcolumn (hwnd, IDC_APPS_LV, 0, nullptr, -95, LVCFMT_LEFT); + _r_listview_addcolumn (hwnd, IDC_APPS_LV, 0, app.LocaleString (IDS_NAME, nullptr), -95, LVCFMT_LEFT); _app_listviewsetview (hwnd, IDC_APPS_LV); _app_listviewsetfont (hwnd, IDC_APPS_LV, false); // name - if (ptr_rule && ptr_rule->pname) + if (ptr_rule->pname && ptr_rule->pname[0]) SetDlgItemText (hwnd, IDC_NAME_EDIT, ptr_rule->pname); // rule_remote (remote) - if (ptr_rule && ptr_rule->prule_remote) + if (ptr_rule->prule_remote && ptr_rule->prule_remote[0]) SetDlgItemText (hwnd, IDC_RULE_REMOTE_EDIT, ptr_rule->prule_remote); // rule_remote (local) - if (ptr_rule && ptr_rule->prule_local) + if (ptr_rule->prule_local && ptr_rule->prule_local[0]) SetDlgItemText (hwnd, IDC_RULE_LOCAL_EDIT, ptr_rule->prule_local); // apps (apply to) @@ -712,19 +700,19 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) for (auto &p : apps) { - PITEM_APP const ptr_app = &p.second; + const PITEM_APP ptr_app = &p.second; // windows store apps (win8+) - if (ptr_app->type == AppPackage && !_r_sys_validversion (6, 2)) + if (ptr_app->type == DataAppPackage && !_r_sys_validversion (6, 2)) continue; - if (ptr_rule && ptr_rule->is_forservices && (p.first == config.ntoskrnl_hash || p.first == config.svchost_hash)) + if (ptr_rule->is_forservices && (p.first == config.ntoskrnl_hash || p.first == config.svchost_hash)) continue; + const bool is_enabled = !ptr_rule->apps.empty () && (ptr_rule->apps.find (p.first) != ptr_rule->apps.end ()); + _r_fastlock_acquireshared (&lock_checkbox); - const bool is_enabled = ptr_rule && !ptr_rule->apps.empty () && (ptr_rule->apps.find (p.first) != ptr_rule->apps.end ()); - _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_setitemcheck (hwnd, IDC_APPS_LV, item, is_enabled); @@ -736,7 +724,7 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_fastlock_releaseshared (&lock_access); // sort column - _app_listviewsort (hwnd, IDC_APPS_LV, 0); + _app_listviewsort (hwnd, IDC_APPS_LV); // resize column RECT rc = {0}; @@ -745,13 +733,18 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_listview_setcolumn (hwnd, IDC_APPS_LV, 0, nullptr, _R_RECT_WIDTH (&rc)); } + if (ptr_rule->type != DataRuleCustom) + { + _r_ctrl_enable (hwnd, IDC_ENABLEFORAPPS_CHK, false); + _r_ctrl_enable (hwnd, IDC_APPS_LV, false); + } + // direction SendDlgItemMessage (hwnd, IDC_DIRECTION_EDIT, CB_INSERTSTRING, 0, (LPARAM)app.LocaleString (IDS_DIRECTION_1, nullptr).GetString ()); SendDlgItemMessage (hwnd, IDC_DIRECTION_EDIT, CB_INSERTSTRING, 1, (LPARAM)app.LocaleString (IDS_DIRECTION_2, nullptr).GetString ()); SendDlgItemMessage (hwnd, IDC_DIRECTION_EDIT, CB_INSERTSTRING, 2, (LPARAM)app.LocaleString (IDS_DIRECTION_3, nullptr).GetString ()); - if (ptr_rule) - SendDlgItemMessage (hwnd, IDC_DIRECTION_EDIT, CB_SETCURSEL, (WPARAM)ptr_rule->dir, 0); + SendDlgItemMessage (hwnd, IDC_DIRECTION_EDIT, CB_SETCURSEL, (WPARAM)ptr_rule->dir, 0); // protocol SendDlgItemMessage (hwnd, IDC_PROTOCOL_EDIT, CB_INSERTSTRING, 0, (LPARAM)app.LocaleString (IDS_ALL, nullptr).GetString ()); @@ -766,7 +759,7 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) SendDlgItemMessage (hwnd, IDC_PROTOCOL_EDIT, CB_INSERTSTRING, i + 1, (LPARAM)_r_fmt (L"#%03d - %s", ptr_protocol->id, ptr_protocol->pname).GetString ()); SendDlgItemMessage (hwnd, IDC_PROTOCOL_EDIT, CB_SETITEMDATA, i + 1, (LPARAM)ptr_protocol->id); - if (ptr_rule && ptr_rule->protocol == ptr_protocol->id) + if (ptr_rule->protocol == ptr_protocol->id) SendDlgItemMessage (hwnd, IDC_PROTOCOL_EDIT, CB_SETCURSEL, (WPARAM)i + 1, 0); } } @@ -781,30 +774,26 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_INSERTSTRING, 2, (LPARAM)L"IPv6"); SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_SETITEMDATA, 2, (LPARAM)AF_INET6); - if (ptr_rule) - { - if (ptr_rule->af == AF_UNSPEC) - SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_SETCURSEL, (WPARAM)0, 0); + if (ptr_rule->af == AF_UNSPEC) + SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_SETCURSEL, (WPARAM)0, 0); - else if (ptr_rule->af == AF_INET) - SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_SETCURSEL, (WPARAM)1, 0); + else if (ptr_rule->af == AF_INET) + SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_SETCURSEL, (WPARAM)1, 0); - else if (ptr_rule->af == AF_INET6) - SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_SETCURSEL, (WPARAM)2, 0); - } + else if (ptr_rule->af == AF_INET6) + SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_SETCURSEL, (WPARAM)2, 0); // action SendDlgItemMessage (hwnd, IDC_ACTION_EDIT, CB_INSERTSTRING, 0, (LPARAM)app.LocaleString (IDS_ACTION_ALLOW, nullptr).GetString ()); SendDlgItemMessage (hwnd, IDC_ACTION_EDIT, CB_INSERTSTRING, 1, (LPARAM)app.LocaleString (IDS_ACTION_BLOCK, nullptr).GetString ()); - if (ptr_rule) - SendDlgItemMessage (hwnd, IDC_ACTION_EDIT, CB_SETCURSEL, (WPARAM)ptr_rule->is_block, 0); + SendDlgItemMessage (hwnd, IDC_ACTION_EDIT, CB_SETCURSEL, (WPARAM)ptr_rule->is_block, 0); // state { UINT ctrl_id = IDC_DISABLE_CHK; - if (ptr_rule && ptr_rule->is_enabled) + if (ptr_rule->is_enabled) ctrl_id = ptr_rule->apps.empty () ? IDC_ENABLE_CHK : IDC_ENABLEFORAPPS_CHK; CheckRadioButton (hwnd, IDC_DISABLE_CHK, IDC_ENABLEFORAPPS_CHK, ctrl_id); @@ -816,17 +805,14 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) SendDlgItemMessage (hwnd, IDC_RULE_LOCAL_EDIT, EM_LIMITTEXT, RULE_RULE_CCH_MAX - 1, 0); // set read-only - if (ptr_rule) - { - SendDlgItemMessage (hwnd, IDC_NAME_EDIT, EM_SETREADONLY, ptr_rule->is_readonly, 0); - SendDlgItemMessage (hwnd, IDC_RULE_REMOTE_EDIT, EM_SETREADONLY, ptr_rule->is_readonly, 0); - SendDlgItemMessage (hwnd, IDC_RULE_LOCAL_EDIT, EM_SETREADONLY, ptr_rule->is_readonly, 0); + SendDlgItemMessage (hwnd, IDC_NAME_EDIT, EM_SETREADONLY, ptr_rule->is_readonly, 0); + SendDlgItemMessage (hwnd, IDC_RULE_REMOTE_EDIT, EM_SETREADONLY, ptr_rule->is_readonly, 0); + SendDlgItemMessage (hwnd, IDC_RULE_LOCAL_EDIT, EM_SETREADONLY, ptr_rule->is_readonly, 0); - _r_ctrl_enable (hwnd, IDC_PORTVERSION_EDIT, !ptr_rule->is_readonly); - _r_ctrl_enable (hwnd, IDC_PROTOCOL_EDIT, !ptr_rule->is_readonly); - _r_ctrl_enable (hwnd, IDC_DIRECTION_EDIT, !ptr_rule->is_readonly); - _r_ctrl_enable (hwnd, IDC_ACTION_EDIT, !ptr_rule->is_readonly); - } + _r_ctrl_enable (hwnd, IDC_PORTVERSION_EDIT, !ptr_rule->is_readonly); + _r_ctrl_enable (hwnd, IDC_PROTOCOL_EDIT, !ptr_rule->is_readonly); + _r_ctrl_enable (hwnd, IDC_DIRECTION_EDIT, !ptr_rule->is_readonly); + _r_ctrl_enable (hwnd, IDC_ACTION_EDIT, !ptr_rule->is_readonly); _r_wnd_addstyle (hwnd, IDC_WIKI, app.IsClassicUI () ? WS_EX_STATICEDGE : 0, WS_EX_STATICEDGE, GWL_EXSTYLE); _r_wnd_addstyle (hwnd, IDC_SAVE, app.IsClassicUI () ? WS_EX_STATICEDGE : 0, WS_EX_STATICEDGE, GWL_EXSTYLE); @@ -834,6 +820,8 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_ctrl_enable (hwnd, IDC_SAVE, (SendDlgItemMessage (hwnd, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0) > 0) && ((SendDlgItemMessage (hwnd, IDC_RULE_REMOTE_EDIT, WM_GETTEXTLENGTH, 0, 0) > 0) || (SendDlgItemMessage (hwnd, IDC_RULE_LOCAL_EDIT, WM_GETTEXTLENGTH, 0, 0) > 0))); // enable apply button + ptr_rule->is_haveerrors = false; + break; } @@ -885,30 +873,39 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { case NM_CUSTOMDRAW: { - _r_fastlock_acquireshared (&lock_access); - const LONG result = _app_nmcustdraw ((LPNMLVCUSTOMDRAW)lparam); - _r_fastlock_releaseshared (&lock_access); + LONG result = CDRF_DODEFAULT; + + if (_r_fastlock_tryacquireshared (&lock_access)) + { + result = _app_nmcustdraw ((LPNMLVCUSTOMDRAW)lparam); + _r_fastlock_releaseshared (&lock_access); + } SetWindowLongPtr (hwnd, DWLP_MSGRESULT, result); return result; } + case LVN_COLUMNCLICK: + { + LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lparam; + _app_listviewsort (hwnd, (UINT)pnmv->hdr.idFrom, pnmv->iSubItem, true); + + break; + } + case LVN_ITEMCHANGED: { - if (_r_fastlock_islocked (&lock_checkbox)) - break; - LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam; - if (lpnmlv->uNewState == 8192 || lpnmlv->uNewState == 4096) + if (IsWindowVisible (lpnmlv->hdr.hwndFrom) && (lpnmlv->uChanged & LVIF_STATE) && (lpnmlv->uNewState == 8192 || lpnmlv->uNewState == 4096) && lpnmlv->uNewState != lpnmlv->uOldState) { + if (_r_fastlock_islocked (&lock_checkbox)) + break; + 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); - const UINT ctrl_id = is_havechecks ? IDC_ENABLEFORAPPS_CHK : IDC_DISABLE_CHK; - - CheckRadioButton (hwnd, IDC_DISABLE_CHK, IDC_ENABLEFORAPPS_CHK, ctrl_id); - - _app_listviewsort (hwnd, IDC_APPS_LV, 0); + _app_listviewsort (hwnd, IDC_APPS_LV); } break; @@ -916,11 +913,15 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case LVN_GETINFOTIP: { - LPNMLVGETINFOTIP lpnmlv = (LPNMLVGETINFOTIP)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 = (size_t)_r_listview_getitemlparam (hwnd, (UINT)lpnmlv->hdr.idFrom, lpnmlv->iItem); + StringCchCopy (lpnmlv->pszText, lpnmlv->cchTextMax, _app_gettooltip ((UINT)lpnmlv->hdr.idFrom, idx)); - StringCchCopy (lpnmlv->pszText, lpnmlv->cchTextMax, _app_gettooltip ((UINT)lpnmlv->hdr.idFrom, idx)); + _r_fastlock_releaseshared (&lock_access); + } break; } @@ -980,14 +981,14 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (!SendDlgItemMessage (hwnd, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0) || (!SendDlgItemMessage (hwnd, IDC_RULE_REMOTE_EDIT, WM_GETTEXTLENGTH, 0, 0) && !SendDlgItemMessage (hwnd, IDC_RULE_LOCAL_EDIT, WM_GETTEXTLENGTH, 0, 0))) return FALSE; + rstring rule_remote = _r_ctrl_gettext (hwnd, IDC_RULE_REMOTE_EDIT).Trim (L"\r\n " RULE_DELIMETER); + size_t rule_remote_length; + + rstring rule_local = _r_ctrl_gettext (hwnd, IDC_RULE_LOCAL_EDIT).Trim (L"\r\n " RULE_DELIMETER); + size_t rule_local_length; + // rule_remote destination { - rstring rule_remote = _r_ctrl_gettext (hwnd, IDC_RULE_REMOTE_EDIT).Trim (L"\r\n " RULE_DELIMETER); - size_t rule_remote_length; - - rstring rule_local = _r_ctrl_gettext (hwnd, IDC_RULE_LOCAL_EDIT).Trim (L"\r\n " RULE_DELIMETER); - size_t rule_local_length; - // here we parse and check rule_remote syntax { rstring::rvector arr = rule_remote.AsVector (RULE_DELIMETER); @@ -1011,38 +1012,39 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) rule_remote = rule_remote_fixed.Trim (L" " RULE_DELIMETER); rule_remote_length = min (rule_remote.GetLength (), RULE_RULE_CCH_MAX); } + } - // here we parse and check rule_remote syntax + // rule_local source + { + rstring::rvector arr = rule_local.AsVector (RULE_DELIMETER); + rstring rule_local_fixed; + + for (size_t i = 0; i < arr.size (); i++) { - rstring::rvector arr = rule_local.AsVector (RULE_DELIMETER); - rstring rule_local_fixed; + LPCWSTR rule_single = arr.at (i).Trim (L" " RULE_DELIMETER); - for (size_t i = 0; i < arr.size (); i++) + if (!_app_parserulestring (rule_single, nullptr)) { - LPCWSTR rule_single = arr.at (i).Trim (L" " RULE_DELIMETER); + _r_ctrl_showtip (hwnd, IDC_RULE_LOCAL_EDIT, TTI_ERROR, APP_NAME, _r_fmt (app.LocaleString (IDS_STATUS_SYNTAX_ERROR, nullptr), rule_single)); + _r_ctrl_enable (hwnd, IDC_SAVE, false); - if (!_app_parserulestring (rule_single, nullptr)) - { - _r_ctrl_showtip (hwnd, IDC_RULE_LOCAL_EDIT, TTI_ERROR, APP_NAME, _r_fmt (app.LocaleString (IDS_STATUS_SYNTAX_ERROR, nullptr), rule_single)); - _r_ctrl_enable (hwnd, IDC_SAVE, false); - - return FALSE; - } - - rule_local_fixed.AppendFormat (L"%s" RULE_DELIMETER, rule_single); + return FALSE; } - rule_local = rule_local_fixed.Trim (L" " RULE_DELIMETER); - rule_local_length = min (rule_local.GetLength (), RULE_RULE_CCH_MAX); + rule_local_fixed.AppendFormat (L"%s" RULE_DELIMETER, rule_single); } - _r_fastlock_acquireexclusive (&lock_access); - - // save rule_remote (remote) - _r_str_alloc (&ptr_rule->prule_remote, rule_remote_length, rule_remote); - _r_str_alloc (&ptr_rule->prule_local, rule_local_length, rule_local); + rule_local = rule_local_fixed.Trim (L" " RULE_DELIMETER); + rule_local_length = min (rule_local.GetLength (), RULE_RULE_CCH_MAX); } + // save rule information + _r_fastlock_acquireexclusive (&lock_access); + + // save rule_remote (remote) + _r_str_alloc (&ptr_rule->prule_remote, rule_remote_length, rule_remote); + _r_str_alloc (&ptr_rule->prule_local, rule_local_length, rule_local); + // save rule_remote name { const rstring name = _r_ctrl_gettext (hwnd, IDC_NAME_EDIT).Trim (L"\r\n " RULE_DELIMETER); @@ -1055,7 +1057,19 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } } + ptr_rule->protocol = (UINT8)SendDlgItemMessage (hwnd, IDC_PROTOCOL_EDIT, CB_GETITEMDATA, SendDlgItemMessage (hwnd, IDC_PROTOCOL_EDIT, CB_GETCURSEL, 0, 0), 0); + ptr_rule->af = (ADDRESS_FAMILY)SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_GETITEMDATA, SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_GETCURSEL, 0, 0), 0); + + ptr_rule->dir = (FWP_DIRECTION)SendDlgItemMessage (hwnd, IDC_DIRECTION_EDIT, CB_GETCURSEL, 0, 0); + ptr_rule->is_block = SendDlgItemMessage (hwnd, IDC_ACTION_EDIT, CB_GETCURSEL, 0, 0) ? true : false; + + if (ptr_rule->type == DataRuleCustom) + ptr_rule->weight = (ptr_rule->is_block ? FILTER_WEIGHT_CUSTOM_BLOCK : FILTER_WEIGHT_CUSTOM); + + _app_ruleenable (ptr_rule, (IsDlgButtonChecked (hwnd, IDC_DISABLE_CHK) == BST_UNCHECKED) ? true : false); + // save rule_remote apps + if (ptr_rule->type == DataRuleCustom) { ptr_rule->apps.clear (); @@ -1064,30 +1078,35 @@ INT_PTR CALLBACK EditorProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) for (size_t 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 PITEM_APP ptr_app = _app_getapplication (app_hash); - if (app_hash) + if (ptr_app) { - bool is_apply = is_enable && _r_listview_isitemchecked (hwnd, IDC_APPS_LV, i); + const UINT listview_id = _app_getlistview_id (ptr_app->type); + const bool is_apply = is_enable && _r_listview_isitemchecked (hwnd, IDC_APPS_LV, i); if (is_apply) ptr_rule->apps[app_hash] = true; - _r_listview_setitem (app.GetHWND (), IDC_APPS_PROFILE, _app_getposition (app.GetHWND (), app_hash), 0, nullptr, LAST_VALUE, _app_getappgroup (app_hash, _app_getapplication (app_hash))); + _r_fastlock_acquireshared (&lock_checkbox); + + _app_setappiteminfo (hwnd, listview_id, _app_getposition (app.GetHWND (), app_hash), app_hash, ptr_app); + + _r_fastlock_releaseshared (&lock_checkbox); } } } - ptr_rule->protocol = (UINT8)SendDlgItemMessage (hwnd, IDC_PROTOCOL_EDIT, CB_GETITEMDATA, SendDlgItemMessage (hwnd, IDC_PROTOCOL_EDIT, CB_GETCURSEL, 0, 0), 0); - ptr_rule->af = (ADDRESS_FAMILY)SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_GETITEMDATA, SendDlgItemMessage (hwnd, IDC_PORTVERSION_EDIT, CB_GETCURSEL, 0, 0), 0); - - ptr_rule->dir = (FWP_DIRECTION)SendDlgItemMessage (hwnd, IDC_DIRECTION_EDIT, CB_GETCURSEL, 0, 0); - ptr_rule->is_block = SendDlgItemMessage (hwnd, IDC_ACTION_EDIT, CB_GETCURSEL, 0, 0) ? true : false; - ptr_rule->weight = (ptr_rule->is_block ? FILTER_WEIGHT_CUSTOM_BLOCK : FILTER_WEIGHT_CUSTOM); - - _app_ruleenable (ptr_rule, (IsDlgButtonChecked (hwnd, IDC_DISABLE_CHK) == BST_UNCHECKED) ? true : false); - _r_fastlock_releaseexclusive (&lock_access); + // apply filter + { + MFILTER_RULES rules; + rules.push_back (ptr_rule); + + _wfp_create4filters (&rules, __LINE__); + } + EndDialog (hwnd, 1); break; @@ -1202,27 +1221,30 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam _r_listview_deleteallitems (hwnd, IDC_COLORS); _r_listview_deleteallcolumns (hwnd, IDC_COLORS); - _r_listview_addcolumn (hwnd, IDC_COLORS, 0, L"", -100, LVCFMT_LEFT); + _r_listview_addcolumn (hwnd, IDC_COLORS, 0, L"", -95, LVCFMT_LEFT); + for (size_t i = 0; i < colors.size (); i++) { - _r_fastlock_acquireshared (&lock_checkbox); + PITEM_COLOR ptr_clr = colors.at (i); - for (size_t i = 0; i < colors.size (); i++) + if (ptr_clr) { - PITEM_COLOR ptr_clr = colors.at (i); + ptr_clr->clr = app.ConfigGet (ptr_clr->pcfg_value, ptr_clr->default_clr).AsUlong (); - if (ptr_clr) - { - ptr_clr->clr = app.ConfigGet (ptr_clr->pcfg_value, ptr_clr->default_clr).AsUlong (); + _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).AsBool ()); - } + _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_fastlock_releaseshared (&lock_checkbox); } - - _r_fastlock_releaseshared (&lock_checkbox); } + RECT rc = {0}; + GetClientRect (GetDlgItem (hwnd, IDC_COLORS), &rc); + + _r_listview_setcolumn (hwnd, IDC_COLORS, 0, nullptr, _R_RECT_WIDTH (&rc)); + break; } @@ -1433,23 +1455,23 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam case LVN_ITEMCHANGED: { - if (_r_fastlock_islocked (&lock_checkbox)) - break; - LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam; if (lpnmlv->hdr.idFrom != IDC_COLORS) break; - if (lpnmlv->uNewState == 8192 || lpnmlv->uNewState == 4096) + if (IsWindowVisible (lpnmlv->hdr.hwndFrom) && (lpnmlv->uChanged & LVIF_STATE) && (lpnmlv->uNewState == 8192 || lpnmlv->uNewState == 4096) && lpnmlv->uNewState != lpnmlv->uOldState) { + if (_r_fastlock_islocked (&lock_checkbox)) + break; + const bool new_val = (lpnmlv->uNewState == 8192) ? true : false; const size_t idx = lpnmlv->lParam; PITEM_COLOR ptr_clr = colors.at (idx); if (ptr_clr) - app.ConfigSet (ptr_clr->pcfg_name, new_val); + app.ConfigSet (ptr_clr->pcfg_name, new_val, L"colors"); _r_listview_redraw (app.GetHWND (), _app_gettab_id (app.GetHWND ())); } @@ -1459,9 +1481,13 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam case NM_CUSTOMDRAW: { - _r_fastlock_acquireshared (&lock_access); - const LONG result = _app_nmcustdraw ((LPNMLVCUSTOMDRAW)lparam); - _r_fastlock_releaseshared (&lock_access); + LONG result = CDRF_DODEFAULT; + + if (_r_fastlock_tryacquireshared (&lock_access)) + { + result = _app_nmcustdraw ((LPNMLVCUSTOMDRAW)lparam); + _r_fastlock_releaseshared (&lock_access); + } SetWindowLongPtr (hwnd, DWLP_MSGRESULT, result); return result; @@ -1478,6 +1504,7 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam CHOOSECOLOR cc = {0}; COLORREF cust[16] = {0}; + PITEM_COLOR ptr_clr = colors.at (idx); for (size_t i = 0; i < min (_countof (cust), colors.size ()); i++) cust[i] = colors.at (i)->default_clr; @@ -1486,16 +1513,14 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam cc.Flags = CC_RGBINIT | CC_FULLOPEN; cc.hwndOwner = hwnd; cc.lpCustColors = cust; - cc.rgbResult = colors.at (idx)->clr; + cc.rgbResult = ptr_clr ? ptr_clr->clr : 0; if (ChooseColor (&cc)) { - PITEM_COLOR ptr_clr = colors.at (idx); - if (ptr_clr) { ptr_clr->clr = cc.rgbResult; - app.ConfigSet (ptr_clr->pcfg_value, cc.rgbResult); + app.ConfigSet (ptr_clr->pcfg_value, cc.rgbResult, L"colors"); } _r_listview_redraw (hwnd, IDC_COLORS); @@ -1629,7 +1654,7 @@ INT_PTR CALLBACK SettingsProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam { app.ConfigSet (L"IsNetworkResolutionsEnabled", (IsDlgButtonChecked (hwnd, ctrl_id) == BST_CHECKED) ? true : false); - _app_notifyrefresh (config.hnotification, false); + //_app_notifyrefresh (config.hnotification, false); } else if (ctrl_id == IDC_USEREFRESHDEVICES_CHK) { @@ -1898,7 +1923,7 @@ void _app_toolbar_init (HWND hwnd) REBARINFO ri = {0}; ri.cbSize = sizeof (ri); - SendDlgItemMessage (hwnd, IDC_REBAR, RB_SETBARINFO, 0, (LPARAM)& ri); + SendMessage (config.hrebar, RB_SETBARINFO, 0, (LPARAM)& ri); SendDlgItemMessage (hwnd, IDC_TOOLBAR, WM_SETFONT, (WPARAM)GetStockObject (DEFAULT_GUI_FONT), TRUE); SendDlgItemMessage (hwnd, IDC_TOOLBAR, TB_BUTTONSTRUCTSIZE, sizeof (TBBUTTON), 0); @@ -1961,7 +1986,9 @@ void _app_toolbar_init (HWND hwnd) rbi.cxMinChild = LOWORD (button_size); rbi.cyMinChild = HIWORD (button_size); - SendDlgItemMessage (hwnd, IDC_REBAR, RB_INSERTBAND, 0, (LPARAM)& rbi); + SendMessage (config.hrebar, RB_INSERTBAND, 0, (LPARAM)& rbi); + + BringWindowToTop (config.hrebar); // HACK!!! } void _app_initialize () @@ -2168,6 +2195,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) addcolor (IDS_HIGHLIGHT_SIGNED, L"IsHighlightSigned", true, L"ColorSigned", LISTVIEW_COLOR_SIGNED); addcolor (IDS_HIGHLIGHT_PICO, L"IsHighlightPico", true, L"ColorPico", LISTVIEW_COLOR_PICO); addcolor (IDS_HIGHLIGHT_SYSTEM, L"IsHighlightSystem", true, L"ColorSystem", LISTVIEW_COLOR_SYSTEM); + addcolor (IDS_HIGHLIGHT_SERVICE, L"IsHighlightService", true, L"ColorService", LISTVIEW_COLOR_SERVICE); + addcolor (IDS_HIGHLIGHT_PACKAGE, L"IsHighlightPackage", true, L"ColorPackage", LISTVIEW_COLOR_PACKAGE); } // initialize protocols @@ -2262,6 +2291,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_listview_addcolumn (hwnd, listview_id, 1, app.LocaleString (IDS_ADDRESS_LOCAL, nullptr), -25, LVCFMT_LEFT); _r_listview_addcolumn (hwnd, listview_id, 2, app.LocaleString (IDS_ADDRESS_REMOTE, nullptr), -25, LVCFMT_LEFT); _r_listview_addcolumn (hwnd, listview_id, 3, app.LocaleString (IDS_PROTOCOL, nullptr), -15, LVCFMT_RIGHT); + _r_listview_addcolumn (hwnd, listview_id, 4, app.LocaleString (IDS_STATE, nullptr), -15, LVCFMT_RIGHT); } _app_listviewsetfont (hwnd, listview_id, false); @@ -2285,12 +2315,12 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _app_changefilters (hwnd, true, true); } - // initialize tab - _app_settab_id (hwnd, app.ConfigGet (L"CurrentTab", IDC_APPS_PROFILE).AsSizeT ()); - // initialize toolbar _app_toolbar_init (hwnd); + // initialize tab + _app_settab_id (hwnd, app.ConfigGet (L"CurrentTab", IDC_APPS_PROFILE).AsSizeT ()); + break; } @@ -2304,10 +2334,31 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) app.TrayCreate (hwnd, UID, nullptr, WM_TRAYICON, app.GetSharedImage (app.GetHINSTANCE (), IDI_ACTIVE, GetSystemMetrics (SM_CXSMICON)), true); - CheckMenuItem (GetMenu (hwnd), IDM_ALWAYSONTOP_CHK, MF_BYCOMMAND | (app.ConfigGet (L"AlwaysOnTop", false).AsBool () ? MF_CHECKED : MF_UNCHECKED)); - CheckMenuItem (GetMenu (hwnd), IDM_SHOWFILENAMESONLY_CHK, MF_BYCOMMAND | (app.ConfigGet (L"ShowFilenames", true).AsBool () ? MF_CHECKED : MF_UNCHECKED)); - CheckMenuItem (GetMenu (hwnd), IDM_AUTOSIZECOLUMNS_CHK, MF_BYCOMMAND | (app.ConfigGet (L"AutoSizeColumns", true).AsBool () ? MF_CHECKED : MF_UNCHECKED)); - CheckMenuItem (GetMenu (hwnd), IDM_ENABLESPECIALGROUP_CHK, MF_BYCOMMAND | (app.ConfigGet (L"IsEnableSpecialGroup", true).AsBool () ? MF_CHECKED : MF_UNCHECKED)); + const HMENU hmenu = GetMenu (hwnd); + + CheckMenuItem (hmenu, IDM_ALWAYSONTOP_CHK, MF_BYCOMMAND | (app.ConfigGet (L"AlwaysOnTop", false).AsBool () ? MF_CHECKED : MF_UNCHECKED)); + CheckMenuItem (hmenu, IDM_SHOWFILENAMESONLY_CHK, MF_BYCOMMAND | (app.ConfigGet (L"ShowFilenames", true).AsBool () ? MF_CHECKED : MF_UNCHECKED)); + CheckMenuItem (hmenu, IDM_AUTOSIZECOLUMNS_CHK, MF_BYCOMMAND | (app.ConfigGet (L"AutoSizeColumns", true).AsBool () ? MF_CHECKED : MF_UNCHECKED)); + CheckMenuItem (hmenu, IDM_ENABLESPECIALGROUP_CHK, MF_BYCOMMAND | (app.ConfigGet (L"IsEnableSpecialGroup", true).AsBool () ? MF_CHECKED : MF_UNCHECKED)); + + CheckMenuItem (hmenu, IDM_ICONSISTABLEVIEW, MF_BYCOMMAND | (app.ConfigGet (L"IsTableView", true).AsBool () ? MF_CHECKED : MF_UNCHECKED)); + CheckMenuItem (hmenu, IDM_ICONSISHIDDEN, MF_BYCOMMAND | (app.ConfigGet (L"IsIconsHidden", false).AsBool () ? MF_CHECKED : MF_UNCHECKED)); + + { + UINT menu_id; + const INT icon_size = app.ConfigGet (L"IconSize", SHIL_SYSSMALL).AsInt (); + + if (icon_size == SHIL_EXTRALARGE) + menu_id = IDM_ICONSEXTRALARGE; + + else if (icon_size == SHIL_LARGE) + menu_id = IDM_ICONSLARGE; + + else + menu_id = IDM_ICONSSMALL; + + CheckMenuRadioItem (hmenu, IDM_ICONSSMALL, IDM_ICONSEXTRALARGE, menu_id, MF_BYCOMMAND); + } _r_toolbar_setbuttoninfo (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLENOTIFICATIONS_CHK, nullptr, 0, app.ConfigGet (L"IsNotificationsEnabled", true).AsBool () ? TBSTATE_PRESSED | TBSTATE_ENABLED : TBSTATE_ENABLED); _r_toolbar_setbuttoninfo (config.hrebar, IDC_TOOLBAR, IDM_TRAY_ENABLELOG_CHK, nullptr, 0, app.ConfigGet (L"IsLogEnabled", false).AsBool () ? TBSTATE_PRESSED | TBSTATE_ENABLED : TBSTATE_ENABLED); @@ -2440,6 +2491,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_listview_setcolumn (hwnd, listview_id, 1, app.LocaleString (IDS_ADDRESS_LOCAL, nullptr), 0); _r_listview_setcolumn (hwnd, listview_id, 2, app.LocaleString (IDS_ADDRESS_REMOTE, nullptr), 0); _r_listview_setcolumn (hwnd, listview_id, 3, app.LocaleString (IDS_PROTOCOL, nullptr), 0); + _r_listview_setcolumn (hwnd, listview_id, 4, app.LocaleString (IDS_STATE, nullptr), 0); } SendDlgItemMessage (hwnd, listview_id, LVM_RESETEMPTYTEXT, 0, 0); @@ -2461,9 +2513,11 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case RM_UPDATE_DONE: { - _app_profile_save (hwnd); + _app_profile_save (); _app_profile_load (hwnd); + _app_refreshstatus (hwnd); + _app_changefilters (hwnd, true, false); break; @@ -2479,51 +2533,15 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_fs_delete (config.rules_config_path, false); _r_fs_delete (config.rules_config_path_backup, false); - _app_profile_save (hwnd); _app_profile_load (hwnd); + _app_refreshstatus (hwnd); + _app_changefilters (hwnd, true, false); break; } - case WM_DROPFILES: - { - const UINT numfiles = DragQueryFile ((HDROP)wparam, UINT32_MAX, nullptr, 0); - size_t app_hash = 0; - - _r_fastlock_acquireexclusive (&lock_access); - - for (UINT i = 0; i < numfiles; i++) - { - const UINT length = DragQueryFile ((HDROP)wparam, i, nullptr, 0) + 1; - - LPWSTR file = new WCHAR[length]; - - if (file) - { - DragQueryFile ((HDROP)wparam, i, file, length); - - app_hash = _app_addapplication (hwnd, file, 0, 0, 0, false, false, false); - - SAFE_DELETE_ARRAY (file); - } - } - - _r_fastlock_releaseexclusive (&lock_access); - - DragFinish ((HDROP)wparam); - - if (_app_gettab_id (hwnd) == IDC_APPS_PROFILE) - _app_listviewsort (hwnd, IDC_APPS_PROFILE); - - _app_profile_save (hwnd); - - _app_showitem (hwnd, IDC_APPS_PROFILE, app_hash); - - break; - } - case WM_CLOSE: { if (_wfp_isfiltersinstalled ()) @@ -2544,6 +2562,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case WM_DESTROY: { + app.ConfigSet (L"CurrentTab", (DWORD)_app_gettab_id (hwnd)); + if (config.hnotification) DestroyWindow (config.hnotification); @@ -2554,7 +2574,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) app.TrayDestroy (hwnd, UID, nullptr); - _app_profile_save (hwnd); + _app_profile_save (); if (config.done_evt) { @@ -2576,6 +2596,41 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) break; } + case WM_DROPFILES: + { + const UINT numfiles = DragQueryFile ((HDROP)wparam, UINT32_MAX, nullptr, 0); + size_t app_hash = 0; + + for (UINT i = 0; i < numfiles; i++) + { + const UINT length = DragQueryFile ((HDROP)wparam, i, nullptr, 0) + 1; + + LPWSTR file = new WCHAR[length]; + + if (file) + { + DragQueryFile ((HDROP)wparam, i, file, length); + + _r_fastlock_acquireexclusive (&lock_access); + app_hash = _app_addapplication (hwnd, file, 0, 0, 0, false, false, false); + _r_fastlock_releaseexclusive (&lock_access); + + SAFE_DELETE_ARRAY (file); + } + } + + DragFinish ((HDROP)wparam); + + _app_profile_save (); + + const PITEM_APP ptr_app = _app_getapplication (app_hash); + + if (ptr_app) + _app_showitem (hwnd, _app_getlistview_id (ptr_app->type), app_hash); + + break; + } + case WM_SETTINGCHANGE: { _app_notifyrefresh (config.hnotification, false); @@ -2598,7 +2653,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) const UINT 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_HIDEWINDOW); + _r_wnd_resize (&hdefer, GetDlgItem (hwnd, current_id), nullptr, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_HIDEWINDOW); } EndDeferWindowPos (hdefer); @@ -2608,8 +2663,6 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (IsWindowVisible (GetDlgItem (hwnd, listview_id))) break; - app.ConfigSet (L"CurrentTab", (DWORD)listview_id); - _app_listviewsetview (hwnd, listview_id); _app_listviewsort (hwnd, listview_id); @@ -2637,7 +2690,6 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } _app_listviewresize (hwnd, listview_id); - _app_refreshstatus (hwnd); _r_listview_redraw (hwnd, listview_id); @@ -2647,9 +2699,13 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case NM_CUSTOMDRAW: { - _r_fastlock_acquireshared (&lock_access); - const LONG result = _app_nmcustdraw ((LPNMLVCUSTOMDRAW)lparam); - _r_fastlock_releaseshared (&lock_access); + LONG result = CDRF_DODEFAULT; + + if (_r_fastlock_tryacquireshared (&lock_access)) + { + result = _app_nmcustdraw ((LPNMLVCUSTOMDRAW)lparam); + _r_fastlock_releaseshared (&lock_access); + } SetWindowLongPtr (hwnd, DWLP_MSGRESULT, result); return result; @@ -2665,29 +2721,33 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case LVN_GETINFOTIP: { - LPNMLVGETINFOTIP lpnmlv = (LPNMLVGETINFOTIP)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 = (size_t)_r_listview_getitemlparam (hwnd, (UINT)lpnmlv->hdr.idFrom, lpnmlv->iItem); + StringCchCopy (lpnmlv->pszText, lpnmlv->cchTextMax, _app_gettooltip ((UINT)lpnmlv->hdr.idFrom, idx)); - StringCchCopy (lpnmlv->pszText, lpnmlv->cchTextMax, _app_gettooltip ((UINT)lpnmlv->hdr.idFrom, idx)); + _r_fastlock_releaseshared (&lock_access); + } break; } case LVN_ITEMCHANGED: { - if (_r_fastlock_islocked (&lock_checkbox)) - break; - LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam; - if (lpnmlv->uNewState == 8192 || lpnmlv->uNewState == 4096) + 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); - const bool new_val = (lpnmlv->uNewState == 8192) ? true : false; - bool is_changed = false; + if (_r_fastlock_islocked (&lock_checkbox)) + break; + + const bool new_val = (lpnmlv->uNewState == 8192) ? true : false; + if ( listview_id == IDC_APPS_PROFILE || listview_id == IDC_APPS_SERVICE || @@ -2698,36 +2758,36 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) const size_t app_hash = lpnmlv->lParam; PITEM_APP ptr_app = _app_getapplication (app_hash); + MFILTER_APPS rules; if (ptr_app) { if (ptr_app->is_enabled != new_val) { ptr_app->is_enabled = new_val; - _r_listview_setitem (hwnd, listview_id, lpnmlv->iItem, 0, nullptr, LAST_VALUE, _app_getappgroup (app_hash, ptr_app)); + _app_setappiteminfo (hwnd, listview_id, lpnmlv->iItem, app_hash, ptr_app); _r_fastlock_acquireexclusive (&lock_notification); - _app_freenotify (app_hash, false); + _app_freenotify (app_hash, false, true); _r_fastlock_releaseexclusive (&lock_notification); if (!new_val && _app_istimeractive (ptr_app)) { - MFILTER_APPS rules; rules.push_back (ptr_app); _app_timer_remove (hwnd, &rules); } - MFILTER_APPS rules; rules.push_back (ptr_app); - _wfp_create3filters (&rules, __LINE__); - is_changed = true; } } _r_fastlock_releaseexclusive (&lock_access); + + if (is_changed) + _wfp_create3filters (&rules, __LINE__); } else if ( listview_id == IDC_RULES_BLOCKLIST || @@ -2739,32 +2799,31 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) const size_t rule_idx = lpnmlv->lParam; PITEM_RULE ptr_rule = rules_arr.at (rule_idx); + MFILTER_RULES rules; if (ptr_rule) { if (ptr_rule->is_enabled != new_val) { _app_ruleenable (ptr_rule, new_val); - _app_setruleitem (hwnd, listview_id, lpnmlv->iItem, ptr_rule); + _app_setruleiteminfo (hwnd, listview_id, lpnmlv->iItem, ptr_rule); - MFILTER_RULES rules; rules.push_back (ptr_rule); - _wfp_create4filters (&rules, __LINE__); - is_changed = true; } } _r_fastlock_releaseexclusive (&lock_access); + + if (is_changed) + _wfp_create4filters (&rules, __LINE__); } if (is_changed) { - _app_notifyrefresh (config.hnotification, false); - _app_listviewsort (hwnd, listview_id); - _app_profile_save (hwnd); + _app_profile_save (); _app_refreshstatus (hwnd); @@ -2816,7 +2875,11 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { command_id = IDM_EXPLORE; } - else if (lpnmlv->hdr.idFrom == IDC_RULES_CUSTOM) + else if ( + lpnmlv->hdr.idFrom == IDC_RULES_BLOCKLIST || + lpnmlv->hdr.idFrom == IDC_RULES_SYSTEM || + lpnmlv->hdr.idFrom == IDC_RULES_CUSTOM + ) { command_id = IDM_PROPERTIES; } @@ -2835,65 +2898,6 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) break; } - //case WM_MOUSEHWHEEL: - //{ - // RDBG (L"%d", GET_KEYSTATE_WPARAM (wparam)); - - // if ((GET_KEYSTATE_WPARAM (wparam) & MK_CONTROL) == 0) - // break; - - - // bool is_tableview = app.ConfigGet (L"IsTableView", true).AsBool (); - // DWORD icons_size = app.ConfigGet (L"IconSize", SHIL_SYSSMALL).AsInt (); - - // const bool is_down = GET_WHEEL_DELTA_WPARAM (wparam) < 0; - - // //SHIL_EXTRALARGE - // //SHIL_LARGE - // //SHIL_SYSSMALL - - // if (is_down) - // { - // if (icons_size == SHIL_SYSSMALL) - // { - // is_tableview = !is_tableview; - // icons_size = SHIL_EXTRALARGE; - // } - // else if (icons_size == SHIL_LARGE) - // { - // icons_size = SHIL_SYSSMALL; - // } - // else if (icons_size == SHIL_EXTRALARGE) - // { - // icons_size = SHIL_LARGE; - // } - // } - // else - // { - // if (icons_size == SHIL_EXTRALARGE) - // { - // is_tableview = !is_tableview; - // icons_size = SHIL_SYSSMALL; - // } - // else if (icons_size == SHIL_LARGE) - // { - // icons_size = SHIL_SYSSMALL; - // } - // else if (icons_size == SHIL_SYSSMALL) - // { - // icons_size = SHIL_EXTRALARGE; - // } - // } - - // app.ConfigSet (L"IsTableView", is_tableview); - // app.ConfigSet (L"IconSize", icons_size); - - // _app_listviewsetimagelist (hwnd, _app_gettab_id (hwnd)); - - // SetWindowLongPtr (hwnd, DWLP_MSGRESULT, TRUE); - // return TRUE; - //} - case WM_SIZE: { _app_resizewindow (hwnd, LOWORD (lparam), HIWORD (lparam)); @@ -2941,8 +2945,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) app.LocaleMenu (hsubmenu, IDS_UNCHECK, IDM_UNCHECK, false, nullptr); app.LocaleMenu (hsubmenu, IDS_SELECT_ALL, IDM_SELECT_ALL, false, L"\tCtrl+A"); - app.LocaleMenu (hsubmenu, menu_id == IDM_RULES ? IDS_ADD : IDS_OPENRULESEDITOR, IDM_OPENRULESEDITOR, false, L"..."); - app.LocaleMenu (hsubmenu, menu_id == IDM_RULES ? IDS_EDIT2 : IDS_PROPERTIES, IDM_PROPERTIES, false, menu_id == IDM_APPS ? nullptr : L"...\tEnter"); + app.LocaleMenu (hsubmenu, IDS_OPENRULESEDITOR, IDM_OPENRULESEDITOR, false, L"..."); + app.LocaleMenu (hsubmenu, IDS_PROPERTIES, IDM_PROPERTIES, false, L"\tEnter"); if (!selected_count) { @@ -2988,17 +2992,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) app.LocaleMenu (hsubmenu, IDS_TRAY_RULES, usettings_id, true, nullptr); app.LocaleMenu (hsubmenu, IDS_TIMER, utimer_id, true, nullptr); - if (!selected_count) - { - EnableMenuItem (hsubmenu, usettings_id, MF_BYPOSITION | MF_DISABLED | MF_GRAYED); - EnableMenuItem (hsubmenu, utimer_id, MF_BYPOSITION | MF_DISABLED | MF_GRAYED); - } - // show configuration - if (selected_count) + if (selected_count && _r_fastlock_tryacquireshared (&lock_access)) { - _r_fastlock_acquireshared (&lock_access); - const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, ctrl_id, item); PITEM_APP const ptr_app = _app_getapplication (app_hash); @@ -3046,6 +3042,11 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_fastlock_releaseshared (&lock_access); } + else + { + EnableMenuItem (hsubmenu, usettings_id, MF_BYPOSITION | MF_DISABLED | MF_GRAYED); + EnableMenuItem (hsubmenu, utimer_id, MF_BYPOSITION | MF_DISABLED | MF_GRAYED); + } if (ctrl_id != IDC_APPS_PROFILE) { @@ -3057,19 +3058,19 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { if (ctrl_id == IDC_RULES_CUSTOM) { - _r_fastlock_acquireshared (&lock_access); + if (_r_fastlock_tryacquireshared (&lock_access)) + { + const size_t rule_idx = (size_t)_r_listview_getitemlparam (hwnd, ctrl_id, item); - const size_t rule_idx = (size_t)_r_listview_getitemlparam (hwnd, ctrl_id, item); + if (rules_arr.at (rule_idx)->is_readonly) + EnableMenuItem (hsubmenu, IDM_DELETE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); - if (rules_arr.at (rule_idx)->is_readonly) - EnableMenuItem (hsubmenu, IDM_DELETE, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); - - _r_fastlock_releaseshared (&lock_access); + _r_fastlock_releaseshared (&lock_access); + } } else { DeleteMenu (hsubmenu, IDM_OPENRULESEDITOR, MF_BYCOMMAND); - DeleteMenu (hsubmenu, IDM_PROPERTIES, MF_BYCOMMAND); DeleteMenu (hsubmenu, IDM_DELETE, MF_BYCOMMAND); DeleteMenu (hsubmenu, 0, MF_BYPOSITION); } @@ -3133,6 +3134,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) constexpr auto notifications_id = 4; constexpr auto logging_id = 5; constexpr auto errlog_id = 6; + constexpr auto pages_start_id = 7; const bool is_filtersinstalled = _wfp_isfiltersinstalled (); @@ -3195,9 +3197,12 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) app.LocaleMenu (hsubmenu, IDS_ABOUT, IDM_TRAY_ABOUT, false, nullptr); app.LocaleMenu (hsubmenu, IDS_EXIT, IDM_TRAY_EXIT, false, nullptr); - CheckMenuItem (hsubmenu, IDM_TRAY_ENABLELOG_CHK, MF_BYCOMMAND | (app.ConfigGet (L"IsLogEnabled", false).AsBool () ? MF_CHECKED : MF_UNCHECKED)); CheckMenuItem (hsubmenu, IDM_TRAY_ENABLENOTIFICATIONS_CHK, MF_BYCOMMAND | (app.ConfigGet (L"IsNotificationsEnabled", true).AsBool () ? MF_CHECKED : MF_UNCHECKED)); CheckMenuItem (hsubmenu, IDM_TRAY_ENABLENOTIFICATIONSSOUND_CHK, MF_BYCOMMAND | (app.ConfigGet (L"IsNotificationsSound", true).AsBool () ? MF_CHECKED : MF_UNCHECKED)); + CheckMenuItem (hsubmenu, IDM_TRAY_ENABLELOG_CHK, MF_BYCOMMAND | (app.ConfigGet (L"IsLogEnabled", false).AsBool () ? MF_CHECKED : MF_UNCHECKED)); + + if (!app.ConfigGet (L"IsNotificationsEnabled", true).AsBool ()) + EnableMenuItem (hsubmenu, IDM_TRAY_ENABLENOTIFICATIONSSOUND_CHK, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); if (_wfp_isfiltersapplying ()) EnableMenuItem (hsubmenu, IDM_TRAY_START, MF_BYCOMMAND | MF_DISABLED | MF_GRAYED); @@ -3225,7 +3230,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { case PBT_APMSUSPEND: { - _app_profile_save (hwnd); + _app_profile_save (); _wfp_uninitialize (false); SetWindowLongPtr (hwnd, DWLP_MSGRESULT, TRUE); @@ -3238,6 +3243,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) app.ConfigInit (); _app_profile_load (hwnd); + _app_refreshstatus (hwnd); if (_wfp_isfiltersinstalled ()) { @@ -3305,8 +3311,6 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) size_t item = LAST_VALUE; BOOL is_remove = (BOOL)-1; - _r_fastlock_acquireexclusive (&lock_access); - const UINT listview_id = _app_gettab_id (hwnd); const size_t rule_idx = (LOWORD (wparam) - IDX_RULES_SPECIAL); @@ -3321,6 +3325,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_rule->is_forservices && (app_hash == config.ntoskrnl_hash || app_hash == config.svchost_hash)) continue; + _r_fastlock_acquireexclusive (&lock_access); + PITEM_APP ptr_app = _app_getapplication (app_hash); if (ptr_app) @@ -3342,10 +3348,16 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _app_ruleenable (ptr_rule, true); } + _r_fastlock_acquireshared (&lock_checkbox); + _app_setappiteminfo (hwnd, listview_id, item, app_hash, ptr_app); + _r_fastlock_releaseshared (&lock_checkbox); + _r_fastlock_acquireexclusive (&lock_notification); - _app_freenotify (app_hash, false); + _app_freenotify (app_hash, false, true); _r_fastlock_releaseexclusive (&lock_notification); } + + _r_fastlock_releaseexclusive (&lock_access); } MFILTER_RULES rules; @@ -3354,12 +3366,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _wfp_create4filters (&rules, __LINE__); } - _r_fastlock_releaseexclusive (&lock_access); - - _app_notifyrefresh (config.hnotification, false); - _app_listviewsort (hwnd, listview_id); - _app_profile_save (hwnd); + _app_profile_save (); _r_listview_redraw (hwnd, listview_id); @@ -3372,28 +3380,28 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (!SendDlgItemMessage (hwnd, listview_id, LVM_GETSELECTEDCOUNT, 0, 0)) break; - const size_t idx = (LOWORD (wparam) - IDX_TIMER); - + const size_t timer_idx = (LOWORD (wparam) - IDX_TIMER); size_t item = LAST_VALUE; - - _r_fastlock_acquireexclusive (&lock_access); - MFILTER_APPS rules; while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) { + _r_fastlock_acquireshared (&lock_access); + const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); const PITEM_APP ptr_app = _app_getapplication (app_hash); - rules.push_back (ptr_app); + if (ptr_app) + rules.push_back (ptr_app); + + _r_fastlock_releaseshared (&lock_access); } - _app_timer_create (hwnd, &rules, timers.at (idx)); - - _r_fastlock_releaseexclusive (&lock_access); + _app_timer_create (hwnd, &rules, timers.at (timer_idx)); _app_listviewsort (hwnd, listview_id); - _app_profile_save (hwnd); + _app_profile_save (); + _app_refreshstatus (hwnd); _r_listview_redraw (hwnd, listview_id); @@ -3499,17 +3507,25 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { // make backup if (LOWORD (wparam) == IDM_IMPORT_APPS) + { + _r_fs_delete (config.apps_path_backup, false); _r_fs_copy (config.apps_path, config.apps_path_backup); + _r_fs_delete (config.apps_path, false); + _r_fs_copy (path, config.apps_path); + } + else if (LOWORD (wparam) == IDM_IMPORT_RULES) + { + _r_fs_delete (config.rules_custom_path_backup, false); _r_fs_copy (config.rules_custom_path, config.rules_custom_path_backup); - _app_profile_load (hwnd, ((LOWORD (wparam) == IDM_IMPORT_APPS) ? path : nullptr), ((LOWORD (wparam) == IDM_IMPORT_RULES) ? path : nullptr)); + _r_fs_delete (config.rules_custom_path, false); + _r_fs_copy (path, config.rules_custom_path); + } - _app_listviewsort (hwnd, _app_gettab_id (hwnd)); - _app_profile_save (hwnd); - - _app_notifyrefresh (config.hnotification, false); + _app_profile_load (hwnd); + _app_refreshstatus (hwnd); _app_changefilters (hwnd, true, false); } @@ -3521,7 +3537,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { const bool new_val = !app.ConfigGet (L"AlwaysOnTop", false).AsBool (); - CheckMenuItem (GetMenu (hwnd), IDM_ALWAYSONTOP_CHK, MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); + CheckMenuItem (GetMenu (hwnd), LOWORD (wparam), MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); app.ConfigSet (L"AlwaysOnTop", new_val); _r_wnd_top (hwnd, new_val); @@ -3533,7 +3549,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { const bool new_val = !app.ConfigGet (L"ShowFilenames", true).AsBool (); - CheckMenuItem (GetMenu (hwnd), IDM_SHOWFILENAMESONLY_CHK, MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); + CheckMenuItem (GetMenu (hwnd), LOWORD (wparam), MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); app.ConfigSet (L"ShowFilenames", new_val); const UINT listview_id = _app_gettab_id (hwnd); @@ -3551,15 +3567,15 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { _app_getdisplayname (app_hash, ptr_app, &ptr_app->display_name); - _r_listview_setitem (hwnd, listview_id, i, 0, ptr_app->display_name); + _r_fastlock_acquireshared (&lock_checkbox); + _app_setappiteminfo (hwnd, listview_id, i, app_hash, ptr_app); + _r_fastlock_releaseshared (&lock_checkbox); } } _r_fastlock_releaseexclusive (&lock_access); - _app_notifyrefresh (config.hnotification, false); _app_listviewsort (hwnd, listview_id); - _r_listview_redraw (hwnd, listview_id); } @@ -3570,7 +3586,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { const bool new_val = !app.ConfigGet (L"AutoSizeColumns", true).AsBool (); - CheckMenuItem (GetMenu (hwnd), IDM_AUTOSIZECOLUMNS_CHK, MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); + CheckMenuItem (GetMenu (hwnd), LOWORD (wparam), MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); app.ConfigSet (L"AutoSizeColumns", new_val); _app_listviewresize (hwnd, _app_gettab_id (hwnd)); @@ -3582,7 +3598,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { const bool new_val = !app.ConfigGet (L"IsEnableSpecialGroup", true).AsBool (); - CheckMenuItem (GetMenu (hwnd), IDM_ENABLESPECIALGROUP_CHK, MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); + CheckMenuItem (GetMenu (hwnd), LOWORD (wparam), MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); app.ConfigSet (L"IsEnableSpecialGroup", new_val); const UINT listview_id = _app_gettab_id (hwnd); @@ -3597,7 +3613,11 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) const PITEM_APP ptr_app = _app_getapplication (app_hash); if (ptr_app) - _r_listview_setitem (hwnd, listview_id, i, 0, nullptr, LAST_VALUE, _app_getappgroup (app_hash, ptr_app)); + { + _r_fastlock_acquireshared (&lock_checkbox); + _app_setappiteminfo (hwnd, listview_id, i, app_hash, ptr_app); + _r_fastlock_releaseshared (&lock_checkbox); + } } _r_fastlock_releaseshared (&lock_access); @@ -3625,6 +3645,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) else icon_size = SHIL_SYSSMALL; + CheckMenuRadioItem (GetMenu (hwnd), IDM_ICONSSMALL, IDM_ICONSEXTRALARGE, LOWORD (wparam), MF_BYCOMMAND); app.ConfigSet (L"IconSize", icon_size); _app_listviewsetview (hwnd, listview_id); @@ -3637,9 +3658,12 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_ICONSISTABLEVIEW: { - const UINT listview_id = _app_gettab_id (hwnd); + const bool new_val = !app.ConfigGet (L"IsTableView", true).AsBool (); - app.ConfigSet (L"IsTableView", !app.ConfigGet (L"IsTableView", true).AsBool ()); + 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); _app_listviewsetview (hwnd, listview_id); _app_listviewresize (hwnd, listview_id); @@ -3653,10 +3677,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { const bool new_val = !app.ConfigGet (L"IsIconsHidden", false).AsBool (); + CheckMenuItem (GetMenu (hwnd), LOWORD (wparam), MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); app.ConfigSet (L"IsIconsHidden", new_val); - CheckMenuItem (GetMenu (hwnd), IDM_ICONSISHIDDEN, MF_BYCOMMAND | (new_val ? MF_CHECKED : MF_UNCHECKED)); - const UINT listview_id = _app_gettab_id (hwnd); if (listview_id) @@ -3670,10 +3693,9 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_app) { - size_t icon_id; - _app_getappicon (ptr_app, false, &icon_id, nullptr); - - _r_listview_setitem (hwnd, listview_id, i, 0, nullptr, icon_id); + _r_fastlock_acquireshared (&lock_checkbox); + _app_setappiteminfo (hwnd, listview_id, i, app_hash, ptr_app); + _r_fastlock_releaseshared (&lock_checkbox); } } @@ -3704,6 +3726,12 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { app.ConfigSet (L"Font", lf.lfFaceName[0] ? _r_fmt (L"%s;%d;%d", lf.lfFaceName, _r_dc_fontheighttosize (lf.lfHeight), lf.lfWeight) : UI_FONT_DEFAULT); + if (config.hfont) + { + DeleteObject (config.hfont); + config.hfont = nullptr; + } + for (size_t i = 0; i < (size_t)SendDlgItemMessage (hwnd, IDC_TAB, TCM_GETITEMCOUNT, 0, 0); i++) _app_listviewsetfont (hwnd, _app_gettab_id (hwnd, i), false); } @@ -3719,6 +3747,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) app.ConfigInit (); _app_profile_load (hwnd); + _app_refreshstatus (hwnd); _app_changefilters (hwnd, true, false); @@ -3744,7 +3773,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_toolbar_setbuttoninfo (config.hrebar, IDC_TOOLBAR, LOWORD (wparam), nullptr, 0, new_val ? TBSTATE_PRESSED | TBSTATE_ENABLED : TBSTATE_ENABLED); app.ConfigSet (L"IsNotificationsEnabled", new_val); - _app_notifyrefresh (config.hnotification, false); + _app_notifyrefresh (config.hnotification, true); break; } @@ -3783,7 +3812,10 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) break; _app_freelogstack (); + + _r_fastlock_acquireexclusive (&lock_writelog); _app_logclear (); + _r_fastlock_releaseexclusive (&lock_writelog); } break; @@ -3864,7 +3896,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_fastlock_releaseexclusive (&lock_access); _app_listviewsort (hwnd, IDC_APPS_PROFILE); - _app_profile_save (hwnd); + _app_profile_save (); _app_showitem (hwnd, IDC_APPS_PROFILE, app_hash); } @@ -3894,7 +3926,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) size_t item = LAST_VALUE; BOOL new_val = BOOL (-1); - _r_fastlock_acquireexclusive (&lock_access); + _r_fastlock_acquireshared (&lock_access); while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) { @@ -3906,7 +3938,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ctrl_id == IDM_EXPLORE) { - if (ptr_app->type != AppPico && ptr_app->type != AppDevice && (ptr_app->real_path && ptr_app->real_path[0])) + if (ptr_app->type != DataAppPico && ptr_app->type != DataAppDevice && (ptr_app->real_path && ptr_app->real_path[0])) { if (_r_fs_exists (ptr_app->real_path)) _r_run (nullptr, _r_fmt (L"\"explorer.exe\" /select,\"%s\"", ptr_app->real_path)); @@ -3925,7 +3957,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) ptr_app->is_silent = new_val; _r_fastlock_acquireexclusive (&lock_notification); - _app_freenotify (app_hash, false); + _app_freenotify (app_hash, false, true); _r_fastlock_releaseexclusive (&lock_notification); } } @@ -3935,21 +3967,20 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) } } + _r_fastlock_releaseshared (&lock_access); + if (ctrl_id == IDM_DISABLETIMER) _app_timer_remove (hwnd, &rules); - _r_fastlock_releaseexclusive (&lock_access); - if ( ctrl_id == IDM_DISABLETIMER || ctrl_id == IDM_DISABLENOTIFICATIONS ) { - _app_notifyrefresh (config.hnotification, false); _app_refreshstatus (hwnd); _app_listviewsort (hwnd, listview_id); - _app_profile_save (hwnd); + _app_profile_save (); _r_listview_redraw (hwnd, listview_id); } @@ -4002,13 +4033,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) listview_id == IDC_APPS_PACKAGE ) { - size_t item = LAST_VALUE; - - _r_fastlock_acquireexclusive (&lock_access); - MFILTER_APPS rules; - - _r_fastlock_acquireshared (&lock_checkbox); + size_t item = LAST_VALUE; while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) { @@ -4017,12 +4043,15 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_app) { + _r_fastlock_acquireexclusive (&lock_access); + if (ptr_app->is_enabled != new_val) { ptr_app->is_enabled = new_val; - _r_listview_setitem (hwnd, listview_id, item, 0, nullptr, LAST_VALUE, _app_getappgroup (app_hash, ptr_app)); - _r_listview_setitemcheck (hwnd, listview_id, item, new_val); + _r_fastlock_acquireshared (&lock_checkbox); + _app_setappiteminfo (hwnd, listview_id, item, app_hash, ptr_app); + _r_fastlock_releaseshared (&lock_checkbox); rules.push_back (ptr_app); @@ -4030,21 +4059,18 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) timer_apps.push_back (ptr_app); _r_fastlock_acquireexclusive (&lock_notification); - _app_freenotify (app_hash, false); + _app_freenotify (app_hash, false, true); _r_fastlock_releaseexclusive (&lock_notification); - if (!is_changed) - is_changed = true; + is_changed = true; } + + _r_fastlock_releaseexclusive (&lock_access); } } - _r_fastlock_releaseshared (&lock_checkbox); - if (is_changed) _wfp_create3filters (&rules, __LINE__); - - _r_fastlock_releaseexclusive (&lock_access); } else if ( listview_id == IDC_RULES_BLOCKLIST || @@ -4052,13 +4078,8 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) listview_id == IDC_RULES_CUSTOM ) { - size_t item = LAST_VALUE; - - _r_fastlock_acquireexclusive (&lock_access); - MFILTER_RULES rules; - - _r_fastlock_acquireshared (&lock_checkbox); + size_t item = LAST_VALUE; while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) { @@ -4067,35 +4088,35 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_rule) { + _r_fastlock_acquireexclusive (&lock_access); + if (ptr_rule->is_enabled != new_val) { _app_ruleenable (ptr_rule, new_val); - _app_setruleitem (hwnd, listview_id, item, ptr_rule); + + _r_fastlock_acquireshared (&lock_checkbox); + _app_setruleiteminfo (hwnd, listview_id, item, ptr_rule); + _r_fastlock_releaseshared (&lock_checkbox); rules.push_back (ptr_rule); - if (!is_changed) - is_changed = true; + is_changed = true; } + + _r_fastlock_releaseexclusive (&lock_access); } } - _r_fastlock_releaseshared (&lock_checkbox); - if (is_changed) _wfp_create4filters (&rules, __LINE__); - - _r_fastlock_releaseexclusive (&lock_access); } if (is_changed) { _app_timer_remove (hwnd, &timer_apps); - _app_notifyrefresh (config.hnotification, false); - _app_listviewsort (hwnd, listview_id); - _app_profile_save (hwnd); + _app_profile_save (); _app_refreshstatus (hwnd); @@ -4107,7 +4128,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_EDITRULES: { - _app_settab_id (hwnd, IDC_RULES_CUSTOM); + _app_settab_id (hwnd, _app_getlistview_id (DataRuleCustom)); break; } @@ -4119,7 +4140,7 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { _app_ruleenable (ptr_rule, true); - ptr_rule->type = TypeCustom; + ptr_rule->type = DataRuleCustom; ptr_rule->is_block = false; const UINT listview_id = _app_gettab_id (hwnd); @@ -4147,14 +4168,14 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) rstring rule_remote; rstring rule_local; - _r_fastlock_acquireshared (&lock_network); - ptr_rule->is_block = true; while ((item = (size_t)SendDlgItemMessage (hwnd, listview_id, LVM_GETNEXTITEM, item, LVNI_SELECTED)) != LAST_VALUE) { - const size_t idx = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); - PITEM_NETWORK ptr_network = network_arr.at (idx); + _r_fastlock_acquireshared (&lock_network); + + const size_t network_idx = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + PITEM_NETWORK ptr_network = network_arr.at (network_idx); if (ptr_network) { @@ -4178,17 +4199,17 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) LPWSTR fmt = nullptr; - _app_formataddress (ptr_network->af, &ptr_network->remote_addr, ptr_network->remote_port, &fmt, false); - rule_remote.AppendFormat (L"%s" RULE_DELIMETER, fmt); + if (_app_formataddress (ptr_network->af, &ptr_network->remote_addr, ptr_network->remote_port, &fmt, false)) + rule_remote.AppendFormat (L"%s" RULE_DELIMETER, fmt); - _app_formataddress (ptr_network->af, &ptr_network->local_addr, ptr_network->local_port, &fmt, false); - rule_local.AppendFormat (L"%s" RULE_DELIMETER, fmt); + if (_app_formataddress (ptr_network->af, &ptr_network->local_addr, ptr_network->local_port, &fmt, false)) + rule_local.AppendFormat (L"%s" RULE_DELIMETER, fmt); SAFE_DELETE_ARRAY (fmt); } - } - _r_fastlock_releaseshared (&lock_network); + _r_fastlock_releaseshared (&lock_network); + } rule_remote.Trim (RULE_DELIMETER); rule_local.Trim (RULE_DELIMETER); @@ -4197,32 +4218,35 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) _r_str_alloc (&ptr_rule->prule_local, rule_local.GetLength (), rule_local); } - if (DialogBoxParam (nullptr, MAKEINTRESOURCE (IDD_EDITOR), hwnd, &EditorProc, (LPARAM)ptr_rule)) + if (ptr_rule && DialogBoxParam (nullptr, MAKEINTRESOURCE (IDD_EDITOR), hwnd, &EditorProc, (LPARAM)ptr_rule)) { _r_fastlock_acquireexclusive (&lock_access); rules_arr.push_back (ptr_rule); - - _r_fastlock_acquireshared (&lock_checkbox); - - const size_t lv_item = _r_listview_getitemcount (hwnd, IDC_RULES_CUSTOM); - - _r_listview_additem (hwnd, IDC_RULES_CUSTOM, lv_item, 0, ptr_rule->pname, _app_getruleicon (ptr_rule), _app_getrulegroup (ptr_rule), rules_arr.size () - 1); - _app_setruleitem (hwnd, IDC_RULES_CUSTOM, lv_item, ptr_rule); - - _r_fastlock_releaseshared (&lock_checkbox); - - MFILTER_RULES rules; - rules.push_back (ptr_rule); - - _wfp_create4filters (&rules, __LINE__); + const size_t rule_idx = rules_arr.size () - 1; _r_fastlock_releaseexclusive (&lock_access); - _app_listviewsort (hwnd, listview_id); - _app_profile_save (hwnd); + const UINT listview_rules_id = _app_getlistview_id (DataRuleCustom); + + if (listview_rules_id) + { + _r_fastlock_acquireshared (&lock_checkbox); + + const size_t new_item = _r_listview_getitemcount (hwnd, listview_rules_id); + + _r_listview_additem (hwnd, listview_rules_id, new_item, 0, ptr_rule->pname, _app_getruleicon (ptr_rule), _app_getrulegroup (ptr_rule), rule_idx); + _app_setruleiteminfo (hwnd, listview_rules_id, new_item, ptr_rule); + + _r_fastlock_releaseshared (&lock_checkbox); + } _r_listview_redraw (hwnd, listview_id); + + _app_listviewsort (hwnd, listview_id); + _app_profile_save (); + + _app_refreshstatus (hwnd); } else { @@ -4247,10 +4271,12 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) listview_id == IDC_APPS_PACKAGE ) { + _r_fastlock_acquireshared (&lock_access); + const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); const PITEM_APP ptr_app = _app_getapplication (app_hash); - if (ptr_app->type != AppPico && ptr_app->type != AppDevice && _r_fs_exists (ptr_app->real_path)) + if (ptr_app->type != DataAppPico && ptr_app->type != DataAppDevice && _r_fs_exists (ptr_app->real_path)) { SHELLEXECUTEINFO shex = {0}; @@ -4263,8 +4289,14 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) ShellExecuteEx (&shex); } + + _r_fastlock_releaseshared (&lock_access); } - else if (listview_id == IDC_RULES_CUSTOM) + else if ( + listview_id == IDC_RULES_BLOCKLIST || + listview_id == IDC_RULES_SYSTEM || + listview_id == IDC_RULES_CUSTOM + ) { const size_t rule_idx = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); const PITEM_RULE ptr_rule = rules_arr.at (rule_idx); @@ -4273,47 +4305,38 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { if (DialogBoxParam (nullptr, MAKEINTRESOURCE (IDD_EDITOR), hwnd, &EditorProc, (LPARAM)ptr_rule)) { - _r_fastlock_acquireexclusive (&lock_access); - - MFILTER_RULES rules; - rules.push_back (ptr_rule); - - _wfp_create4filters (&rules, __LINE__); - _r_fastlock_acquireshared (&lock_checkbox); - - _app_setruleitem (hwnd, listview_id, item, ptr_rule); - + _app_setruleiteminfo (hwnd, listview_id, item, ptr_rule); _r_fastlock_releaseshared (&lock_checkbox); - _r_fastlock_releaseexclusive (&lock_access); + _r_listview_redraw (hwnd, listview_id); _app_listviewsort (hwnd, listview_id); - _app_profile_save (hwnd); + _app_profile_save (); - _r_listview_redraw (hwnd, listview_id); + _app_refreshstatus (hwnd); } } } - else if (listview_id == IDC_NETWORK) - { - _r_fastlock_acquireexclusive (&lock_access); - _r_fastlock_acquireshared (&lock_network); + //else if (listview_id == IDC_NETWORK) + //{ + // _r_fastlock_acquireexclusive (&lock_access); + // _r_fastlock_acquireshared (&lock_network); - const size_t idx = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); - const PITEM_NETWORK ptr_network = network_arr.at (idx); + // const size_t idx = (size_t)_r_listview_getitemlparam (hwnd, listview_id, item); + // const PITEM_NETWORK ptr_network = network_arr.at (idx); - if (ptr_network) - { - if (!_app_getapplication (ptr_network->hash)) - _app_addapplication (hwnd, ptr_network->path, 0, 0, 0, false, false, true); + // if (ptr_network) + // { + // if (!_app_getapplication (ptr_network->hash)) + // _app_addapplication (hwnd, ptr_network->path, 0, 0, 0, false, false, true); - _app_showitem (hwnd, _app_getapplistview_id (ptr_network->hash), ptr_network->hash); - } + // _app_showitem (hwnd, _app_getapplistview_id (ptr_network->hash), ptr_network->hash); + // } - _r_fastlock_releaseshared (&lock_network); - _r_fastlock_releaseexclusive (&lock_access); - } + // _r_fastlock_releaseshared (&lock_network); + // _r_fastlock_releaseexclusive (&lock_access); + //} break; } @@ -4334,12 +4357,12 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) MARRAY ids; - _r_fastlock_acquireexclusive (&lock_access); - for (size_t i = count; i != LAST_VALUE; i--) { if (ListView_GetItemState (GetDlgItem (hwnd, listview_id), i, LVNI_SELECTED)) { + _r_fastlock_acquireexclusive (&lock_access); + if (listview_id == IDC_APPS_PROFILE) { const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_id, i); @@ -4348,7 +4371,6 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) if (ptr_app && !ptr_app->is_undeletable) // skip "undeletable" apps { ids.insert (ids.end (), ptr_app->mfarr.begin (), ptr_app->mfarr.end ()); - ptr_app->mfarr.clear (); SendDlgItemMessage (hwnd, listview_id, LVM_DELETEITEM, i, 0); _app_freeapplication (app_hash); @@ -4357,28 +4379,25 @@ 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); - PITEM_RULE ptr_rule = rules_arr.at (rule_idx); + PITEM_RULE *ptr_rule = &rules_arr.at (rule_idx); - if (ptr_rule && !ptr_rule->is_readonly) // skip "read-only" rules + if ((*ptr_rule) && !(*ptr_rule)->is_readonly) // skip "read-only" rules { - ids.insert (ids.end (), ptr_rule->mfarr.begin (), ptr_rule->mfarr.end ()); - ptr_rule->mfarr.clear (); + ids.insert (ids.end (), (*ptr_rule)->mfarr.begin (), (*ptr_rule)->mfarr.end ()); SendDlgItemMessage (hwnd, listview_id, LVM_DELETEITEM, i, 0); - _app_freerule (&ptr_rule); + _app_freerule (ptr_rule); } } + + _r_fastlock_releaseexclusive (&lock_access); } } _wfp_destroy2filters (&ids, __LINE__); - _r_fastlock_releaseexclusive (&lock_access); - - _app_notifyrefresh (config.hnotification, false); _app_refreshstatus (hwnd); - - _app_profile_save (hwnd); + _app_profile_save (); _r_listview_redraw (hwnd, listview_id); @@ -4397,47 +4416,44 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) MARRAY ids; - _r_fastlock_acquireexclusive (&lock_access); - for (size_t i = 0; i < _countof (listview_ids); i++) { const size_t count = _r_listview_getitemcount (hwnd, listview_ids[i]) - 1; for (size_t j = count; j != LAST_VALUE; j--) { + _r_fastlock_acquireexclusive (&lock_access); + const size_t app_hash = (size_t)_r_listview_getitemlparam (hwnd, listview_ids[i], j); PITEM_APP ptr_app = _app_getapplication (app_hash); if (ptr_app) { - if (!ptr_app->is_undeletable && (!_app_isappexists (ptr_app) || ((ptr_app->type != AppService && ptr_app->type != AppPackage) && !_app_isappused (ptr_app, app_hash)))) + if (!ptr_app->is_undeletable && (!_app_isappexists (ptr_app) || ((ptr_app->type != DataAppService && ptr_app->type != DataAppPackage) && !_app_isappused (ptr_app, app_hash)))) { ids.insert (ids.end (), ptr_app->mfarr.begin (), ptr_app->mfarr.end ()); - ptr_app->mfarr.clear (); SendDlgItemMessage (hwnd, listview_ids[i], LVM_DELETEITEM, j, 0); _app_freeapplication (app_hash); - if (!is_deleted) - is_deleted = true; + is_deleted = true; } } + + _r_fastlock_releaseexclusive (&lock_access); } } - _wfp_destroy2filters (&ids, __LINE__); - - _r_fastlock_releaseexclusive (&lock_access); - if (is_deleted) { - _app_notifyrefresh (config.hnotification, false); - _app_refreshstatus (hwnd); + _wfp_destroy2filters (&ids, __LINE__); const UINT listview_id = _app_gettab_id (hwnd); + _app_refreshstatus (hwnd); + _app_listviewsort (hwnd, listview_id); - _app_profile_save (hwnd); + _app_profile_save (); _r_listview_redraw (hwnd, listview_id); } @@ -4447,10 +4463,10 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) case IDM_PURGE_TIMERS: { - if (!_app_istimersactive () || !app.ConfirmMessage (hwnd, nullptr, app.LocaleString (IDS_QUESTION_TIMERS, nullptr), L"ConfirmTimers")) + if (!_app_istimersactive () || _r_msg (hwnd, MB_YESNO | MB_ICONEXCLAMATION, APP_NAME, nullptr, app.LocaleString (IDS_QUESTION_TIMERS, nullptr)) != IDYES) break; - _r_fastlock_acquireexclusive (&lock_access); + _r_fastlock_acquireshared (&lock_access); MFILTER_APPS rules; @@ -4460,19 +4476,19 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) rules.push_back (&p.second); } - _app_timer_remove (hwnd, &rules); + _r_fastlock_releaseshared (&lock_access); - _r_fastlock_releaseexclusive (&lock_access); + if (_app_timer_remove (hwnd, &rules)) + { + const UINT listview_id = _app_gettab_id (hwnd); - _app_notifyrefresh (config.hnotification, false); - _app_refreshstatus (hwnd); + _app_refreshstatus (hwnd); - const UINT listview_id = _app_gettab_id (hwnd); + _app_listviewsort (hwnd, listview_id); + _app_profile_save (); - _app_listviewsort (hwnd, listview_id); - _app_profile_save (hwnd); - - _r_listview_redraw (hwnd, listview_id); + _r_listview_redraw (hwnd, listview_id); + } break; } @@ -4498,35 +4514,32 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) #define LM_AD L"192.168.2.1" #define LP_AD 0 - case 999: + case 997: { - static const UINT32 flags = FWPM_NET_EVENT_FLAG_APP_ID_SET | - FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET | - FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET | - FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET | - FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET | - FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET | - FWPM_NET_EVENT_FLAG_USER_ID_SET | - FWPM_NET_EVENT_FLAG_IP_VERSION_SET; - - FILETIME ft = {0}; - GetSystemTimeAsFileTime (&ft); - - sockaddr_in ipv4_remote = {0}; - sockaddr_in ipv4_local = {0}; - INT len1 = sizeof (ipv4_remote); - INT len2 = sizeof (ipv4_local); - - rstring path = app.GetBinaryPath ();; - _r_path_ntpathfromdos (path); - - for (int i = 0; i < 255; i++) - { - WSAStringToAddress (_r_fmt (RM_AD, i + 1).GetBuffer (), AF_INET, nullptr, (sockaddr *)& ipv4_remote, &len1); - WSAStringToAddress (_r_fmt (LM_AD, i + 1).GetBuffer (), AF_INET, nullptr, (sockaddr *)& ipv4_local, &len2); - - _wfp_logcallback (flags, &ft, (UINT8 *)path.GetString (), nullptr, nullptr, IPPROTO_TCP, FWP_IP_VERSION_V4, ntohl (ipv4_remote.sin_addr.S_un.S_addr), nullptr, RP_AD, 0, nullptr, LP_AD, 0, 9240001 + i, FWP_DIRECTION_INBOUND, false, false); - } + _r_msg (hwnd, MB_OK | MB_ICONINFORMATION, APP_NAME, L"fastlock information:", L"%s: %d\r\n%s: %d\r\n%s: %d\r\n%s: %d\r\n%s: %d\r\n%s: %d\r\n%s: %d\r\n%s: %d\r\n%s: %d\r\n%s: %d\r\n%s: %d", + L"lock_access", + _r_fastlock_islocked (&lock_access), + L"lock_apply", + _r_fastlock_islocked (&lock_apply), + L"lock_cache", + _r_fastlock_islocked (&lock_cache), + L"lock_checkbox", + _r_fastlock_islocked (&lock_checkbox), + L"lock_logbusy", + _r_fastlock_islocked (&lock_logbusy), + L"lock_logthread", + _r_fastlock_islocked (&lock_logthread), + L"lock_network", + _r_fastlock_islocked (&lock_network), + L"lock_notification", + _r_fastlock_islocked (&lock_notification), + L"lock_threadpool", + _r_fastlock_islocked (&lock_threadpool), + L"lock_transaction", + _r_fastlock_islocked (&lock_transaction), + L"lock_writelog", + _r_fastlock_islocked (&lock_writelog) + ); break; } @@ -4564,6 +4577,39 @@ INT_PTR CALLBACK DlgProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) break; } + + case 999: + { + static const UINT32 flags = FWPM_NET_EVENT_FLAG_APP_ID_SET | + FWPM_NET_EVENT_FLAG_IP_PROTOCOL_SET | + FWPM_NET_EVENT_FLAG_LOCAL_ADDR_SET | + FWPM_NET_EVENT_FLAG_LOCAL_PORT_SET | + FWPM_NET_EVENT_FLAG_REMOTE_ADDR_SET | + FWPM_NET_EVENT_FLAG_REMOTE_PORT_SET | + FWPM_NET_EVENT_FLAG_USER_ID_SET | + FWPM_NET_EVENT_FLAG_IP_VERSION_SET; + + FILETIME ft = {0}; + GetSystemTimeAsFileTime (&ft); + + sockaddr_in ipv4_remote = {0}; + sockaddr_in ipv4_local = {0}; + INT len1 = sizeof (ipv4_remote); + INT len2 = sizeof (ipv4_local); + + rstring path = app.GetBinaryPath ();; + _r_path_ntpathfromdos (path); + + for (int i = 0; i < 255; i++) + { + WSAStringToAddress (_r_fmt (RM_AD, i + 1).GetBuffer (), AF_INET, nullptr, (sockaddr *)& ipv4_remote, &len1); + WSAStringToAddress (_r_fmt (LM_AD, i + 1).GetBuffer (), AF_INET, nullptr, (sockaddr *)& ipv4_local, &len2); + + _wfp_logcallback (flags, &ft, (UINT8 *)path.GetString (), nullptr, nullptr, IPPROTO_TCP, FWP_IP_VERSION_V4, ntohl (ipv4_remote.sin_addr.S_un.S_addr), nullptr, RP_AD, 0, nullptr, LP_AD, 0, 9240001 + i, FWP_DIRECTION_INBOUND, false, false); + } + + break; + } #endif // _APP_BETA || _APP_BETA_RC } diff --git a/src/main.hpp b/src/main.hpp index 6b95aefa..073153e2 100644 --- a/src/main.hpp +++ b/src/main.hpp @@ -52,30 +52,21 @@ extern "C" { }; // enums -enum EnumAppType +enum EnumDataType { - AppRegular = 0, - AppDevice = 1, - AppNetwork = 2, - AppService = 3, - AppPackage = 4, // win8+ - AppPico = 5 // win10+ -}; - -enum EnumRuleType -{ - TypeRuleUnknown = 0, - TypeBlocklist = 1, - TypeSystem = 2, - TypeCustom = 3, -}; - -enum EnumRuleItemType -{ - TypeRuleItemUnknown = 0, - TypeHost = 1, - TypeIp = 2, - TypePort = 4, + DataUnknown, + DataAppRegular, + DataAppDevice, + DataAppNetwork, + DataAppService, + DataAppPackage, // win8+ + DataAppPico, // win10+ + DataRuleBlocklist, + DataRuleSystem, + DataRuleCustom, + DataTypePort, + DataTypeIp, + DataTypeHost }; enum EnumXmlType @@ -300,7 +291,7 @@ typedef struct tagITEM_APP size_t icon_id = 0; - EnumAppType type = AppRegular; + EnumDataType type = DataUnknown; bool is_haveerrors = false; @@ -343,7 +334,7 @@ typedef struct tagITEM_RULE UINT8 weight = 0; UINT8 protocol = 0; - EnumRuleType type = TypeRuleUnknown; + EnumDataType type = DataUnknown; bool is_haveerrors = false; bool is_forservices = false; @@ -476,6 +467,8 @@ typedef struct tagITEM_NETWORK size_t icon_id=0; + DWORD state = 0; + UINT16 remote_port = 0; UINT16 local_port = 0; @@ -507,7 +500,7 @@ typedef struct tagITEM_ADD size_t hash = 0; time_t timestamp = 0; - EnumAppType type = AppRegular; + EnumDataType type = DataUnknown; LPWSTR display_name = nullptr; LPWSTR real_path = nullptr; @@ -573,7 +566,7 @@ typedef struct tagITEM_ADDRESS FWP_RANGE* prange = nullptr; - EnumRuleItemType type = TypeRuleItemUnknown; + EnumDataType type = DataUnknown; NET_ADDRESS_FORMAT format = NET_ADDRESS_FORMAT_UNSPECIFIED; diff --git a/src/notifications.cpp b/src/notifications.cpp index 7b0edb36..1744f423 100644 --- a/src/notifications.cpp +++ b/src/notifications.cpp @@ -27,7 +27,7 @@ void _app_notifycreatewindow () static const INT cxsmIcon = GetSystemMetrics (SM_CXSMICON); static const INT IconSize = app.GetDPI (20); - config.hnotification = CreateWindowEx (WS_EX_TOPMOST | WS_EX_TOOLWINDOW, NOTIFY_CLASS_DLG, nullptr, WS_POPUP, 0, 0, wnd_width, wnd_height, nullptr, nullptr, wcex.hInstance, nullptr); + config.hnotification = CreateWindowEx (WS_EX_TOPMOST | WS_EX_TOOLWINDOW, NOTIFY_CLASS_DLG, nullptr, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, wnd_width, wnd_height, nullptr, nullptr, wcex.hInstance, nullptr); if (!config.hnotification) return; @@ -155,84 +155,93 @@ bool _app_notifycommand (HWND hwnd, UINT ctrl_id, size_t timer_idx) { _r_fastlock_acquireexclusive (&lock_notification); - const size_t idx = _app_notifygetcurrent (hwnd); + size_t app_hash = 0; + const size_t notify_idx = _app_notifygetcurrent (hwnd); - if (idx != LAST_VALUE) + if (notify_idx != LAST_VALUE) { - PITEM_LOG ptr_log = notifications.at (idx); + PITEM_LOG ptr_log = notifications.at (notify_idx); if (ptr_log) - { - _r_fastlock_acquireexclusive (&lock_access); + app_hash = ptr_log->hash; - const size_t hash = ptr_log->hash; - const size_t item = _app_getposition (app.GetHWND (), hash); + _app_freenotify (notify_idx, true, false); - PITEM_APP ptr_app = _app_getapplication (hash); + if (app_hash) + _app_freenotify (app_hash, false, false); - if (ptr_app) - { - if (ctrl_id == IDC_ALLOW_BTN || ctrl_id == IDC_BLOCK_BTN) - { - ptr_app->is_enabled = (ctrl_id == IDC_ALLOW_BTN); - - if (ctrl_id == IDC_BLOCK_BTN) - ptr_app->is_silent = true; - - _r_fastlock_acquireshared (&lock_checkbox); - - _r_listview_setitem (app.GetHWND (), IDC_APPS_PROFILE, item, 0, nullptr, LAST_VALUE, _app_getappgroup (hash, ptr_app)); - _r_listview_setitemcheck (app.GetHWND (), IDC_APPS_PROFILE, item, ptr_app->is_enabled); - - _r_fastlock_releaseshared (&lock_checkbox); - - MFILTER_APPS rules; - rules.push_back (ptr_app); - - // create rule timer - if (timer_idx != LAST_VALUE) - { - _app_timer_create (app.GetHWND (), &rules, timers.at (timer_idx)); - } - else - { - _wfp_create3filters (&rules, __LINE__); - } - } - else if (ctrl_id == IDM_DISABLENOTIFICATIONS) - { - ptr_app->is_silent = true; - } - else if (ctrl_id == IDC_LATER_BTN) - { - // TODO - } - - ptr_app->last_notify = _r_unixtime_now (); - - _r_fastlock_releaseexclusive (&lock_access); - - _app_freenotify (hash, false); - - _r_fastlock_releaseexclusive (&lock_notification); - - _app_notifyrefresh (hwnd, true); - - _app_listviewsort (app.GetHWND (), IDC_APPS_PROFILE); - _app_profile_save (app.GetHWND ()); - - _r_listview_redraw (app.GetHWND (), IDC_APPS_PROFILE); - - return true; - } - - _r_fastlock_releaseexclusive (&lock_access); - } + _app_notifyrefresh (hwnd, true); } _r_fastlock_releaseexclusive (&lock_notification); - return false; + if (!app_hash) + return false; + + PITEM_APP ptr_app = _app_getapplication (app_hash); + + if (!ptr_app) + return false; + + MFILTER_APPS rules; + + const UINT listview_id = _app_getlistview_id (ptr_app->type); + const size_t item = _app_getposition (app.GetHWND (), app_hash); + + _r_fastlock_acquireexclusive (&lock_access); + + if (ctrl_id == IDC_ALLOW_BTN || ctrl_id == IDC_BLOCK_BTN) + { + ptr_app->is_enabled = (ctrl_id == IDC_ALLOW_BTN); + ptr_app->is_silent = (ctrl_id == IDC_BLOCK_BTN); + + if (item != LAST_VALUE) + { + _r_fastlock_acquireshared (&lock_checkbox); + + _r_listview_setitem (app.GetHWND (), listview_id, item, 0, nullptr, LAST_VALUE, _app_getappgroup (app_hash, ptr_app)); + _r_listview_setitemcheck (app.GetHWND (), listview_id, item, ptr_app->is_enabled); + + _r_fastlock_releaseshared (&lock_checkbox); + } + + rules.push_back (ptr_app); + } + else if (ctrl_id == IDM_DISABLENOTIFICATIONS) + { + ptr_app->is_silent = true; + } + else if (ctrl_id == IDC_LATER_BTN) + { + // TODO + } + + ptr_app->last_notify = _r_unixtime_now (); + + _r_fastlock_releaseexclusive (&lock_access); + + // create filters + if (!rules.empty ()) + { + if (timer_idx != LAST_VALUE) + _app_timer_create (app.GetHWND (), &rules, timers.at (timer_idx)); + + else + _wfp_create3filters (&rules, __LINE__); + } + + _app_profile_save (); + + if (_app_gettab_id (app.GetHWND ()) == listview_id) + { + _app_listviewsort (app.GetHWND (), listview_id); + _r_listview_redraw (app.GetHWND (), listview_id); + } + + _r_fastlock_releaseexclusive (&lock_access); + + return true; + } bool _app_notifyadd (HWND hwnd, PITEM_LOG const ptr_log, PITEM_APP const ptr_app) @@ -254,21 +263,11 @@ bool _app_notifyadd (HWND hwnd, PITEM_LOG const ptr_log, PITEM_APP const ptr_app ptr_app->last_notify = current_time; - // remove existing log item (if exists) - for (size_t i = 0; i < notifications.size (); i++) - { - PITEM_LOG ptr_chk = notifications.at (i); - - if (ptr_chk && ptr_chk->hash == ptr_log->hash) - { - _app_freenotify (i, true); - break; - } - } + _app_freenotify (ptr_log->hash, false, false); // remove existing log item (if exists) // prevent notifications overflow if ((notifications.size () >= NOTIFY_LIMIT_SIZE)) - _app_freenotify (0, true); + _app_freenotify (0, true, false); notifications.push_back (ptr_log); size_t idx = notifications.size () - 1; @@ -289,7 +288,7 @@ bool _app_notifyadd (HWND hwnd, PITEM_LOG const ptr_log, PITEM_APP const ptr_app return true; } -void _app_freenotify (size_t idx_orhash, bool is_idx) +void _app_freenotify (size_t idx_orhash, bool is_idx, bool is_refresh) { const size_t count = notifications.size (); @@ -298,26 +297,35 @@ void _app_freenotify (size_t idx_orhash, bool is_idx) if (is_idx) { - PITEM_LOG ptr_log = notifications.at (idx_orhash); + if (idx_orhash != LAST_VALUE) + { + PITEM_LOG ptr_log = notifications.at (idx_orhash); - SAFE_DELETE (ptr_log); + SAFE_DELETE (ptr_log); - notifications.erase (notifications.begin () + idx_orhash); + notifications.erase (notifications.begin () + idx_orhash); + } } else { - for (size_t i = (count - 1); i != LAST_VALUE; i--) + if (idx_orhash) { - PITEM_LOG ptr_log = notifications.at (i); - - if (!ptr_log || ptr_log->hash == idx_orhash) + for (size_t i = (count - 1); i != LAST_VALUE; i--) { - SAFE_DELETE (ptr_log); + PITEM_LOG ptr_log = notifications.at (i); - notifications.erase (notifications.begin () + i); + if (!ptr_log || ptr_log->hash == idx_orhash) + { + SAFE_DELETE (ptr_log); + + notifications.erase (notifications.begin () + i); + } } } } + + if (is_refresh) + _app_notifyrefresh (config.hnotification, true); } size_t _app_notifygetcurrent (HWND hwnd) @@ -345,15 +353,11 @@ size_t _app_notifygetcurrent (HWND hwnd) bool _app_notifyshow (HWND hwnd, size_t idx, bool is_forced, bool is_safety) { - _r_fastlock_acquireshared (&lock_notification); - if (!app.ConfigGet (L"IsNotificationsEnabled", true).AsBool () || notifications.empty () || idx == LAST_VALUE) { if (notifications.empty () || idx == LAST_VALUE) SetWindowLongPtr (hwnd, GWLP_USERDATA, LAST_VALUE); - _r_fastlock_releaseshared (&lock_notification); - return false; } @@ -372,8 +376,6 @@ bool _app_notifyshow (HWND hwnd, size_t idx, bool is_forced, bool is_safety) if (ptr_log) { - _r_fastlock_acquireshared (&lock_access); - PITEM_APP const ptr_app = _app_getapplication (ptr_log->hash); if (ptr_app) @@ -416,9 +418,6 @@ bool _app_notifyshow (HWND hwnd, size_t idx, bool is_forced, bool is_safety) _app_notifysetnote (hwnd, IDC_BLOCK_BTN, app.LocaleString (IDS_ACTION_BLOCK_HINT, nullptr)); _app_notifysetnote (hwnd, IDC_LATER_BTN, app.LocaleString (IDS_ACTION_LATER_HINT, nullptr)); - _r_fastlock_releaseshared (&lock_notification); - _r_fastlock_releaseshared (&lock_access); - _app_notifysetpos (hwnd); _r_ctrl_enable (hwnd, IDC_ALLOW_BTN, !is_safety); @@ -432,12 +431,8 @@ bool _app_notifyshow (HWND hwnd, size_t idx, bool is_forced, bool is_safety) return true; } - - _r_fastlock_releaseshared (&lock_access); } - _r_fastlock_releaseshared (&lock_notification); - return false; } @@ -494,21 +489,15 @@ bool _app_notifyrefresh (HWND hwnd, bool is_safety) return true; } - _r_fastlock_acquireshared (&lock_notification); + const size_t notify_idx = _app_notifygetcurrent (hwnd); - const size_t idx = _app_notifygetcurrent (hwnd); - - if (notifications.empty () || idx == LAST_VALUE || !IsWindowVisible (hwnd)) + if (!IsWindowVisible (hwnd) || notifications.empty () || notify_idx == LAST_VALUE) { _app_notifyhide (hwnd); - _r_fastlock_releaseshared (&lock_notification); - return false; } - _r_fastlock_releaseshared (&lock_notification); - - return _app_notifyshow (hwnd, idx, false, is_safety); + return _app_notifyshow (hwnd, notify_idx, false, is_safety); } void _app_notifysetpos (HWND hwnd) @@ -636,7 +625,8 @@ HFONT _app_notifyinitfont (PLOGFONT plf, LONG height, LONG weight, LPCWSTR name, //plf->lfCharSet = DEFAULT_CHARSET; //plf->lfQuality = DEFAULT_QUALITY; - StringCchCopy (plf->lfFaceName, LF_FACESIZE, name); + if (name) + StringCchCopy (plf->lfFaceName, LF_FACESIZE, name); return CreateFontIndirect (plf); } @@ -865,37 +855,46 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp ctrl_id == IDC_DATE_TEXT ) { - _r_fastlock_acquireshared (&lock_notification); - - const size_t idx = _app_notifygetcurrent (hwnd); - - if (idx != LAST_VALUE) + if (ctrl_id == IDC_RULES_BTN) { - PITEM_LOG const ptr_log = notifications.at (idx); - - if (ptr_log) + StringCchCopy (buffer, _countof (buffer), app.LocaleString (IDS_TRAY_RULES, nullptr)); + } + else if (ctrl_id == IDC_TIMER_BTN) + { + StringCchCopy (buffer, _countof (buffer), app.LocaleString (IDS_TIMER, nullptr)); + } + else if (ctrl_id == IDC_CLOSE_BTN) + { + StringCchCopy (buffer, _countof (buffer), app.LocaleString (IDS_CLOSE, nullptr)); + } + else if (ctrl_id == IDC_FILE_TEXT) + { + if (_r_fastlock_tryacquireshared (&lock_notification)) { - if (ctrl_id == IDC_RULES_BTN) - StringCchCopy (buffer, _countof (buffer), app.LocaleString (IDS_TRAY_RULES, nullptr)); + size_t app_hash = 0; + const size_t notify_idx = _app_notifygetcurrent (hwnd); - else if (ctrl_id == IDC_TIMER_BTN) - StringCchCopy (buffer, _countof (buffer), app.LocaleString (IDS_TIMER, nullptr)); + if (notify_idx != LAST_VALUE) + { + PITEM_LOG const ptr_log = notifications.at (notify_idx); - else if (ctrl_id == IDC_CLOSE_BTN) - StringCchCopy (buffer, _countof (buffer), app.LocaleString (IDS_CLOSE, nullptr)); + if (ptr_log) + app_hash = ptr_log->hash; + } - else if (ctrl_id == IDC_FILE_TEXT) - StringCchCopy (buffer, _countof (buffer), _app_gettooltip (IDC_APPS_PROFILE, ptr_log->hash)); + _r_fastlock_releaseshared (&lock_notification); - else - StringCchCopy (buffer, _countof (buffer), _r_ctrl_gettext (hwnd, ctrl_id)); + if (app_hash) + StringCchCopy (buffer, _countof (buffer), _app_gettooltip (IDC_APPS_PROFILE, app_hash)); } - - if (buffer[0]) - lpnmdi->lpszText = buffer; + } + else + { + StringCchCopy (buffer, _countof (buffer), _r_ctrl_gettext (hwnd, ctrl_id)); } - _r_fastlock_releaseshared (&lock_notification); + if (buffer[0]) + lpnmdi->lpszText = buffer; } } @@ -910,70 +909,85 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp { if ((LOWORD (wparam) >= IDX_RULES_SPECIAL && LOWORD (wparam) <= IDX_RULES_SPECIAL + rules_arr.size ())) { - size_t hash = 0; - - _r_fastlock_acquireexclusive (&lock_access); - const size_t rule_idx = (LOWORD (wparam) - IDX_RULES_SPECIAL); PITEM_RULE ptr_rule = rules_arr.at (rule_idx); - if (ptr_rule) + if (!ptr_rule) + return FALSE; + + _r_fastlock_acquireexclusive (&lock_notification); + + size_t app_hash = 0; + const size_t notify_idx = _app_notifygetcurrent (hwnd); + + if (notify_idx != LAST_VALUE) { - _r_fastlock_acquireshared (&lock_notification); + PITEM_LOG ptr_log = notifications.at (notify_idx); - const size_t notify_idx = _app_notifygetcurrent (hwnd); + if (ptr_log) + app_hash = ptr_log->hash; - if (notify_idx != LAST_VALUE) - { - hash = notifications.at (notify_idx)->hash; + _app_freenotify (notify_idx, true, false); - //if (ptr_rule->is_forservices && (app_hash == config.ntoskrnl_hash || app_hash == config.svchost_hash)) - // continue; + if (app_hash) + _app_freenotify (app_hash, false, false); - PITEM_APP ptr_app = _app_getapplication (hash); + _app_notifyrefresh (hwnd, true); + } - if (ptr_app) - { - const bool is_remove = ptr_rule->is_enabled && (ptr_rule->apps.find (hash) != ptr_rule->apps.end ()); + _r_fastlock_releaseexclusive (&lock_notification); - if (is_remove) - { - ptr_rule->apps.erase (hash); + if (!app_hash) + return false; - if (ptr_rule->apps.empty ()) - _app_ruleenable (ptr_rule, false); - } - else - { - ptr_rule->apps[hash] = true; + //if (ptr_rule->is_forservices && (app_hash == config.ntoskrnl_hash || app_hash == config.svchost_hash)) + // continue; - _app_ruleenable (ptr_rule, true); - } - } - } + const size_t item = _app_getposition (app.GetHWND (), app_hash); + PITEM_APP ptr_app = _app_getapplication (app_hash); - _r_fastlock_releaseshared (&lock_notification); + if (!ptr_app) + return false; - MFILTER_RULES rules; - rules.push_back (ptr_rule); + _r_fastlock_acquireexclusive (&lock_access); - _wfp_create4filters (&rules, __LINE__); + const UINT listview_id = _app_getlistview_id (ptr_app->type); + const bool is_remove = ptr_rule->is_enabled && (ptr_rule->apps.find (app_hash) != ptr_rule->apps.end ()); + + if (is_remove) + { + ptr_rule->apps.erase (app_hash); + + if (ptr_rule->apps.empty ()) + _app_ruleenable (ptr_rule, false); + } + else + { + ptr_rule->apps[app_hash] = true; + _app_ruleenable (ptr_rule, true); + } + + if (item != LAST_VALUE) + { + _r_fastlock_acquireshared (&lock_checkbox); + _app_setappiteminfo (app.GetHWND (), listview_id, item, app_hash, ptr_app); + _r_fastlock_releaseshared (&lock_checkbox); } _r_fastlock_releaseexclusive (&lock_access); - _r_fastlock_acquireexclusive (&lock_notification); + MFILTER_RULES rules; + rules.push_back (ptr_rule); - _app_freenotify (hash, false); + _wfp_create4filters (&rules, __LINE__); - _r_fastlock_releaseexclusive (&lock_notification); + if (_app_gettab_id (app.GetHWND ()) == listview_id) + { + _app_listviewsort (app.GetHWND (), listview_id); + _r_listview_redraw (app.GetHWND (), listview_id); + } - _app_notifyrefresh (hwnd, true); - - _app_listviewsort (app.GetHWND (), IDC_APPS_PROFILE); - _app_profile_save (app.GetHWND ()); - - _r_listview_redraw (app.GetHWND (), IDC_APPS_PROFILE); + _app_profile_save (); return FALSE; } @@ -985,7 +999,7 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp return FALSE; } - else if ((LOWORD (wparam) >= IDX_NOTIFICATIONS && LOWORD (wparam) <= IDX_NOTIFICATIONS + timers.size ())) + else if ((LOWORD (wparam) >= IDX_NOTIFICATIONS && LOWORD (wparam) <= IDX_NOTIFICATIONS + notifications.size ())) { const size_t idx = (LOWORD (wparam) - IDX_NOTIFICATIONS); @@ -1000,17 +1014,28 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp { _r_fastlock_acquireshared (&lock_notification); - const size_t idx = _app_notifygetcurrent (hwnd); + size_t app_hash = 0; + const size_t notify_idx = _app_notifygetcurrent (hwnd); - if (idx != LAST_VALUE) + if (notify_idx != LAST_VALUE) { - _app_showitem (app.GetHWND (), _app_getapplistview_id (notifications.at (idx)->hash), notifications.at (idx)->hash); + PITEM_LOG ptr_log = notifications.at (notify_idx); - _r_wnd_toggle (app.GetHWND (), true); + if (ptr_log) + app_hash = ptr_log->hash; } _r_fastlock_releaseshared (&lock_notification); + const PITEM_APP ptr_app = _app_getapplication (app_hash); + + if (ptr_app) + { + _app_showitem (app.GetHWND (), _app_getlistview_id (ptr_app->type), app_hash); + + _r_wnd_toggle (app.GetHWND (), true); + } + break; } @@ -1053,12 +1078,12 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp { _r_fastlock_acquireshared (&lock_notification); - const size_t idx = _app_notifygetcurrent (hwnd); + const size_t notify_idx = _app_notifygetcurrent (hwnd); size_t app_hash = 0; - if (idx != LAST_VALUE) + if (notify_idx != LAST_VALUE) { - PITEM_LOG const ptr_log = notifications.at (idx); + PITEM_LOG const ptr_log = notifications.at (notify_idx); if (ptr_log) app_hash = ptr_log->hash; @@ -1079,6 +1104,7 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp for (size_t i = 0; i < timers.size (); i++) AppendMenu (hsubmenu, MF_BYPOSITION, IDX_TIMER + UINT (i), _r_fmt_interval (timers.at (i) + 1, 1)); } + RECT buttonRect = {0}; GetClientRect (hctrl, &buttonRect); @@ -1108,7 +1134,7 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp case IDM_EDITRULES: { - _app_settab_id (hwnd, IDC_RULES_CUSTOM); + _app_settab_id (app.GetHWND (), _app_getlistview_id (DataRuleCustom)); break; } @@ -1116,70 +1142,65 @@ LRESULT CALLBACK NotificationProc (HWND hwnd, UINT msg, WPARAM wparam, LPARAM lp { PITEM_RULE ptr_rule = new ITEM_RULE; - if (ptr_rule) + _r_fastlock_acquireexclusive (&lock_notification); + + const size_t notify_idx = _app_notifygetcurrent (hwnd); + size_t app_hash = 0; + + if (notify_idx != LAST_VALUE) { - _r_fastlock_acquireshared (&lock_notification); + const PITEM_LOG ptr_log = notifications.at (notify_idx); - const size_t idx = _app_notifygetcurrent (hwnd); - size_t hash = 0; - - if (idx != LAST_VALUE) + if (ptr_log) { - PITEM_LOG const ptr_log = notifications.at (idx); + ptr_rule->apps[ptr_log->hash] = true; + ptr_rule->protocol = ptr_log->protocol; + app_hash = ptr_log->hash; - if (ptr_log) + LPWSTR rule = nullptr; + + if (_app_formataddress (ptr_log->af, &ptr_log->remote_addr, ptr_log->remote_port, &rule, false)) { - ptr_rule->apps[ptr_log->hash] = true; - ptr_rule->protocol = ptr_log->protocol; - hash = ptr_log->hash; - - LPWSTR rule = nullptr; - _app_formataddress (ptr_log->af, &ptr_log->remote_addr, ptr_log->remote_port, &rule, false); - _r_str_alloc (&ptr_rule->pname, _r_str_length (rule), rule); _r_str_alloc (&ptr_rule->prule_remote, _r_str_length (rule), rule); - - SAFE_DELETE_ARRAY (rule); } + + SAFE_DELETE_ARRAY (rule); } - _r_fastlock_releaseshared (&lock_notification); + _app_freenotify (notify_idx, true, false); - _app_ruleenable (ptr_rule, true); + if (app_hash) + _app_freenotify (app_hash, false, false); - ptr_rule->type = TypeCustom; - ptr_rule->is_block = false; + _app_notifyrefresh (hwnd, true); + } - if (DialogBoxParam (nullptr, MAKEINTRESOURCE (IDD_EDITOR), app.GetHWND (), &EditorProc, (LPARAM)ptr_rule)) - { - _r_fastlock_acquireexclusive (&lock_access); + _r_fastlock_releaseexclusive (&lock_notification); - rules_arr.push_back (ptr_rule); + ptr_rule->type = DataRuleCustom; + ptr_rule->is_block = false; - MFILTER_RULES rules; - rules.push_back (ptr_rule); + _app_ruleenable (ptr_rule, true); - _wfp_create4filters (&rules, __LINE__); + if (DialogBoxParam (nullptr, MAKEINTRESOURCE (IDD_EDITOR), app.GetHWND (), &EditorProc, (LPARAM)ptr_rule)) + { + _r_fastlock_acquireexclusive (&lock_access); + rules_arr.push_back (ptr_rule); + _r_fastlock_releaseexclusive (&lock_access); - _r_fastlock_releaseexclusive (&lock_access); + const UINT listview_id = _app_gettab_id (app.GetHWND ()); - _app_listviewsort (hwnd, IDC_APPS_PROFILE); - _app_profile_save (hwnd); + _r_listview_redraw (app.GetHWND (), listview_id); - _r_listview_redraw (hwnd, IDC_APPS_PROFILE); + _app_listviewsort (app.GetHWND (), listview_id); + _app_profile_save (); - _r_fastlock_acquireexclusive (&lock_notification); - - _app_freenotify (hash, false); - - _r_fastlock_releaseexclusive (&lock_notification); - - _app_notifyrefresh (hwnd, true); - } - else - { - _app_freerule (&ptr_rule); - } + _app_refreshstatus (app.GetHWND ()); + } + else + { + _app_freerule (&ptr_rule); } break; diff --git a/src/notifications.hpp b/src/notifications.hpp index 636bc7c9..e1639dc8 100644 --- a/src/notifications.hpp +++ b/src/notifications.hpp @@ -7,7 +7,7 @@ void _app_notifycreatewindow (); bool _app_notifycommand (HWND hwnd, UINT ctrl_id, size_t timer_idx); bool _app_notifyadd (HWND hwnd, PITEM_LOG const ptr_log, PITEM_APP const ptr_app); -void _app_freenotify (size_t idx_orhash, bool is_idx); +void _app_freenotify (size_t idx_orhash, bool is_idx, bool is_refresh); size_t _app_notifygetcurrent (HWND hwnd); bool _app_notifyshow (HWND hwnd, size_t idx, bool is_forced, bool is_safety); diff --git a/src/profile.cpp b/src/profile.cpp index a403a153..4603e0bc 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -22,14 +22,14 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t ti _app_resolvefilename (path); - const size_t hash = path.Hash (); + const size_t app_hash = path.Hash (); - if (apps.find (hash) != apps.end ()) - return hash; // already exists + if (apps.find (app_hash) != apps.end ()) + return app_hash; // already exists - ITEM_APP * ptr_app = &apps[hash]; // application pointer + ITEM_APP * ptr_app = &apps[app_hash]; // application pointer - const bool is_ntoskrnl = (hash == config.ntoskrnl_hash); + const bool is_ntoskrnl = (app_hash == config.ntoskrnl_hash); const time_t current_time = _r_unixtime_now (); rstring real_path; @@ -38,19 +38,19 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t ti { real_path = path; - ptr_app->type = AppDevice; + ptr_app->type = DataAppDevice; } else if (_wcsnicmp (path, L"S-1-", 4) == 0) // windows store (win8+) { - ptr_app->type = AppPackage; + ptr_app->type = DataAppPackage; - _app_item_get (AppPackage, hash, nullptr, &real_path, &ptr_app->psid, nullptr, nullptr); + _app_item_get (DataAppPackage, app_hash, nullptr, &real_path, &ptr_app->psid, nullptr, nullptr); } else if (PathIsNetworkPath (path)) // network path { real_path = path; - ptr_app->type = AppNetwork; + ptr_app->type = DataAppNetwork; } else { @@ -58,18 +58,15 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t ti if (!is_ntoskrnl && real_path.Find (OBJ_NAME_PATH_SEPARATOR) == rstring::npos) { - if (_app_item_get (AppService, hash, nullptr, &real_path, nullptr, &ptr_app->psd, nullptr)) - { - ptr_app->type = AppService; - } + if (_app_item_get (DataAppService, app_hash, nullptr, &real_path, nullptr, &ptr_app->psd, nullptr)) + ptr_app->type = DataAppService; + else - { - ptr_app->type = AppPico; - } + ptr_app->type = DataAppPico; } else { - ptr_app->type = AppRegular; + ptr_app->type = DataAppRegular; if (is_ntoskrnl) // "system" process { @@ -87,7 +84,7 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t ti ptr_app->is_temp = ((dwAttr != INVALID_FILE_ATTRIBUTES && (dwAttr & FILE_ATTRIBUTE_TEMPORARY) != 0)) || (_wcsnicmp (real_path, config.tmp1_dir, config.tmp1_length) == 0); ptr_app->is_system = !ptr_app->is_temp && (is_ntoskrnl || ((dwAttr != INVALID_FILE_ATTRIBUTES && (dwAttr & FILE_ATTRIBUTE_SYSTEM) != 0)) || (_wcsnicmp (real_path, config.windows_dir, config.wd_length) == 0)); - ptr_app->is_signed = _app_getsignatureinfo (hash, real_path, &ptr_app->signer); + ptr_app->is_signed = _app_getsignatureinfo (app_hash, real_path, &ptr_app->signer); } _app_applycasestyle (real_path.GetBuffer (), real_path.GetLength ()); // apply case-style @@ -96,8 +93,7 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t ti _r_str_alloc (&ptr_app->original_path, path.GetLength (), path); _r_str_alloc (&ptr_app->real_path, real_path.GetLength (), real_path); - _app_getdisplayname (hash, ptr_app, &ptr_app->display_name); - _app_getappicon (ptr_app, true, &ptr_app->icon_id, nullptr); + _app_getdisplayname (app_hash, ptr_app, &ptr_app->display_name); ptr_app->is_enabled = is_enabled; ptr_app->is_silent = is_silent; @@ -105,12 +101,15 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t ti ptr_app->timestamp = timestamp ? timestamp : current_time; ptr_app->last_notify = last_notify; + if (ptr_app->type == DataAppService || ptr_app->type == DataAppPackage) + ptr_app->is_undeletable = true; + // install timer if (timer) { if (timer > current_time) { - if (!ptr_app->htimer && CreateTimerQueueTimer (&ptr_app->htimer, config.htimer, &_app_timer_callback, (PVOID)hash, DWORD ((timer - current_time) * _R_SECONDSCLOCK_MSEC), 0, WT_EXECUTEONLYONCE | WT_EXECUTEINTIMERTHREAD)) + if (!ptr_app->htimer && CreateTimerQueueTimer (&ptr_app->htimer, config.htimer, &_app_timer_callback, (PVOID)app_hash, DWORD ((timer - current_time) * _R_SECONDSCLOCK_MSEC), 0, WT_EXECUTEONLYONCE | WT_EXECUTEINTIMERTHREAD)) { ptr_app->is_enabled = true; ptr_app->timer = timer; @@ -124,20 +123,22 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t ti if (hwnd) { - const UINT listview_id = _app_getapplistview_id (hash); - const size_t item = _r_listview_getitemcount (hwnd, listview_id); + const UINT listview_id = _app_getlistview_id (ptr_app->type); - _r_fastlock_acquireshared (&lock_checkbox); + if (listview_id) + { + const size_t item = _r_listview_getitemcount (hwnd, listview_id); - _r_listview_additem (hwnd, listview_id, item, 0, ptr_app->display_name, ptr_app->icon_id, _app_getappgroup (hash, ptr_app), hash); - _r_listview_setitem (hwnd, listview_id, item, 1, _r_fmt_date (ptr_app->timestamp, FDTF_SHORTDATE | FDTF_SHORTTIME)); + _r_fastlock_acquireshared (&lock_checkbox); - _r_listview_setitemcheck (hwnd, listview_id, item, is_enabled); + _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); + } } - return hash; + return app_hash; } PITEM_APP _app_getapplication (size_t hash) @@ -148,23 +149,23 @@ PITEM_APP _app_getapplication (size_t hash) return nullptr; } -PITEM_RULE _app_getrule (size_t hash, EnumRuleType type, BOOL is_readonly) +PITEM_RULE _app_getrule (size_t hash, EnumDataType type, BOOL is_readonly) { if (!hash) return nullptr; for (size_t i = 0; i < rules_arr.size (); i++) { - PITEM_RULE ptr_rule = rules_arr.at (i); + const PITEM_RULE ptr_rule = rules_arr.at (i); - if (ptr_rule && ptr_rule->type == type) - { - if (is_readonly != -1 && ((BOOL)ptr_rule->is_readonly != (is_readonly))) - continue; + if (!ptr_rule || ptr_rule->type != type) + continue; - if (ptr_rule->pname && _r_str_hash (ptr_rule->pname) == hash) - return ptr_rule; - } + if (is_readonly != -1 && ((BOOL)ptr_rule->is_readonly != (is_readonly))) + continue; + + if (ptr_rule->pname && _r_str_hash (ptr_rule->pname) == hash) + return ptr_rule; } return nullptr; @@ -217,7 +218,7 @@ bool _app_freeapplication (size_t hash) if (ptr_rule) { - if (ptr_rule->type != TypeCustom) + if (ptr_rule->type != DataRuleCustom) continue; if (ptr_rule->apps.find (hash) != ptr_rule->apps.end ()) @@ -237,16 +238,11 @@ bool _app_freeapplication (size_t hash) } _r_fastlock_acquireexclusive (&lock_notification); - _app_freenotify (hash, false); + _app_freenotify (hash, false, true); _r_fastlock_releaseexclusive (&lock_notification); if (ptr_app && ptr_app->htimer) - { - if (DeleteTimerQueueTimer (config.htimer, ptr_app->htimer, nullptr)) - ptr_app->htimer = nullptr; - } - - _app_notifyrefresh (config.hnotification, false); + DeleteTimerQueueTimer (config.htimer, ptr_app->htimer, nullptr); apps.erase (hash); } @@ -281,7 +277,7 @@ void _app_getcount (PITEM_STATUS ptr_status) if (_app_istimeractive (ptr_app)) ptr_status->apps_timer_count += 1; - if (!ptr_app->is_undeletable && (!_app_isappexists (ptr_app) || !is_used) && !(ptr_app->type == AppService || ptr_app->type == AppPackage)) + if (!ptr_app->is_undeletable && (!_app_isappexists (ptr_app) || !is_used) && !(ptr_app->type == DataAppService || ptr_app->type == DataAppPackage)) ptr_status->apps_unused_count += 1; if (is_used) @@ -292,7 +288,7 @@ void _app_getcount (PITEM_STATUS ptr_status) { const PITEM_RULE ptr_rule = rules_arr.at (i); - if (!ptr_rule || ptr_rule->type != TypeCustom) + if (!ptr_rule || ptr_rule->type != DataRuleCustom) continue; if (ptr_rule->is_enabled && !ptr_rule->apps.empty ()) @@ -349,8 +345,6 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) { rstring result; - _r_fastlock_acquireshared (&lock_access); - if (listview_id == IDC_NETWORK) { return _app_gettooltip (IDC_APPS_PROFILE, network_arr.at (idx)->hash); @@ -369,7 +363,7 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) result = (ptr_app->real_path && ptr_app->real_path[0]) ? ptr_app->real_path : ((ptr_app->display_name && ptr_app->display_name[0]) ? ptr_app->display_name : ptr_app->original_path); // file information - if (ptr_app->type == AppRegular) + if (ptr_app->type == DataAppRegular) { rstring display_name; @@ -381,14 +375,14 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) result.AppendFormat (L"\r\n%s:\r\n" SZ_TAB L"%s" SZ_TAB, app.LocaleString (IDS_FILE, nullptr).GetString (), display_name.GetString ()); } } - else if (ptr_app->type == AppService) + else if (ptr_app->type == DataAppService) { rstring display_name; if (_app_item_get (ptr_app->type, idx, &display_name, nullptr, nullptr, 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 == AppPackage) + else if (ptr_app->type == DataAppPackage) { rstring display_name; @@ -419,16 +413,16 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) // app type { - if (ptr_app->type == AppNetwork) + if (ptr_app->type == DataAppNetwork) buffer.AppendFormat (SZ_TAB L"%s\r\n", app.LocaleString (IDS_HIGHLIGHT_NETWORK, nullptr).GetString ()); - else if (ptr_app->type == AppPico) + else if (ptr_app->type == DataAppPico) buffer.AppendFormat (SZ_TAB L"%s\r\n", app.LocaleString (IDS_HIGHLIGHT_PICO, nullptr).GetString ()); - else if (ptr_app->type == AppPackage) + else if (ptr_app->type == DataAppPackage) buffer.AppendFormat (SZ_TAB L"%s\r\n", app.LocaleString (IDS_HIGHLIGHT_PACKAGE, nullptr).GetString ()); - else if (ptr_app->type == AppService) + else if (ptr_app->type == DataAppService) buffer.AppendFormat (SZ_TAB L"%s\r\n", app.LocaleString (IDS_HIGHLIGHT_SERVICE, nullptr).GetString ()); } @@ -463,24 +457,38 @@ rstring _app_gettooltip (UINT listview_id, size_t idx) } } - _r_fastlock_releaseshared (&lock_access); - return result; } -void _app_setruleitem (HWND hwnd, UINT listview_id, size_t item, PITEM_RULE ptr_rule) +void _app_setappiteminfo (HWND hwnd, UINT listview_id, size_t item, size_t app_hash, PITEM_APP ptr_app) { - _r_listview_setitem (hwnd, listview_id, item, 0, ptr_rule->type == TypeCustom && ptr_rule->is_readonly ? _r_fmt (L"%s*", ptr_rule->pname) : ptr_rule->pname, _app_getruleicon (ptr_rule), _app_getrulegroup (ptr_rule)); + if (!ptr_app || !listview_id) + return; + + _app_getappicon (ptr_app, true, &ptr_app->icon_id, nullptr); + + _r_listview_setitem (hwnd, listview_id, item, 0, ptr_app->display_name, ptr_app->icon_id, _app_getappgroup (app_hash, ptr_app)); + _r_listview_setitem (hwnd, listview_id, item, 1, _r_fmt_date (ptr_app->timestamp, FDTF_SHORTDATE | FDTF_SHORTTIME)); + + _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) +{ + if (!ptr_rule || !listview_id) + return; + + _r_listview_setitem (hwnd, listview_id, item, 0, ptr_rule->type == DataRuleCustom && ptr_rule->is_readonly ? _r_fmt (L"%s*", ptr_rule->pname) : ptr_rule->pname, _app_getruleicon (ptr_rule), _app_getrulegroup (ptr_rule)); _r_listview_setitem (hwnd, listview_id, item, 1, app.LocaleString (IDS_DIRECTION_1 + ptr_rule->dir, nullptr)); _r_listview_setitem (hwnd, listview_id, item, 2, ptr_rule->protocol ? _app_getprotoname (ptr_rule->protocol) : app.LocaleString (IDS_ALL, nullptr)); _r_listview_setitemcheck (hwnd, listview_id, item, ptr_rule->is_enabled); } -bool _app_ruleenable (PITEM_RULE ptr_rule, bool is_enable) +void _app_ruleenable (PITEM_RULE ptr_rule, bool is_enable) { if (!ptr_rule) - return false; + return; ptr_rule->is_enabled = is_enable; @@ -491,8 +499,6 @@ bool _app_ruleenable (PITEM_RULE ptr_rule, bool is_enable) if (rules_config.find (hash) != rules_config.end ()) rules_config[hash]->is_enabled = is_enable; } - - return true; } rstring _app_rulesexpand (PITEM_RULE const ptr_rule, bool is_forservices, LPCWSTR delimeter) @@ -518,7 +524,7 @@ rstring _app_rulesexpand (PITEM_RULE const ptr_rule, bool is_forservices, LPCWST if (ptr_app) { - if (ptr_app->type == AppPackage || ptr_app->type == AppService) + if (ptr_app->type == DataAppPackage || ptr_app->type == DataAppService) { if (ptr_app->display_name && ptr_app->display_name[0]) result.Append (ptr_app->display_name); @@ -590,10 +596,13 @@ bool _app_isappexists (ITEM_APP const *ptr_app) if (ptr_app->is_enabled && ptr_app->is_haveerrors) return false; - if (ptr_app->type == AppRegular) + if (ptr_app->type == DataAppDevice || ptr_app->type == DataAppNetwork || ptr_app->type == DataAppPico) + return true; + + else if (ptr_app->type == DataAppRegular) return ptr_app->real_path && ptr_app->real_path[0] && _r_fs_exists (ptr_app->real_path); - else if (ptr_app->type == AppService || ptr_app->type == AppPackage) + else if (ptr_app->type == DataAppService || ptr_app->type == DataAppPackage) return _app_item_get (ptr_app->type, _r_str_hash (ptr_app->original_path), nullptr, nullptr, nullptr, nullptr, nullptr); return true; @@ -665,7 +674,7 @@ bool _app_isrulepresent (size_t hash) return false; } -void _app_profile_loadrules (MFILTER_RULES * ptr_rules, LPCWSTR path, LPCWSTR path_backup, bool is_internal, EnumRuleType type, UINT8 weight, time_t * ptimestamp) +void _app_profile_loadrules (MFILTER_RULES * ptr_rules, LPCWSTR path, LPCWSTR path_backup, bool is_internal, EnumDataType type, UINT8 weight, time_t * ptimestamp) { if (!ptr_rules) return; @@ -746,22 +755,14 @@ void _app_profile_loadrules (MFILTER_RULES * ptr_rules, LPCWSTR path, LPCWSTR pa ptr_rule->protocol = (UINT8)item.attribute (L"protocol").as_uint (); ptr_rule->af = (ADDRESS_FAMILY)item.attribute (L"version").as_uint (); - ptr_rule->type = item.attribute (L"is_custom").as_bool () ? TypeCustom : type; + ptr_rule->type = item.attribute (L"is_custom").as_bool () ? DataRuleCustom : type; ptr_rule->is_block = item.attribute (L"is_block").as_bool (); ptr_rule->is_forservices = item.attribute (L"is_services").as_bool (); - ptr_rule->is_readonly = (type != TypeCustom); + ptr_rule->is_readonly = (type != DataRuleCustom); + ptr_rule->weight = (type == DataRuleCustom && ptr_rule->is_block) ? FILTER_WEIGHT_CUSTOM_BLOCK : weight; // calculate rule weight ptr_rule->is_enabled = item.attribute (L"is_enabled").as_bool (); - // calculate rule weight - { - if (type == TypeCustom && item.attribute (L"is_block").as_bool ()) - ptr_rule->weight = FILTER_WEIGHT_CUSTOM_BLOCK; - - else - ptr_rule->weight = weight; - } - if (is_internal) { // internal rules @@ -820,7 +821,7 @@ void _app_profile_loadrules (MFILTER_RULES * ptr_rules, LPCWSTR path, LPCWSTR pa if (!_app_getapplication (app_hash)) app_hash = _app_addapplication (nullptr, app_path, 0, 0, 0, false, false, true); - if (ptr_rule->type == TypeBlocklist || ptr_rule->type == TypeSystem) + if (ptr_rule->type == DataRuleBlocklist || ptr_rule->type == DataRuleSystem) apps[app_hash].is_undeletable = true; ptr_rule->apps[app_hash] = true; @@ -931,7 +932,7 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_apps, LPCWSTR path_rules) const PITEM_ADD ptr_item = items.at (i); if (ptr_item) - _app_addapplication (nullptr, ptr_item->type == AppService ? ptr_item->service_name : ptr_item->sid, ptr_item->timestamp, 0, 0, false, false, true); + _app_addapplication (nullptr, ptr_item->type == DataAppService ? ptr_item->service_name : ptr_item->sid, ptr_item->timestamp, 0, 0, false, false, true); } } @@ -998,34 +999,35 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_apps, LPCWSTR path_rules) } // load blocklist rules (internal) - _app_profile_loadrules (&rules_arr, config.rules_blocklist_path, MAKEINTRESOURCE (IDR_RULES_BLOCKLIST), true, TypeBlocklist, FILTER_WEIGHT_BLOCKLIST, &config.blocklist_timestamp); + _app_profile_loadrules (&rules_arr, config.rules_blocklist_path, MAKEINTRESOURCE (IDR_RULES_BLOCKLIST), true, DataRuleBlocklist, FILTER_WEIGHT_BLOCKLIST, &config.blocklist_timestamp); // load system rules (internal) - _app_profile_loadrules (&rules_arr, config.rules_system_path, MAKEINTRESOURCE (IDR_RULES_SYSTEM), true, TypeSystem, FILTER_WEIGHT_SYSTEM, &config.rule_system_timestamp); + _app_profile_loadrules (&rules_arr, config.rules_system_path, MAKEINTRESOURCE (IDR_RULES_SYSTEM), true, DataRuleSystem, FILTER_WEIGHT_SYSTEM, &config.rule_system_timestamp); // load user rules - _app_profile_loadrules (&rules_arr, path_rules ? path_rules : config.rules_custom_path, config.rules_custom_path_backup, false, TypeCustom, FILTER_WEIGHT_CUSTOM, nullptr); + _app_profile_loadrules (&rules_arr, path_rules ? path_rules : config.rules_custom_path, config.rules_custom_path_backup, false, DataRuleCustom, FILTER_WEIGHT_CUSTOM, nullptr); _r_fastlock_releaseexclusive (&lock_access); if (hwnd) { _r_fastlock_acquireshared (&lock_access); - _r_fastlock_acquireshared (&lock_checkbox); // add apps for (auto &p : apps) { - const size_t hash = p.first; + const size_t app_hash = p.first; const PITEM_APP ptr_app = &p.second; - const UINT ctrl_id = _app_getapplistview_id (hash); + const UINT ctrl_id = _app_getlistview_id (ptr_app->type); const size_t item = _r_listview_getitemcount (hwnd, ctrl_id); - _r_listview_additem (hwnd, ctrl_id, item, 0, ptr_app->display_name, ptr_app->icon_id, _app_getappgroup (hash, ptr_app), hash); - _r_listview_setitem (hwnd, ctrl_id, item, 1, _r_fmt_date (ptr_app->timestamp, FDTF_SHORTDATE | FDTF_SHORTTIME)); + _r_fastlock_acquireshared (&lock_checkbox); - _r_listview_setitemcheck (hwnd, ctrl_id, item, ptr_app->is_enabled); + _r_listview_additem (hwnd, ctrl_id, item, 0, ptr_app->display_name, ptr_app->icon_id, _app_getappgroup (app_hash, ptr_app), app_hash); + _app_setappiteminfo (hwnd, ctrl_id, item, app_hash, ptr_app); + + _r_fastlock_releaseshared (&lock_checkbox); } // add rules @@ -1036,14 +1038,17 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_apps, LPCWSTR path_rules) if (!ptr_rule) continue; - const UINT ctrl_id = _app_getrulelistview_id (ptr_rule); + const UINT ctrl_id = _app_getlistview_id (ptr_rule->type); const size_t item = _r_listview_getitemcount (hwnd, ctrl_id); + _r_fastlock_acquireshared (&lock_checkbox); + _r_listview_additem (hwnd, ctrl_id, item, 0, ptr_rule->pname, _app_getruleicon (ptr_rule), _app_getrulegroup (ptr_rule), i); - _app_setruleitem (hwnd, ctrl_id, item, ptr_rule); + _app_setruleiteminfo (hwnd, ctrl_id, item, ptr_rule); + + _r_fastlock_releaseshared (&lock_checkbox); } - _r_fastlock_releaseshared (&lock_checkbox); _r_fastlock_releaseshared (&lock_access); } @@ -1061,8 +1066,6 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_apps, LPCWSTR path_rules) if (hwnd) { - _r_fastlock_acquireshared (&lock_checkbox); - for (size_t i = 0; i < network_arr.size (); i++) { const PITEM_NETWORK ptr_network = network_arr.at (i); @@ -1078,37 +1081,27 @@ void _app_profile_load (HWND hwnd, LPCWSTR path_apps, LPCWSTR path_rules) _app_formataddress (ptr_network->af, &ptr_network->remote_addr, ptr_network->remote_port, &ptr_network->remote_fmt, false); _r_listview_additem (hwnd, IDC_NETWORK, i, 0, _r_path_extractfile (ptr_network->path), ptr_network->icon_id, LAST_VALUE, i); + _r_listview_setitem (hwnd, IDC_NETWORK, i, 1, ptr_network->local_fmt); _r_listview_setitem (hwnd, IDC_NETWORK, i, 2, ptr_network->remote_fmt); _r_listview_setitem (hwnd, IDC_NETWORK, i, 3, _app_getprotoname (ptr_network->protocol)); + _r_listview_setitem (hwnd, IDC_NETWORK, i, 4, _app_getstatename (ptr_network->state)); } - - _r_fastlock_releaseshared (&lock_checkbox); } _r_fastlock_releaseexclusive (&lock_network); if (hwnd) - { - _app_listviewsort (hwnd, listview_id); - _r_listview_redraw (hwnd, listview_id); - _app_showitem (hwnd, listview_id, lparam, scroll_pos); - } - - if (hwnd) - _app_refreshstatus (hwnd); } -void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) +void _app_profile_save (LPCWSTR path_apps, LPCWSTR path_rules) { const time_t current_time = _r_unixtime_now (); const bool is_backuprequired = app.ConfigGet (L"IsBackupProfile", true).AsBool () && (((current_time - app.ConfigGet (L"BackupTimestamp", 0).AsLonglong ()) >= app.ConfigGet (L"BackupPeriod", _R_SECONDSCLOCK_HOUR (BACKUP_HOURS_PERIOD)).AsLonglong ()) || !_r_fs_exists (config.apps_path_backup) || !_r_fs_exists (config.rules_custom_path_backup) || !_r_fs_exists (config.rules_config_path_backup)); bool is_backupcreated = false; - _r_fastlock_acquireshared (&lock_access); - // save apps { pugi::xml_document doc; @@ -1119,6 +1112,8 @@ void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) root.append_attribute (L"timestamp").set_value (current_time); root.append_attribute (L"type").set_value (XmlApps); + _r_fastlock_acquireshared (&lock_access); + for (auto &p : apps) { PITEM_APP const ptr_app = &p.second; @@ -1128,7 +1123,7 @@ void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) const bool is_used = _app_isappused (ptr_app, p.first); - if (!is_used && (ptr_app->type == AppService || ptr_app->type == AppPackage)) + if (!is_used && (ptr_app->type == DataAppService || ptr_app->type == DataAppPackage)) continue; pugi::xml_node item = root.append_child (L"item"); @@ -1156,6 +1151,8 @@ void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) } } + _r_fastlock_releaseshared (&lock_access); + doc.save_file (path_apps ? path_apps : config.apps_path, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); // make backup @@ -1177,9 +1174,16 @@ void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) root.append_attribute (L"timestamp").set_value (current_time); root.append_attribute (L"type").set_value (XmlRulesConfig); + _r_fastlock_acquireshared (&lock_access); + for (auto const &p : rules_config) { - const size_t hash = _r_str_hash (p.second->pname); + const PITEM_RULE_CONFIG ptr_config = p.second; + + if (!ptr_config || !ptr_config->pname) + continue; + + const size_t hash = _r_str_hash (ptr_config->pname); if (!_app_isrulepresent (hash)) continue; @@ -1191,7 +1195,7 @@ void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) item.append_attribute (L"name").set_value (p.second->pname); // save apps - const PITEM_RULE ptr_rule = _app_getrule (hash, TypeCustom, true); + const PITEM_RULE ptr_rule = _app_getrule (hash, DataRuleCustom, true); if (ptr_rule && !ptr_rule->apps.empty ()) { @@ -1206,6 +1210,8 @@ void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) } } + _r_fastlock_releaseshared (&lock_access); + doc.save_file (config.rules_config_path, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); // make backup @@ -1229,11 +1235,13 @@ void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) size_t rules_count = 0; + _r_fastlock_acquireshared (&lock_access); + for (size_t i = 0; i < rules_arr.size (); i++) { - PITEM_RULE const ptr_rule = rules_arr.at (i); + const PITEM_RULE ptr_rule = rules_arr.at (i); - if (!ptr_rule || ptr_rule->is_readonly) + if (!ptr_rule || ptr_rule->is_readonly || !ptr_rule->pname) continue; pugi::xml_node item = root.append_child (L"item"); @@ -1272,8 +1280,7 @@ void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) arr.Append (_r_path_unexpand (ptr_app->original_path)); arr.Append (RULE_DELIMETER); - if (!is_haveapps) - is_haveapps = true; + is_haveapps = true; } } @@ -1291,6 +1298,8 @@ void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) } } + _r_fastlock_releaseshared (&lock_access); + doc.save_file (path_rules ? path_rules : config.rules_custom_path, L"\t", PUGIXML_SAVE_FLAGS, PUGIXML_SAVE_ENCODING); // make backup @@ -1302,8 +1311,6 @@ void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps, LPCWSTR path_rules) } } - _r_fastlock_releaseshared (&lock_access); - if (is_backupcreated) app.ConfigSet (L"BackupTimestamp", current_time); } diff --git a/src/profile.hpp b/src/profile.hpp index 2cc514cd..75325c09 100644 --- a/src/profile.hpp +++ b/src/profile.hpp @@ -6,7 +6,7 @@ size_t _app_addapplication (HWND hwnd, rstring path, time_t timestamp, time_t timer, time_t last_notify, bool is_silent, bool is_enabled, bool is_fromdb); PITEM_APP _app_getapplication (size_t hash); -PITEM_RULE _app_getrule (size_t hash, EnumRuleType type, BOOL is_readonly); +PITEM_RULE _app_getrule (size_t hash, EnumDataType type, BOOL is_readonly); bool _app_freeapplication (size_t hash); void _app_freerule (PITEM_RULE* ptr); @@ -18,9 +18,11 @@ size_t _app_getrulegroup (PITEM_RULE const ptr_rule); size_t _app_getruleicon (PITEM_RULE const ptr_rule); rstring _app_gettooltip (UINT listview_id, size_t idx); -void _app_setruleitem (HWND hwnd, UINT listview_id, size_t item, PITEM_RULE ptr_rule); -bool _app_ruleenable (PITEM_RULE ptr_rule, bool is_enable); +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); + +void _app_ruleenable (PITEM_RULE ptr_rule, bool is_enable); rstring _app_rulesexpand (PITEM_RULE const ptr_rule, bool is_forservices, LPCWSTR delimeter); bool _app_isapphaveconnection (size_t hash); @@ -34,7 +36,7 @@ bool _app_isruleport (LPCWSTR rule); bool _app_isrulepresent (size_t hash); -void _app_profile_loadrules (MFILTER_RULES *ptr_rules, LPCWSTR path, LPCWSTR path_backup, bool is_internal, EnumRuleType type, UINT8 weight, time_t *ptimestamp); +void _app_profile_loadrules (MFILTER_RULES *ptr_rules, LPCWSTR path, LPCWSTR path_backup, bool is_internal, EnumDataType type, UINT8 weight, time_t *ptimestamp); void _app_profile_load (HWND hwnd, LPCWSTR path_apps = nullptr, LPCWSTR path_rules = nullptr); -void _app_profile_save (HWND /*hwnd*/, LPCWSTR path_apps = nullptr, LPCWSTR path_rules = nullptr); +void _app_profile_save (LPCWSTR path_apps = nullptr, LPCWSTR path_rules = nullptr); diff --git a/src/timer.cpp b/src/timer.cpp index bebbb6ed..08c7afdc 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -10,6 +10,8 @@ void _app_timer_create (HWND hwnd, const MFILTER_APPS *ptr_apps, time_t seconds) const time_t current_time = _r_unixtime_now (); + _r_fastlock_acquireexclusive (&lock_access); + for (size_t i = 0; i < ptr_apps->size (); i++) { PITEM_APP ptr_app = ptr_apps->at (i); @@ -47,6 +49,8 @@ void _app_timer_create (HWND hwnd, const MFILTER_APPS *ptr_apps, time_t seconds) } } + _r_fastlock_releaseexclusive (&lock_access); + _wfp_create3filters (ptr_apps, __LINE__); } @@ -60,6 +64,8 @@ size_t _app_timer_remove (HWND hwnd, const MFILTER_APPS *ptr_apps) MARRAY ids; + _r_fastlock_acquireexclusive (&lock_access); + for (size_t i = 0; i < ptr_apps->size (); i++) { PITEM_APP ptr_app = ptr_apps->at (i); @@ -69,42 +75,51 @@ size_t _app_timer_remove (HWND hwnd, const MFILTER_APPS *ptr_apps) ids.insert (ids.end (), ptr_app->mfarr.begin (), ptr_app->mfarr.end ()); ptr_app->mfarr.clear (); + ptr_app->is_haveerrors = false; if (ptr_app->htimer) { if (DeleteTimerQueueTimer (config.htimer, ptr_app->htimer, nullptr)) - { ptr_app->htimer = nullptr; - ptr_app->timer = 0; - } + } - ptr_app->is_enabled = false; + if(ptr_app->timer) + ptr_app->timer = 0; - const size_t hash = _r_str_hash (ptr_app->original_path); // note: be carefull (!) - const size_t item = _app_getposition (hwnd, hash); + ptr_app->is_enabled = false; - if (item != LAST_VALUE) + const size_t app_hash = _r_str_hash (ptr_app->original_path); // note: be carefull (!) + const size_t item = _app_getposition (hwnd, app_hash); + const UINT listview_id = _app_getlistview_id (ptr_app->type); + + if (item != LAST_VALUE) + { + if (!_app_isappexists (ptr_app) || ptr_app->is_temp) { - if (!_app_isappexists (ptr_app) || ptr_app->is_temp) - { - SendDlgItemMessage (hwnd, IDC_APPS_PROFILE, LVM_DELETEITEM, item, 0); - _app_freeapplication (hash); - } - else + if (listview_id) + SendDlgItemMessage (hwnd, listview_id, LVM_DELETEITEM, item, 0); + + _app_freeapplication (app_hash); + } + else + { + if (listview_id) { _r_fastlock_acquireshared (&lock_checkbox); - _r_listview_setitem (hwnd, IDC_APPS_PROFILE, item, 0, nullptr, LAST_VALUE, _app_getappgroup (hash, ptr_app)); - _r_listview_setitemcheck (hwnd, IDC_APPS_PROFILE, item, ptr_app->is_enabled); + _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_fastlock_releaseshared (&lock_checkbox); } } - - count += 1; } + + count += 1; } + _r_fastlock_releaseexclusive (&lock_access); + _wfp_destroy2filters (&ids, __LINE__); return count; @@ -124,7 +139,6 @@ bool _app_istimersactive () if (_app_istimeractive (&p.second)) { _r_fastlock_releaseshared (&lock_access); - return true; } } @@ -136,25 +150,27 @@ bool _app_istimersactive () void CALLBACK _app_timer_callback (PVOID lparam, BOOLEAN) { - _r_fastlock_acquireexclusive (&lock_access); + _r_fastlock_acquireshared (&lock_access); - const size_t hash = (size_t)lparam; - const PITEM_APP ptr_app = _app_getapplication (hash); + const size_t app_hash = (size_t)lparam; + const PITEM_APP ptr_app = _app_getapplication (app_hash); const HWND hwnd = app.GetHWND (); MFILTER_APPS rules; rules.push_back (ptr_app); - const bool is_succcess = _app_timer_remove (hwnd, &rules); + _r_fastlock_releaseshared (&lock_access); - _r_fastlock_releaseexclusive (&lock_access); + const bool is_succcess = _app_timer_remove (hwnd, &rules); if (is_succcess) { - _app_listviewsort (hwnd, IDC_APPS_PROFILE); - _app_profile_save (hwnd); + const UINT listview_id = _app_gettab_id (hwnd); - _r_listview_redraw (hwnd, IDC_APPS_PROFILE); + _app_listviewsort (hwnd, listview_id); + _app_profile_save (); + + _r_listview_redraw (hwnd, listview_id); if (app.ConfigGet (L"IsNotificationsTimer", true).AsBool ()) app.TrayPopup (hwnd, UID, nullptr, NIIF_USER | (app.ConfigGet (L"IsNotificationsSound", true).AsBool () ? 0 : NIIF_NOSOUND), APP_NAME, _r_fmt (app.LocaleString (IDS_STATUS_TIMER_DONE, nullptr), ptr_app->display_name)); diff --git a/src/wfp.cpp b/src/wfp.cpp index d8b66ba2..f67b9c56 100644 --- a/src/wfp.cpp +++ b/src/wfp.cpp @@ -71,7 +71,6 @@ bool _wfp_initialize (bool is_full) if (!config.hengine) { _r_fastlock_releaseexclusive (&lock_transaction); - return false; } @@ -610,6 +609,8 @@ void _wfp_destroyfilters () if (!config.hengine) return; + _r_fastlock_acquireexclusive (&lock_access); + // clear common filters filter_ids.clear (); @@ -632,6 +633,8 @@ void _wfp_destroyfilters () } } + _r_fastlock_releaseexclusive (&lock_access); + // destroy all filters MARRAY filter_all; @@ -644,7 +647,7 @@ bool _wfp_destroy2filters (const MARRAY * pmar, UINT line) if (!config.hengine || !pmar || pmar->empty ()) return false; - const bool is_enabled = _app_initinterfacestate(); + const bool is_enabled = _app_initinterfacestate (); _r_fastlock_acquireexclusive (&lock_transaction); @@ -698,7 +701,7 @@ bool _wfp_createrulefilter (LPCWSTR name, size_t app_hash, LPCWSTR rule_remote, if (!ptr_app) return false; - if (ptr_app->type == AppPackage) // windows store app (win8+) + if (ptr_app->type == DataAppPackage) // windows store app (win8+) { if (ptr_app->psid) { @@ -715,7 +718,7 @@ bool _wfp_createrulefilter (LPCWSTR name, size_t app_hash, LPCWSTR rule_remote, return false; } } - else if (ptr_app->type == AppService) // windows service + else if (ptr_app->type == DataAppService) // windows service { const rstring path = _r_path_expand (PATH_SVCHOST); const DWORD rc = _FwpmGetAppIdFromFileName1 (path, &bPath, ptr_app->type); @@ -808,16 +811,16 @@ bool _wfp_createrulefilter (LPCWSTR name, size_t app_hash, LPCWSTR rule_remote, { if (i == 0) { - if (addr.type == TypeIp || addr.type == TypeHost) + if (addr.type == DataTypeIp || addr.type == DataTypeHost) is_remoteaddr_set = true; - else if (addr.type == TypePort) + else if (addr.type == DataTypePort) is_remoteport_set = true; } - if (addr.is_range && (addr.type == TypeIp || addr.type == TypePort)) + if (addr.is_range && (addr.type == DataTypeIp || addr.type == DataTypePort)) { - if (addr.type == TypeIp) + if (addr.type == DataTypeIp) { if (addr.format == NET_ADDRESS_IPV4) { @@ -836,14 +839,14 @@ bool _wfp_createrulefilter (LPCWSTR name, size_t app_hash, LPCWSTR rule_remote, } } - fwfc[count].fieldKey = (addr.type == TypePort) ? ((i == 0) ? FWPM_CONDITION_IP_REMOTE_PORT : FWPM_CONDITION_IP_LOCAL_PORT) : ((i == 0) ? FWPM_CONDITION_IP_REMOTE_ADDRESS : FWPM_CONDITION_IP_LOCAL_ADDRESS); + fwfc[count].fieldKey = (addr.type == DataTypePort) ? ((i == 0) ? FWPM_CONDITION_IP_REMOTE_PORT : FWPM_CONDITION_IP_LOCAL_PORT) : ((i == 0) ? FWPM_CONDITION_IP_REMOTE_ADDRESS : FWPM_CONDITION_IP_LOCAL_ADDRESS); fwfc[count].matchType = FWP_MATCH_RANGE; fwfc[count].conditionValue.type = FWP_RANGE_TYPE; fwfc[count].conditionValue.rangeValue = ⦥ count += 1; } - else if (addr.type == TypePort) + else if (addr.type == DataTypePort) { fwfc[count].fieldKey = ((i == 0) ? FWPM_CONDITION_IP_REMOTE_PORT : FWPM_CONDITION_IP_LOCAL_PORT); fwfc[count].matchType = FWP_MATCH_EQUAL; @@ -852,7 +855,7 @@ bool _wfp_createrulefilter (LPCWSTR name, size_t app_hash, LPCWSTR rule_remote, count += 1; } - else if (addr.type == TypeHost || addr.type == TypeIp) + else if (addr.type == DataTypeHost || addr.type == DataTypeIp) { fwfc[count].fieldKey = ((i == 0) ? FWPM_CONDITION_IP_REMOTE_ADDRESS : FWPM_CONDITION_IP_LOCAL_ADDRESS); fwfc[count].matchType = FWP_MATCH_EQUAL; @@ -1011,15 +1014,14 @@ bool _wfp_create4filters (const MFILTER_RULES * ptr_rules, UINT line, bool is_in for (size_t i = 0; i < ptr_rules->size (); i++) { + _r_fastlock_acquireshared (&lock_access); + PITEM_RULE ptr_rule = ptr_rules->at (i); if (ptr_rule) - { ids.insert (ids.end (), ptr_rule->mfarr.begin (), ptr_rule->mfarr.end ()); - ptr_rule->is_haveerrors = false; - ptr_rule->mfarr.clear (); - } + _r_fastlock_releaseshared (&lock_access); } _wfp_destroy2filters (&ids, line); @@ -1030,10 +1032,13 @@ bool _wfp_create4filters (const MFILTER_RULES * ptr_rules, UINT line, bool is_in for (size_t i = 0; i < ptr_rules->size (); i++) { + _r_fastlock_acquireexclusive (&lock_access); + PITEM_RULE ptr_rule = ptr_rules->at (i); if (ptr_rule) { + ptr_rule->is_haveerrors = false; ptr_rule->mfarr.clear (); if (ptr_rule->is_enabled) @@ -1087,6 +1092,8 @@ bool _wfp_create4filters (const MFILTER_RULES * ptr_rules, UINT line, bool is_in } } } + + _r_fastlock_releaseexclusive (&lock_access); } if (!is_intransact) @@ -1099,6 +1106,8 @@ bool _wfp_create4filters (const MFILTER_RULES * ptr_rules, UINT line, bool is_in { for (size_t i = 0; i < ptr_rules->size (); i++) { + _r_fastlock_acquireshared (&lock_access); + PITEM_RULE ptr_rule = ptr_rules->at (i); if (ptr_rule && ptr_rule->is_enabled) @@ -1106,6 +1115,8 @@ bool _wfp_create4filters (const MFILTER_RULES * ptr_rules, UINT line, bool is_in for (size_t j = 0; j < ptr_rule->mfarr.size (); j++) _wfp_setfiltersecurity (config.hengine, &ptr_rule->mfarr.at (j), config.pusersid, is_secure ? config.pacl_secure : config.pacl_default, line); } + + _r_fastlock_releaseshared (&lock_access); } } @@ -1139,10 +1150,9 @@ bool _wfp_create3filters (const MFILTER_APPS * ptr_apps, UINT line, bool is_intr if (ptr_app) { + _r_fastlock_acquireexclusive (&lock_access); ids.insert (ids.end (), ptr_app->mfarr.begin (), ptr_app->mfarr.end ()); - - ptr_app->is_haveerrors = false; - ptr_app->mfarr.clear (); + _r_fastlock_releaseexclusive (&lock_access); } } @@ -1156,8 +1166,18 @@ bool _wfp_create3filters (const MFILTER_APPS * ptr_apps, UINT line, bool is_intr { PITEM_APP ptr_app = ptr_apps->at (i); - if (ptr_app && ptr_app->is_enabled) - ptr_app->is_haveerrors = !_wfp_createrulefilter (ptr_app->display_name, _r_str_hash (ptr_app->original_path), nullptr, nullptr, 0, AF_UNSPEC, FWP_DIRECTION_MAX, FILTER_WEIGHT_APPLICATION, action, 0, &ptr_app->mfarr); + if (ptr_app) + { + _r_fastlock_acquireexclusive (&lock_access); + + ptr_app->is_haveerrors = false; + ptr_app->mfarr.clear (); + + if (ptr_app->is_enabled) + ptr_app->is_haveerrors = !_wfp_createrulefilter (ptr_app->display_name, _r_str_hash (ptr_app->original_path), nullptr, nullptr, 0, AF_UNSPEC, FWP_DIRECTION_MAX, FILTER_WEIGHT_APPLICATION, action, 0, &ptr_app->mfarr); + + _r_fastlock_releaseexclusive (&lock_access); + } } if (!is_intransact) @@ -1174,8 +1194,12 @@ bool _wfp_create3filters (const MFILTER_APPS * ptr_apps, UINT line, bool is_intr if (ptr_app) { + _r_fastlock_acquireshared (&lock_access); + for (size_t j = 0; j < ptr_app->mfarr.size (); j++) _wfp_setfiltersecurity (config.hengine, &ptr_app->mfarr.at (j), config.pusersid, is_secure ? config.pacl_secure : config.pacl_default, line); + + _r_fastlock_releaseshared (&lock_access); } } } @@ -1714,14 +1738,14 @@ void _mps_changeconfig2 (bool is_enable) } } -DWORD _FwpmGetAppIdFromFileName1 (LPCWSTR path, FWP_BYTE_BLOB * *lpblob, EnumAppType type) +DWORD _FwpmGetAppIdFromFileName1 (LPCWSTR path, FWP_BYTE_BLOB * *lpblob, EnumDataType type) { if (!path || !path[0] || !lpblob) return ERROR_BAD_ARGUMENTS; rstring path_buff; - if (type == AppRegular || type == AppNetwork || type == AppService) + if (type == DataAppRegular || type == DataAppNetwork || type == DataAppService) { path_buff = path; @@ -1776,11 +1800,11 @@ DWORD _FwpmGetAppIdFromFileName1 (LPCWSTR path, FWP_BYTE_BLOB * *lpblob, EnumApp return ERROR_SUCCESS; } } - else if (type == AppPico || type == AppDevice) + else if (type == DataAppPico || type == DataAppDevice) { path_buff = path; - if (type == AppDevice) + if (type == DataAppDevice) path_buff.ToLower (); // lower is important! if (ByteBlobAlloc ((LPVOID)path_buff.GetString (), (path_buff.GetLength () + 1) * sizeof (WCHAR), lpblob)) diff --git a/src/wfp.hpp b/src/wfp.hpp index 8d3a53ed..d99f365f 100644 --- a/src/wfp.hpp +++ b/src/wfp.hpp @@ -33,7 +33,7 @@ size_t _wfp_dumpfilters (const GUID* pprovider, MARRAY* pfilters); bool _mps_firewallapi (bool* pis_enabled, const bool* pis_enable); void _mps_changeconfig2 (bool is_enable); -DWORD _FwpmGetAppIdFromFileName1 (LPCWSTR path, FWP_BYTE_BLOB** lpblob, EnumAppType type); +DWORD _FwpmGetAppIdFromFileName1 (LPCWSTR path, FWP_BYTE_BLOB** lpblob, EnumDataType type); bool ByteBlobAlloc (PVOID data, size_t length, FWP_BYTE_BLOB** lpblob); void ByteBlobFree (FWP_BYTE_BLOB** lpblob);