diff options
author | George Hazan <ghazan@miranda.im> | 2018-07-10 23:41:16 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2018-07-10 23:41:16 +0300 |
commit | 431b632ec24f13356397323f19d0db4d117c793f (patch) | |
tree | 629eea40228851e9c8d85204f25fe90cdafd7af5 /plugins/ProxySwitch/src | |
parent | 3d8ca17492f7dcf1d47cddda9afb3797c0f2752b (diff) |
fixes #1455 completely
Diffstat (limited to 'plugins/ProxySwitch/src')
-rw-r--r-- | plugins/ProxySwitch/src/main.cpp | 97 | ||||
-rw-r--r-- | plugins/ProxySwitch/src/opt.cpp | 85 | ||||
-rw-r--r-- | plugins/ProxySwitch/src/resource.h | 3 | ||||
-rw-r--r-- | plugins/ProxySwitch/src/stdafx.h | 2 |
4 files changed, 78 insertions, 109 deletions
diff --git a/plugins/ProxySwitch/src/main.cpp b/plugins/ProxySwitch/src/main.cpp index 44fd01e464..06cea7f732 100644 --- a/plugins/ProxySwitch/src/main.cpp +++ b/plugins/ProxySwitch/src/main.cpp @@ -28,6 +28,7 @@ CMPlugin::CMPlugin() : {} HGENMENU hEnableDisablePopupMenu = 0; +HGENMENU hMenuRoot; OBJLIST<ACTIVE_CONNECTION> g_arConnections(10, PtrKeySortT); mir_cs csConnection_List; @@ -46,8 +47,6 @@ UINT opt_showProxyState; UINT opt_miranda; UINT opt_ie; UINT opt_firefox; -UINT opt_showMyIP; -UINT opt_showProxyIP; UINT opt_alwayReconnect; UINT opt_startup; UINT opt_not_restarted; @@ -129,9 +128,6 @@ void UpdateInterfacesMenu(void) { CMenuItem mi(g_plugin); - if (!opt_showProxyIP && !opt_not_restarted) - return; - mir_cslock lck(csNIF_List); for (auto &it : g_arNIF) { if (it->MenuItem) { @@ -146,8 +142,7 @@ void UpdateInterfacesMenu(void) sprintf(svc, "%s%d", MS_PROXYSWITCH_COPYIP2CLIP, idx); mi.position = 0xC00000; mi.flags = CMIF_UNICODE; - mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Proxy settings && interfaces"), 0xC0000000); - Menu_ConfigureItem(mi.root, MCI_OPT_UID, "68AB766F-09F1-4C4C-9AE1-4135617741C9"); + mi.root = hMenuRoot; SET_UID(mi, 0x8295e40d, 0xa262, 0x434b, 0xa4, 0xb3, 0x57, 0x6b, 0xe0, 0xfc, 0x8f, 0x68); mi.name.w = Print_NIF(it); @@ -253,68 +248,60 @@ int CMPlugin::Load() int Init(WPARAM, LPARAM) { - CMenuItem mi(g_plugin); - opt_popupPluginInstalled = ServiceExists(MS_POPUP_ADDPOPUP); - hEventRebound = CreateEvent(NULL, TRUE, FALSE, NULL); mir_forkthread(IP_WatchDog, 0); - if (opt_showMyIP) { - hSvcShowMyIP = CreateServiceFunction(MS_PROXYSWITCH_SHOWMYIPADDRS, ShowMyIPAddrs); - //ZeroMemory(&mi, sizeof(mi)); - //mi.cbSize = sizeof(mi); - SET_UID(mi, 0x53b0835b, 0x7162, 0x4272, 0x83, 0x3b, 0x3f, 0x60, 0x9e, 0xe, 0x76, 0x4a); - mi.position = 0xC0000000; - mi.flags = CMIF_UNICODE; - mi.hIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_LOGO)); - mi.name.w = LPGENW("Show my &IP addresses"); - mi.pszService = MS_PROXYSWITCH_SHOWMYIPADDRS; - Menu_AddMainMenuItem(&mi); + // menu item + CMenuItem mi(g_plugin); + SET_UID(mi, 0x53b0835b, 0x7162, 0x4272, 0x83, 0x3b, 0x3f, 0x60, 0x9e, 0xe, 0x76, 0x4a); + mi.position = 0xC0000000; + mi.flags = CMIF_UNICODE; + mi.hIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_LOGO)); + mi.name.w = LPGENW("Show my &IP addresses"); + mi.pszService = MS_PROXYSWITCH_SHOWMYIPADDRS; + HGENMENU hMenu = Menu_AddMainMenuItem(&mi); + hSvcShowMyIP = CreateServiceFunction(mi.pszService, ShowMyIPAddrs); + + int opt_showMyIP = db_get_b(NULL, MODULENAME, "ShowMyIP", 100); + if (opt_showMyIP != 100) { + Menu_SetVisible(hMenu, opt_showMyIP != 0); + db_unset(NULL, MODULENAME, "ShowMyIP"); } - if (opt_showProxyIP) { - - hSvcProxyDisable = CreateServiceFunction(MS_PROXYSWITCH_PROXYDISABLE, ProxyDisable); - //ZeroMemory(&mi, sizeof(mi)); - //mi.cbSize = sizeof(mi); - SET_UID(mi, 0xf93289a9, 0x3bad, 0x424b, 0xb2, 0x72, 0x14, 0xa7, 0x45, 0xa5, 0x8, 0x9c); - mi.position = 1; - mi.name.w = LPGENW("Disable proxy"); - mi.pszService = MS_PROXYSWITCH_PROXYDISABLE; - mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Proxy settings && interfaces"), 0xC0000000); - Menu_ConfigureItem(mi.root, MCI_OPT_UID, "A9684E9E-E621-4962-986F-576897928D27"); - //mi.pszPopupName = Translate("Proxy settings && interfaces"); - //mi.popupPosition = 0xC0000000; - Menu_AddMainMenuItem(&mi); - - hSvcProxyEnable = CreateServiceFunction(MS_PROXYSWITCH_PROXYENABLE, ProxyEnable); - //ZeroMemory(&mi, sizeof(mi)); - //mi.cbSize = sizeof(mi); - mi.position = 1; - mi.name.w = LPGENW("Enable proxy"); - mi.pszService = MS_PROXYSWITCH_PROXYENABLE; - mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Proxy settings && interfaces"), 0xC0000000); - Menu_ConfigureItem(mi.root, MCI_OPT_UID, "B37E5BBE-19CF-4C78-AE53-A0DB11656C36"); - //mi.pszPopupName = Translate("Proxy settings && interfaces"); - //mi.popupPosition = 0xC0000000; - Menu_AddMainMenuItem(&mi); - - UpdateInterfacesMenu(); + hMenuRoot = mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Proxy settings && interfaces"), 0xC0000000); + Menu_ConfigureItem(hMenuRoot, MCI_OPT_UID, "A9684E9E-E621-4962-986F-576897928D27"); + + SET_UID(mi, 0xf93289a9, 0x3bad, 0x424b, 0xb2, 0x72, 0x14, 0xa7, 0x45, 0xa5, 0x8, 0x9c); + mi.position = 1; + mi.name.w = LPGENW("Disable proxy"); + mi.pszService = MS_PROXYSWITCH_PROXYDISABLE; + Menu_AddMainMenuItem(&mi); + hSvcProxyDisable = CreateServiceFunction(mi.pszService, ProxyDisable); + + SET_UID(mi, 0xf93289a9, 0x3bad, 0x424b, 0xb2, 0x72, 0x14, 0xa7, 0x45, 0xa5, 0x8, 0x9D); + mi.position = 2; + mi.name.w = LPGENW("Enable proxy"); + mi.pszService = MS_PROXYSWITCH_PROXYENABLE; + Menu_AddMainMenuItem(&mi); + hSvcProxyEnable = CreateServiceFunction(mi.pszService, ProxyEnable); + + int opt_showProxyIP = db_get_b(NULL, MODULENAME, "ShowProxyIP", 100); + if (opt_showProxyIP != 100) { + Menu_SetVisible(mi.root, opt_showProxyIP != 0); + db_unset(NULL, MODULENAME, "ShowProxyIP"); } + UpdateInterfacesMenu(); + if (opt_popupPluginInstalled) { - hSvcPopupSwitch = CreateServiceFunction(MS_PROXYSWITCH_POPUPSWITCH, PopupSwitch); - //ZeroMemory(&mi, sizeof(mi)); - //mi.cbSize = sizeof(mi); + mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Popups"), 0xC0000000); mi.name.w = LPGENW("IP change notification"); mi.hIcon = LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(IDI_LOGO)); - mi.root = g_plugin.addRootMenu(MO_MAIN, LPGENW("Popups"), 0xC0000000); - Menu_ConfigureItem(mi.root, MCI_OPT_UID, "185AC334-E90E-46C6-83A2-D4E36CB257D9"); - //mi.pszPopupName = Translate("Popups"); mi.pszService = MS_PROXYSWITCH_POPUPSWITCH; hEnableDisablePopupMenu = Menu_AddMainMenuItem(&mi); + hSvcPopupSwitch = CreateServiceFunction(mi.pszService, PopupSwitch); UpdatePopupMenu(opt_popups); } diff --git a/plugins/ProxySwitch/src/opt.cpp b/plugins/ProxySwitch/src/opt.cpp index 44c7df46af..416ff92fc8 100644 --- a/plugins/ProxySwitch/src/opt.cpp +++ b/plugins/ProxySwitch/src/opt.cpp @@ -9,27 +9,24 @@ the proxy settings of Miranda and Internet Explorer accordingly. int help_shown; -void ShowHelp(HWND hdlg, int showhide_help) +static INT_PTR CALLBACK HelpProc(HWND hdlg, UINT msg, WPARAM wParam, LPARAM) { - int showhide_others = showhide_help == SW_SHOW ? SW_HIDE : SW_SHOW; - help_shown = showhide_help; - - ShowWindow(GetDlgItem(hdlg, IDC_HELP_1), showhide_help); - ShowWindow(GetDlgItem(hdlg, IDC_HELP_2), showhide_help); - ShowWindow(GetDlgItem(hdlg, IDC_HELP_3), showhide_help); - - ShowWindow(GetDlgItem(hdlg, IDC_CHECK_MIRANDA), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_CHECK_IE), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_CHECK_FIREFOX), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_CHECK_PROXYIPMENU), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_CHECK_SHOWMYIPMENU), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_CHECK_DEFAULTCOLORS), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_CHECK_SHOWPROXYSTATUS), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_CHECK_ALWAY_RECONNECT), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_CHECK_POPUPS), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_BGCOLOR), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_TEXTCOLOR), showhide_others); - ShowWindow(GetDlgItem(hdlg, IDC_EDIT_HIDEINTF), showhide_others); + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hdlg); + return 1; + + case WM_COMMAND: + if (wParam == IDOK || wParam == IDCANCEL) + EndDialog(hdlg, 0); + break; + + case WM_CLOSE: + EndDialog(hdlg, 0); + break; + } + + return 0; } INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) @@ -39,14 +36,11 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) case WM_INITDIALOG: opt_startup = TRUE; LoadSettings(); - ShowHelp(hdlg, SW_HIDE); SetDlgItemText(hdlg, IDC_EDIT_USEPROXY, opt_useProxy); SetDlgItemText(hdlg, IDC_EDIT_NOPROXY, opt_noProxy); CheckDlgButton(hdlg, IDC_CHECK_MIRANDA, opt_miranda ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hdlg, IDC_CHECK_IE, opt_ie ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hdlg, IDC_CHECK_FIREFOX, opt_firefox ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_CHECK_SHOWMYIPMENU, opt_showMyIP ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hdlg, IDC_CHECK_PROXYIPMENU, opt_showProxyIP ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hdlg, IDC_CHECK_ALWAY_RECONNECT, opt_alwayReconnect ? BST_CHECKED : BST_UNCHECKED); SetDlgItemText(hdlg, IDC_EDIT_HIDEINTF, opt_hideIntf); SendDlgItemMessage(hdlg, IDC_BGCOLOR, CPM_SETCOLOUR, 0, opt_bgColor); @@ -68,7 +62,6 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) case WM_NOTIFY: switch (((LPNMHDR)lparam)->code) { case PSN_APPLY: - opt_not_restarted = opt_not_restarted || IsDlgButtonChecked(hdlg, IDC_CHECK_PROXYIPMENU) != opt_showProxyIP || IsDlgButtonChecked(hdlg, IDC_CHECK_SHOWMYIPMENU) != opt_showMyIP; ShowWindow(GetDlgItem(hdlg, IDC_RESTARTREQUIRED), opt_not_restarted ? SW_SHOW : SW_HIDE); GetDlgItemText(hdlg, IDC_EDIT_NOPROXY, opt_noProxy, MAX_IPLIST_LENGTH); GetDlgItemText(hdlg, IDC_EDIT_USEPROXY, opt_useProxy, MAX_IPLIST_LENGTH); @@ -76,8 +69,6 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) opt_miranda = IsDlgButtonChecked(hdlg, IDC_CHECK_MIRANDA); opt_ie = IsDlgButtonChecked(hdlg, IDC_CHECK_IE); opt_firefox = IsDlgButtonChecked(hdlg, IDC_CHECK_FIREFOX); - opt_showMyIP = IsDlgButtonChecked(hdlg, IDC_CHECK_SHOWMYIPMENU); - opt_showProxyIP = IsDlgButtonChecked(hdlg, IDC_CHECK_PROXYIPMENU); opt_alwayReconnect = IsDlgButtonChecked(hdlg, IDC_CHECK_ALWAY_RECONNECT); opt_popups = IsDlgButtonChecked(hdlg, IDC_CHECK_POPUPS); opt_defaultColors = IsDlgButtonChecked(hdlg, IDC_CHECK_DEFAULTCOLORS); @@ -93,12 +84,13 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) case WM_COMMAND: if (opt_startup) return 0; + if (HIWORD(wparam) == BN_CLICKED && GetFocus() == (HWND)lparam && LOWORD(wparam) != IDC_BTN_HELP) SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); - switch (LOWORD(wparam)) { + switch (LOWORD(wparam)) { case IDC_BTN_HELP: - ShowHelp(hdlg, help_shown == SW_SHOW ? SW_HIDE : SW_SHOW); + DialogBox(g_plugin.getInst(), MAKEINTRESOURCE(IDD_HELP), 0, HelpProc); break; case IDC_EDIT_USEPROXY: @@ -114,11 +106,6 @@ INT_PTR CALLBACK OptionsProc(HWND hdlg, UINT msg, WPARAM wparam, LPARAM lparam) SendMessage(GetParent(hdlg), PSM_CHANGED, 0, 0); break; - case IDC_CHECK_PROXYIPMENU: - case IDC_CHECK_SHOWMYIPMENU: - ShowWindow(GetDlgItem(hdlg, IDC_RESTARTREQUIRED), opt_not_restarted || (IsDlgButtonChecked(hdlg, IDC_CHECK_PROXYIPMENU) != opt_showProxyIP || IsDlgButtonChecked(hdlg, IDC_CHECK_SHOWMYIPMENU) != opt_showMyIP) ? SW_SHOW : SW_HIDE); - break; - case IDC_CHECK_DEFAULTCOLORS: case IDC_CHECK_POPUPS: if (!opt_popupPluginInstalled) @@ -156,28 +143,28 @@ int OptInit(WPARAM wParam, LPARAM) void LoadSettings(void) { - DBVARIANT dbv; - if (db_get(NULL, MODULENAME, "UseProxyIPNets", &dbv)) - mir_wstrcpy(opt_useProxy, L""); + ptrW wszStr(db_get_wsa(NULL, MODULENAME, "UseProxyIPNets")); + if (!wszStr) + opt_useProxy[0] = 0; else - mir_wstrcpy(opt_useProxy, dbv.pwszVal); - db_free(&dbv); - if (db_get(NULL, MODULENAME, "NoProxyIPNets", &dbv)) - mir_wstrcpy(opt_noProxy, L""); + wcsncpy_s(opt_useProxy, wszStr, _TRUNCATE); + + wszStr = db_get_wsa(NULL, MODULENAME, "NoProxyIPNets"); + if (!wszStr) + opt_noProxy[0] = 0; else - mir_wstrcpy(opt_noProxy, dbv.pwszVal); - db_free(&dbv); - if (db_get(NULL, MODULENAME, "HideInterfaces", &dbv)) - mir_wstrcpy(opt_hideIntf, L""); + wcsncpy_s(opt_noProxy, wszStr, _TRUNCATE); + + wszStr = db_get_wsa(NULL, MODULENAME, "HideInterfaces"); + if (!wszStr) + opt_hideIntf[0] = 0; else - mir_wstrcpy(opt_hideIntf, dbv.pwszVal); - db_free(&dbv); + wcsncpy_s(opt_hideIntf, wszStr, _TRUNCATE); + opt_miranda = db_get_b(NULL, MODULENAME, "ManageMirandaProxy", TRUE); opt_ie = db_get_b(NULL, MODULENAME, "ManageIEProxy", FALSE); opt_firefox = db_get_b(NULL, MODULENAME, "ManageFirefoxProxy", FALSE) && Firefox_Installed(); opt_alwayReconnect = db_get_b(NULL, MODULENAME, "AlwaysReconnect", FALSE); - opt_showMyIP = db_get_b(NULL, MODULENAME, "ShowMyIP", TRUE); - opt_showProxyIP = db_get_b(NULL, MODULENAME, "ShowProxyIP", TRUE); opt_popups = db_get_b(NULL, MODULENAME, "PopupEnabled", TRUE); opt_defaultColors = db_get_b(NULL, MODULENAME, "PopupDefaultColors", TRUE); opt_showProxyState = db_get_b(NULL, MODULENAME, "ShowProxyStatus", TRUE); @@ -194,8 +181,6 @@ void SaveSettings(void) db_set_b(NULL, MODULENAME, "ManageIEProxy", (BYTE)opt_ie); db_set_b(NULL, MODULENAME, "ManageFirefoxProxy", (BYTE)opt_firefox); db_set_b(NULL, MODULENAME, "AlwaysReconnect", (BYTE)opt_alwayReconnect); - db_set_b(NULL, MODULENAME, "ShowMyIP", (BYTE)opt_showMyIP); - db_set_b(NULL, MODULENAME, "ShowProxyIP", (BYTE)opt_showProxyIP); db_set_b(NULL, MODULENAME, "PopupEnabled", (BYTE)opt_popups); db_set_b(NULL, MODULENAME, "PopupDefaultColors", (BYTE)opt_defaultColors); db_set_b(NULL, MODULENAME, "ShowProxyStatus", (BYTE)opt_showProxyState); diff --git a/plugins/ProxySwitch/src/resource.h b/plugins/ProxySwitch/src/resource.h index 8fa07ce325..5550c2f5a1 100644 --- a/plugins/ProxySwitch/src/resource.h +++ b/plugins/ProxySwitch/src/resource.h @@ -8,6 +8,7 @@ #define IDD_OPTIONS 103 #define IDI_NOTIF_0 104 #define IDI_NOTIF_1 105 +#define IDD_HELP 106 #define IDC_EDIT_USEPROXY 1002 #define IDC_EDIT_NOPROXY 1004 #define IDC_CHECK_DEFAULTCOLORS 1009 @@ -16,8 +17,6 @@ #define IDC_CHECK_IE 1015 #define IDC_CHECK_IE2 1016 #define IDC_CHECK_FIREFOX 1016 -#define IDC_CHECK_SHOWMYIPMENU 1021 -#define IDC_CHECK_PROXYIPMENU 1022 #define IDC_CHECK_ALWAY_RECONNECT 1024 #define IDC_EDIT_HIDEINTF 1025 #define IDC_RESTARTREQUIRED 1026 diff --git a/plugins/ProxySwitch/src/stdafx.h b/plugins/ProxySwitch/src/stdafx.h index 550d21f8ad..0afc33e0dd 100644 --- a/plugins/ProxySwitch/src/stdafx.h +++ b/plugins/ProxySwitch/src/stdafx.h @@ -101,8 +101,6 @@ extern UINT opt_showProxyState; extern UINT opt_miranda; extern UINT opt_ie; extern UINT opt_firefox; -extern UINT opt_showMyIP; -extern UINT opt_showProxyIP; extern UINT opt_alwayReconnect; extern UINT opt_startup; extern UINT opt_not_restarted; |