mirror of https://github.com/OpenVPN/openvpn-gui
fix loading of the proxy source from registry
parent
9d918954d5
commit
6934dfa783
97
proxy.c
97
proxy.c
|
@ -39,16 +39,18 @@
|
||||||
|
|
||||||
extern options_t o;
|
extern options_t o;
|
||||||
|
|
||||||
bool CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam)
|
bool CALLBACK
|
||||||
|
ProxySettingsDialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam)
|
||||||
{
|
{
|
||||||
HICON hIcon;
|
HICON hIcon;
|
||||||
LPPSHNOTIFY psn;
|
LPPSHNOTIFY psn;
|
||||||
|
|
||||||
switch (msg) {
|
switch (msg)
|
||||||
|
{
|
||||||
case WM_INITDIALOG:
|
case WM_INITDIALOG:
|
||||||
hIcon = LoadLocalizedIcon(ID_ICO_APP);
|
hIcon = LoadLocalizedIcon(ID_ICO_APP);
|
||||||
if (hIcon) {
|
if (hIcon)
|
||||||
|
{
|
||||||
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon));
|
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon));
|
||||||
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon));
|
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon));
|
||||||
}
|
}
|
||||||
|
@ -60,8 +62,8 @@ bool CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UN
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_COMMAND:
|
case WM_COMMAND:
|
||||||
switch (LOWORD(wParam)) {
|
switch (LOWORD(wParam))
|
||||||
|
{
|
||||||
case ID_RB_PROXY_OPENVPN:
|
case ID_RB_PROXY_OPENVPN:
|
||||||
if (HIWORD(wParam) == BN_CLICKED)
|
if (HIWORD(wParam) == BN_CLICKED)
|
||||||
{
|
{
|
||||||
|
@ -120,8 +122,7 @@ bool CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UN
|
||||||
psn = (LPPSHNOTIFY) lParam;
|
psn = (LPPSHNOTIFY) lParam;
|
||||||
if (psn->hdr.code == (UINT) PSN_KILLACTIVE)
|
if (psn->hdr.code == (UINT) PSN_KILLACTIVE)
|
||||||
{
|
{
|
||||||
SetWindowLong(hwndDlg, DWL_MSGRESULT,
|
SetWindowLong(hwndDlg, DWL_MSGRESULT, (CheckProxySettings(hwndDlg) ? FALSE : TRUE));
|
||||||
( CheckProxySettings(hwndDlg) ? FALSE : TRUE ));
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else if (psn->hdr.code == (UINT) PSN_APPLY)
|
else if (psn->hdr.code == (UINT) PSN_APPLY)
|
||||||
|
@ -135,13 +136,14 @@ bool CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UN
|
||||||
case WM_CLOSE:
|
case WM_CLOSE:
|
||||||
EndDialog(hwndDlg, LOWORD(wParam));
|
EndDialog(hwndDlg, LOWORD(wParam));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Check that proxy settings are valid */
|
/* Check that proxy settings are valid */
|
||||||
int CheckProxySettings(HWND hwndDlg)
|
int
|
||||||
|
CheckProxySettings(HWND hwndDlg)
|
||||||
{
|
{
|
||||||
if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MANUAL) == BST_CHECKED)
|
if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MANUAL) == BST_CHECKED)
|
||||||
{
|
{
|
||||||
|
@ -153,7 +155,7 @@ int CheckProxySettings(HWND hwndDlg)
|
||||||
{
|
{
|
||||||
/* proxy address not specified */
|
/* proxy address not specified */
|
||||||
ShowLocalizedMsg((http ? IDS_ERR_HTTP_PROXY_ADDRESS : IDS_ERR_SOCKS_PROXY_ADDRESS));
|
ShowLocalizedMsg((http ? IDS_ERR_HTTP_PROXY_ADDRESS : IDS_ERR_SOCKS_PROXY_ADDRESS));
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
GetDlgItemText(hwndDlg, ID_EDT_PROXY_PORT, text, _tsizeof(text));
|
GetDlgItemText(hwndDlg, ID_EDT_PROXY_PORT, text, _tsizeof(text));
|
||||||
|
@ -161,7 +163,7 @@ int CheckProxySettings(HWND hwndDlg)
|
||||||
{
|
{
|
||||||
/* proxy port not specified */
|
/* proxy port not specified */
|
||||||
ShowLocalizedMsg((http ? IDS_ERR_HTTP_PROXY_PORT : IDS_ERR_SOCKS_PROXY_PORT));
|
ShowLocalizedMsg((http ? IDS_ERR_HTTP_PROXY_PORT : IDS_ERR_SOCKS_PROXY_PORT));
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
long port = _tcstol(text, NULL, 10);
|
long port = _tcstol(text, NULL, 10);
|
||||||
|
@ -169,11 +171,11 @@ int CheckProxySettings(HWND hwndDlg)
|
||||||
{
|
{
|
||||||
/* proxy port range error */
|
/* proxy port range error */
|
||||||
ShowLocalizedMsg((http ? IDS_ERR_HTTP_PROXY_PORT_RANGE : IDS_ERR_SOCKS_PROXY_PORT_RANGE));
|
ShowLocalizedMsg((http ? IDS_ERR_HTTP_PROXY_PORT_RANGE : IDS_ERR_SOCKS_PROXY_PORT_RANGE));
|
||||||
return(0);
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(1);
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -210,7 +212,8 @@ LoadProxySettings(HWND hwndDlg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SaveProxySettings(HWND hwndDlg)
|
void
|
||||||
|
SaveProxySettings(HWND hwndDlg)
|
||||||
{
|
{
|
||||||
HKEY regkey;
|
HKEY regkey;
|
||||||
DWORD dwDispos;
|
DWORD dwDispos;
|
||||||
|
@ -223,12 +226,12 @@ void SaveProxySettings(HWND hwndDlg)
|
||||||
o.proxy_source = config;
|
o.proxy_source = config;
|
||||||
proxy_source_string[0] = _T('0');
|
proxy_source_string[0] = _T('0');
|
||||||
}
|
}
|
||||||
if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MSIE) == BST_CHECKED)
|
else if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MSIE) == BST_CHECKED)
|
||||||
{
|
{
|
||||||
o.proxy_source = browser;
|
o.proxy_source = browser;
|
||||||
proxy_source_string[0] = _T('1');
|
proxy_source_string[0] = _T('1');
|
||||||
}
|
}
|
||||||
if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MANUAL) == BST_CHECKED)
|
else if (IsDlgButtonChecked(hwndDlg, ID_RB_PROXY_MANUAL) == BST_CHECKED)
|
||||||
{
|
{
|
||||||
o.proxy_source = manual;
|
o.proxy_source = manual;
|
||||||
proxy_source_string[0] = _T('2');
|
proxy_source_string[0] = _T('2');
|
||||||
|
@ -257,15 +260,8 @@ void SaveProxySettings(HWND hwndDlg)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Open Registry for writing */
|
/* Open Registry for writing */
|
||||||
if (RegCreateKeyEx(HKEY_CURRENT_USER,
|
if (RegCreateKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, _T(""), REG_OPTION_NON_VOLATILE,
|
||||||
GUI_REGKEY_HKCU,
|
KEY_WRITE, NULL, ®key, &dwDispos) != ERROR_SUCCESS)
|
||||||
0,
|
|
||||||
_T(""),
|
|
||||||
REG_OPTION_NON_VOLATILE,
|
|
||||||
KEY_WRITE,
|
|
||||||
NULL,
|
|
||||||
®key,
|
|
||||||
&dwDispos) != ERROR_SUCCESS)
|
|
||||||
{
|
{
|
||||||
/* error creating Registry-Key */
|
/* error creating Registry-Key */
|
||||||
ShowLocalizedMsg(IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU);
|
ShowLocalizedMsg(IDS_ERR_CREATE_REG_HKCU_KEY, GUI_REGKEY_HKCU);
|
||||||
|
@ -283,7 +279,9 @@ void SaveProxySettings(HWND hwndDlg)
|
||||||
RegCloseKey(regkey);
|
RegCloseKey(regkey);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GetProxyRegistrySettings()
|
|
||||||
|
void
|
||||||
|
GetProxyRegistrySettings()
|
||||||
{
|
{
|
||||||
LONG status;
|
LONG status;
|
||||||
HKEY regkey;
|
HKEY regkey;
|
||||||
|
@ -291,39 +289,32 @@ void GetProxyRegistrySettings()
|
||||||
TCHAR proxy_type_string[2] = _T("0");
|
TCHAR proxy_type_string[2] = _T("0");
|
||||||
|
|
||||||
/* Open Registry for reading */
|
/* Open Registry for reading */
|
||||||
status = RegOpenKeyEx(HKEY_CURRENT_USER,
|
status = RegOpenKeyEx(HKEY_CURRENT_USER, GUI_REGKEY_HKCU, 0, KEY_READ, ®key);
|
||||||
GUI_REGKEY_HKCU,
|
if (status != ERROR_SUCCESS)
|
||||||
0,
|
return;
|
||||||
KEY_READ,
|
|
||||||
®key);
|
|
||||||
|
|
||||||
/* Return if can't open the registry key */
|
|
||||||
if (status != ERROR_SUCCESS) return;
|
|
||||||
|
|
||||||
|
|
||||||
/* get registry settings */
|
/* get registry settings */
|
||||||
GetRegistryValue(regkey, _T("proxy_http_address"), o.proxy_http_address,
|
GetRegistryValue(regkey, _T("proxy_http_address"), o.proxy_http_address, _tsizeof(o.proxy_http_address));
|
||||||
_tsizeof(o.proxy_http_address));
|
GetRegistryValue(regkey, _T("proxy_http_port"), o.proxy_http_port, _tsizeof(o.proxy_http_port));
|
||||||
GetRegistryValue(regkey, _T("proxy_http_port"), o.proxy_http_port,
|
GetRegistryValue(regkey, _T("proxy_socks_address"), o.proxy_socks_address, _tsizeof(o.proxy_socks_address));
|
||||||
_tsizeof(o.proxy_http_port));
|
GetRegistryValue(regkey, _T("proxy_socks_port"), o.proxy_socks_port, _tsizeof(o.proxy_socks_port));
|
||||||
GetRegistryValue(regkey, _T("proxy_socks_address"), o.proxy_socks_address,
|
GetRegistryValue(regkey, _T("proxy_source"), proxy_source_string, _tsizeof(proxy_source_string));
|
||||||
_tsizeof(o.proxy_socks_address));
|
GetRegistryValue(regkey, _T("proxy_type"), proxy_type_string, _tsizeof(proxy_type_string));
|
||||||
GetRegistryValue(regkey, _T("proxy_socks_port"), o.proxy_socks_port,
|
|
||||||
_tsizeof(o.proxy_socks_port));
|
|
||||||
GetRegistryValue(regkey, _T("proxy_source"), proxy_source_string,
|
|
||||||
_tsizeof(proxy_source_string));
|
|
||||||
GetRegistryValue(regkey, _T("proxy_type"), proxy_type_string,
|
|
||||||
_tsizeof(proxy_type_string));
|
|
||||||
|
|
||||||
if (proxy_source_string[0] == _T('1'))
|
if (proxy_source_string[0] == _T('0'))
|
||||||
|
{
|
||||||
o.proxy_source = config;
|
o.proxy_source = config;
|
||||||
if (proxy_source_string[0] == _T('2'))
|
}
|
||||||
|
else if (proxy_source_string[0] == _T('1'))
|
||||||
|
{
|
||||||
o.proxy_source = browser;
|
o.proxy_source = browser;
|
||||||
if (proxy_source_string[0] == _T('3'))
|
}
|
||||||
|
else if (proxy_source_string[0] == _T('2'))
|
||||||
|
{
|
||||||
o.proxy_source = manual;
|
o.proxy_source = manual;
|
||||||
|
}
|
||||||
|
|
||||||
if (proxy_type_string[0] == _T('1'))
|
o.proxy_type = (proxy_type_string[0] == _T('0') ? http : socks);
|
||||||
o.proxy_type = socks;
|
|
||||||
|
|
||||||
RegCloseKey(regkey);
|
RegCloseKey(regkey);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue