mirror of https://github.com/OpenVPN/openvpn-gui
Change default log file location to a OpenVPN/log in user's profile directory
Change the default log file location to OpenVPN/log in user's profile directory to support running without admin privileges using the interactive service. The registry keys are moved to HKCU from HKLM to allow for user-specific settings as well as to avoid the need for running the GUI as admin at the first instance. Signed-off-by: Selva Nair <selva.nair@gmail.com>pull/13/head
parent
791aea49e6
commit
4437ce7a8c
|
@ -239,5 +239,6 @@
|
|||
#define IDS_ERR_OPEN_WRITE_REG 1810
|
||||
#define IDS_ERR_READ_SET_KEY 1811
|
||||
#define IDS_ERR_WRITE_REGVALUE 1812
|
||||
#define IDS_ERR_GET_PROFILE_DIR 1813
|
||||
|
||||
#endif
|
||||
|
|
18
registry.c
18
registry.c
|
@ -42,6 +42,7 @@ GetRegistryKeys()
|
|||
TCHAR windows_dir[MAX_PATH];
|
||||
TCHAR temp_path[MAX_PATH];
|
||||
TCHAR openvpn_path[MAX_PATH];
|
||||
TCHAR profile_dir[MAX_PATH];
|
||||
HKEY regkey;
|
||||
|
||||
if (!GetWindowsDirectory(windows_dir, _countof(windows_dir))) {
|
||||
|
@ -50,6 +51,11 @@ GetRegistryKeys()
|
|||
return(false);
|
||||
}
|
||||
|
||||
if (SHGetFolderPath(NULL, CSIDL_PROFILE, NULL, SHGFP_TYPE_CURRENT, profile_dir) != S_OK) {
|
||||
ShowLocalizedMsg(IDS_ERR_GET_PROFILE_DIR);
|
||||
return(false);
|
||||
}
|
||||
|
||||
/* Get path to OpenVPN installation. */
|
||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\OpenVPN"), 0, KEY_READ, ®key)
|
||||
!= ERROR_SUCCESS)
|
||||
|
@ -78,7 +84,7 @@ GetRegistryKeys()
|
|||
if (!GetRegKey(_T("exe_path"), o.exe_path,
|
||||
temp_path, _countof(o.exe_path))) return(false);
|
||||
|
||||
_sntprintf_0(temp_path, _T("%slog"), openvpn_path);
|
||||
_sntprintf_0(temp_path, _T("%s\\OpenVPN\\log"), profile_dir);
|
||||
if (!GetRegKey(_T("log_dir"), o.log_dir,
|
||||
temp_path, _countof(o.log_dir))) return(false);
|
||||
|
||||
|
@ -178,7 +184,7 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
|
|||
return(true);
|
||||
}
|
||||
|
||||
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
status = RegOpenKeyEx(HKEY_CURRENT_USER,
|
||||
_T("SOFTWARE\\OpenVPN-GUI"),
|
||||
0,
|
||||
KEY_READ,
|
||||
|
@ -186,7 +192,7 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
|
|||
|
||||
if (status != ERROR_SUCCESS)
|
||||
{
|
||||
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
|
||||
if (RegCreateKeyEx(HKEY_CURRENT_USER,
|
||||
_T("Software\\OpenVPN-GUI"),
|
||||
0,
|
||||
_T(""),
|
||||
|
@ -197,7 +203,7 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
|
|||
&dwDispos) != ERROR_SUCCESS)
|
||||
{
|
||||
/* error creating registry key */
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_REG_KEY);
|
||||
ShowLocalizedMsg(IDS_ERR_CREATE_REG_HKCU_KEY, _T("OpenVPN-GUI"));
|
||||
return(false);
|
||||
}
|
||||
}
|
||||
|
@ -208,7 +214,7 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
|
|||
if (status != ERROR_SUCCESS || type != REG_SZ)
|
||||
{
|
||||
/* key did not exist - set default value */
|
||||
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
||||
status = RegOpenKeyEx(HKEY_CURRENT_USER,
|
||||
_T("SOFTWARE\\OpenVPN-GUI"),
|
||||
0,
|
||||
KEY_READ | KEY_WRITE,
|
||||
|
@ -216,7 +222,7 @@ int GetRegKey(const TCHAR name[], TCHAR *data, const TCHAR default_data[], DWORD
|
|||
|
||||
if (status != ERROR_SUCCESS) {
|
||||
/* can't open registry for writing */
|
||||
ShowLocalizedMsg(IDS_ERR_OPEN_WRITE_REG);
|
||||
ShowLocalizedMsg(IDS_ERR_WRITE_REGVALUE, _T("OpenVPN-GUI"), name);
|
||||
return(false);
|
||||
}
|
||||
if(!SetRegistryValue(openvpn_key_write, name, default_data))
|
||||
|
|
|
@ -325,6 +325,7 @@ BEGIN
|
|||
|
||||
/* registry */
|
||||
IDS_ERR_GET_WINDOWS_DIR "Error getting Windows Directory."
|
||||
IDS_ERR_GET_PROFILE_DIR "Error getting User Profile Directory."
|
||||
IDS_ERR_GET_PROGRAM_DIR "Error getting ""Program"" folder name."
|
||||
IDS_ERR_OPEN_REGISTRY "Error opening registry for reading (HKLM\\SOFTWARE\\OpenVPN).\n " \
|
||||
"OpenVPN is probably not installed"
|
||||
|
|
Loading…
Reference in New Issue