Browse Source

Use file associations to open config and log

- Use ShellExecute to open config and log files so that
  file associations can be used. If that fails fall-back to
  the default editor (notepad.exe).
- Remove the keys editor and log_viewer from registry.
  The user can change the editor/viewer through fie association.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
pull/62/head
Selva Nair 9 years ago
parent
commit
964d728a42
  1. 1
      Makefile.am
  2. 14
      registry.c
  3. 29
      viewlog.c

1
Makefile.am

@ -104,6 +104,7 @@ openvpn_gui_LDADD = \
-lwtsapi32 \
-lcrypt32 \
-lnetapi32 \
-lole32 \
-lsecur32
openvpn-gui-res.o: $(openvpn_gui_RESOURCES) $(srcdir)/openvpn-gui-res.h

14
registry.c

@ -128,13 +128,15 @@ GetRegistryKeys()
if (!GetRegKey(_T("log_append"), o.append_string, _T("0"), _countof(o.append_string))) return(false);
_sntprintf_0(temp_path, _T("%s\\system32\\notepad.exe"), windows_dir);
if (!GetRegKey(_T("log_viewer"), o.log_viewer,
temp_path, _countof(o.log_viewer))) return(false);
if (o.editor[0] != L'\0') /* set by cmd-line */
ExpandString (o.editor, _countof(o.editor));
else
_sntprintf_0(o.editor, _T("%s\\system32\\notepad.exe"), windows_dir);
_sntprintf_0(temp_path, _T("%s\\system32\\notepad.exe"), windows_dir);
if (!GetRegKey(_T("editor"), o.editor,
temp_path, _countof(o.editor))) return(false);
if (o.log_viewer[0] != L'\0') /* set by cmd-line */
ExpandString (o.log_viewer, _countof(o.log_viewer));
else
_sntprintf_0(o.log_viewer, _T("%s\\system32\\notepad.exe"), windows_dir);
if (!GetRegKey(_T("service_only"), o.service_only, _T("0"), _countof(o.service_only))) return(false);

29
viewlog.c

@ -25,6 +25,8 @@
#include <windows.h>
#include <stdio.h>
#include <shellapi.h>
#include <objbase.h>
#include "tray.h"
#include "openvpn.h"
@ -37,18 +39,29 @@ extern options_t o;
void ViewLog(int config)
{
TCHAR filename[200];
TCHAR filename[2*MAX_PATH];
STARTUPINFO start_info;
PROCESS_INFORMATION proc_info;
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
HINSTANCE status;
CLEAR (start_info);
CLEAR (proc_info);
CLEAR (sa);
CLEAR (sd);
/* Try first using file association */
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); /* Safe to init COM multiple times */
status = ShellExecuteW (o.hWnd, L"open", o.conn[config].log_path, NULL, o.log_dir, SW_SHOWNORMAL);
if (status > (HINSTANCE) 32) /* Success */
return;
else
PrintDebug (L"Opening log file using ShellExecute with verb = open failed"
" for config '%s' (status = %lu)", o.conn[config].config_name, status);
_sntprintf_0(filename, _T("%s \"%s\""), o.log_viewer, o.conn[config].log_path);
/* fill in STARTUPINFO struct */
@ -81,18 +94,30 @@ void ViewLog(int config)
void EditConfig(int config)
{
TCHAR filename[200];
TCHAR filename[2*MAX_PATH];
STARTUPINFO start_info;
PROCESS_INFORMATION proc_info;
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
HINSTANCE status;
CLEAR (start_info);
CLEAR (proc_info);
CLEAR (sa);
CLEAR (sd);
/* Try first using file association */
_sntprintf_0(filename, L"%s\\%s", o.conn[config].config_dir, o.conn[config].config_file);
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); /* Safe to init COM multiple times */
status = ShellExecuteW (o.hWnd, L"open", filename, NULL, o.conn[config].config_dir, SW_SHOWNORMAL);
if (status > (HINSTANCE) 32)
return;
else
PrintDebug (L"Opening config file using ShellExecute with verb = open failed"
" for config '%s' (status = %lu)", o.conn[config].config_name, status);
_sntprintf_0(filename, _T("%s \"%s\\%s\""), o.editor, o.conn[config].config_dir, o.conn[config].config_file);
/* fill in STARTUPINFO struct */

Loading…
Cancel
Save