mirror of https://github.com/OpenVPN/openvpn-gui
parent
20c6ad51a7
commit
46f617259b
29
main.c
29
main.c
|
@ -173,10 +173,11 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance,
|
||||||
|
|
||||||
GetRegistryKeys();
|
GetRegistryKeys();
|
||||||
|
|
||||||
EnsureDirExists(o.config_dir);
|
|
||||||
/* Parse command-line options */
|
/* Parse command-line options */
|
||||||
ProcessCommandLine(&o, GetCommandLine());
|
ProcessCommandLine(&o, GetCommandLine());
|
||||||
|
|
||||||
|
EnsureDirExists(o.config_dir);
|
||||||
|
|
||||||
if (already_running)
|
if (already_running)
|
||||||
{
|
{
|
||||||
ShowLocalizedMsg(IDS_ERR_GUI_ALREADY_RUNNING);
|
ShowLocalizedMsg(IDS_ERR_GUI_ALREADY_RUNNING);
|
||||||
|
@ -540,11 +541,13 @@ ShowConfigFileDialog(PTCHAR config_file)
|
||||||
int dlgresult = 0;
|
int dlgresult = 0;
|
||||||
|
|
||||||
fileName = PathFindFileName(config_file);
|
fileName = PathFindFileName(config_file);
|
||||||
dlgresult = ShowLocalizedMsgEx(MB_YESNO, _T(PACKAGE_NAME), IDS_ASK_IMPORT_OR_EDIT, fileName);
|
dlgresult = ShowLocalizedMsgEx(MB_YESNOCANCEL, _T(PACKAGE_NAME), IDS_ASK_IMPORT_OR_EDIT, fileName);
|
||||||
if (dlgresult == IDYES)
|
if (dlgresult == IDYES)
|
||||||
ImportConfigFile(config_file);
|
ImportConfigFile(config_file);
|
||||||
else
|
else if(dlgresult == IDNO)
|
||||||
EditConfig(0, config_file);
|
EditConfig(0, config_file);
|
||||||
|
else
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -553,7 +556,7 @@ ImportConfigFile(PTCHAR config_file)
|
||||||
{
|
{
|
||||||
TCHAR source[MAX_PATH] = _T("");
|
TCHAR source[MAX_PATH] = _T("");
|
||||||
PTCHAR fileName;
|
PTCHAR fileName;
|
||||||
BOOL result = 1;
|
BOOL result = FALSE;
|
||||||
|
|
||||||
if (config_file == NULL)
|
if (config_file == NULL)
|
||||||
{
|
{
|
||||||
|
@ -577,10 +580,17 @@ ImportConfigFile(PTCHAR config_file)
|
||||||
|
|
||||||
result = GetOpenFileName(&fn) && (fileName = source + fn.nFileOffset);
|
result = GetOpenFileName(&fn) && (fileName = source + fn.nFileOffset);
|
||||||
}
|
}
|
||||||
else
|
else if(PathFileExists(config_file))
|
||||||
{
|
{
|
||||||
fileName = PathFindFileName(config_file);
|
fileName = PathFindFileName(config_file);
|
||||||
_tcscpy(source, config_file);
|
_sntprintf_0(source, L"%s", config_file);
|
||||||
|
result = TRUE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowLocalizedMsg(IDS_ERR_PATH_NOT_FOUND, config_file);
|
||||||
|
PrintDebug(L"The file specified for import does not exist: '%s'", config_file);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
|
@ -589,9 +599,9 @@ ImportConfigFile(PTCHAR config_file)
|
||||||
|
|
||||||
_sntprintf_0(destination, _T("%s\\%s"), o.config_dir, fileName);
|
_sntprintf_0(destination, _T("%s\\%s"), o.config_dir, fileName);
|
||||||
|
|
||||||
destination[_tcslen(destination) - _tcslen(o.ext_string) - 1] = _T('\0');
|
PathRemoveExtension(destination);
|
||||||
|
|
||||||
if (EnsureDirExists(destination) && EnsureDirExists(o.config_dir))
|
if (EnsureDirExists(destination))
|
||||||
{
|
{
|
||||||
|
|
||||||
_sntprintf_0(destination, _T("%s\\%s"), destination, fileName);
|
_sntprintf_0(destination, _T("%s\\%s"), destination, fileName);
|
||||||
|
@ -612,11 +622,8 @@ ImportConfigFile(PTCHAR config_file)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED, destination);
|
ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED, destination);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
|
@ -293,6 +293,7 @@
|
||||||
#define IDS_ERR_IMPORT_FAILED 1902
|
#define IDS_ERR_IMPORT_FAILED 1902
|
||||||
#define IDS_NFO_IMPORT_SUCCESS 1903
|
#define IDS_NFO_IMPORT_SUCCESS 1903
|
||||||
#define IDS_ASK_IMPORT_OR_EDIT 1904
|
#define IDS_ASK_IMPORT_OR_EDIT 1904
|
||||||
|
#define IDS_ERR_PATH_NOT_FOUND 1905
|
||||||
|
|
||||||
/* Save password related messages */
|
/* Save password related messages */
|
||||||
#define IDS_NFO_DELETE_PASS 2001
|
#define IDS_NFO_DELETE_PASS 2001
|
||||||
|
|
|
@ -262,6 +262,8 @@ InitOptions(options_t *opt)
|
||||||
CLEAR(*opt);
|
CLEAR(*opt);
|
||||||
opt->netcmd_semaphore = InitSemaphore ();
|
opt->netcmd_semaphore = InitSemaphore ();
|
||||||
opt->version = MakeVersion (PACKAGE_VERSION_RESOURCE);
|
opt->version = MakeVersion (PACKAGE_VERSION_RESOURCE);
|
||||||
|
/* An editor to fall back to if associated exec not found*/
|
||||||
|
_sntprintf_0(opt->editor, L"%s", L"C:\\Windows\\system32\\notepad.exe");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -431,6 +431,7 @@ BEGIN
|
||||||
IDS_NFO_IMPORT_SUCCESS "File imported successfully."
|
IDS_NFO_IMPORT_SUCCESS "File imported successfully."
|
||||||
IDS_ASK_IMPORT_OR_EDIT "Do you want to import ""%s""?\n" \
|
IDS_ASK_IMPORT_OR_EDIT "Do you want to import ""%s""?\n" \
|
||||||
"Choose ""yes"" to import or ""no"" to edit config file."
|
"Choose ""yes"" to import or ""no"" to edit config file."
|
||||||
|
IDS_ERR_PATH_NOT_FOUND "Specified path '%s' not found"
|
||||||
|
|
||||||
/* save/delete password */
|
/* save/delete password */
|
||||||
IDS_NFO_DELETE_PASS "Press OK to delete saved passwords for config ""%s"""
|
IDS_NFO_DELETE_PASS "Press OK to delete saved passwords for config ""%s"""
|
||||||
|
|
44
viewlog.c
44
viewlog.c
|
@ -41,7 +41,7 @@ extern options_t o;
|
||||||
void ViewLog(int config)
|
void ViewLog(int config)
|
||||||
{
|
{
|
||||||
TCHAR filename[2*MAX_PATH];
|
TCHAR filename[2*MAX_PATH];
|
||||||
TCHAR assocexe[2*MAX_PATH];
|
TCHAR assocexe[MAX_PATH];
|
||||||
DWORD assocexe_num;
|
DWORD assocexe_num;
|
||||||
|
|
||||||
STARTUPINFO start_info;
|
STARTUPINFO start_info;
|
||||||
|
@ -57,12 +57,14 @@ void ViewLog(int config)
|
||||||
|
|
||||||
/* Try first using file association */
|
/* Try first using file association */
|
||||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); /* Safe to init COM multiple times */
|
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); /* Safe to init COM multiple times */
|
||||||
|
assocexe_num = _countof(assocexe);
|
||||||
if (AssocQueryString(0, ASSOCSTR_EXECUTABLE, L".log", NULL, assocexe, &assocexe_num) == S_OK)
|
if (AssocQueryString(0, ASSOCSTR_EXECUTABLE, L".log", NULL, assocexe, &assocexe_num) == S_OK)
|
||||||
status = ShellExecuteW (o.hWnd, L"open", assocexe, o.conn[config].log_path, o.log_dir, SW_SHOWNORMAL);
|
status = ShellExecuteW (o.hWnd, L"open", assocexe, o.conn[config].log_path, o.log_dir, SW_SHOWNORMAL);
|
||||||
if (status > (HINSTANCE) 32) /* Success */
|
if (status > (HINSTANCE) 32) /* Success */
|
||||||
return;
|
return;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
assocexe_num = _countof(assocexe);
|
||||||
if (AssocQueryString(0, ASSOCSTR_EXECUTABLE, L".txt", NULL, assocexe, &assocexe_num) == S_OK)
|
if (AssocQueryString(0, ASSOCSTR_EXECUTABLE, L".txt", NULL, assocexe, &assocexe_num) == S_OK)
|
||||||
status = ShellExecuteW (o.hWnd, L"open", assocexe, o.conn[config].log_path, o.log_dir, SW_SHOWNORMAL);
|
status = ShellExecuteW (o.hWnd, L"open", assocexe, o.conn[config].log_path, o.log_dir, SW_SHOWNORMAL);
|
||||||
if (status > (HINSTANCE) 32) /* Success */
|
if (status > (HINSTANCE) 32) /* Success */
|
||||||
|
@ -72,7 +74,7 @@ void ViewLog(int config)
|
||||||
" for config '%s' (status = %lu)", o.conn[config].config_name, status);
|
" 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);
|
_sntprintf_0(filename, _T("\"%s\" \"%s\""), o.log_viewer, o.conn[config].log_path);
|
||||||
|
|
||||||
/* fill in STARTUPINFO struct */
|
/* fill in STARTUPINFO struct */
|
||||||
GetStartupInfo(&start_info);
|
GetStartupInfo(&start_info);
|
||||||
|
@ -102,12 +104,12 @@ void ViewLog(int config)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* either config or config_path */
|
/* either config or config_path */
|
||||||
void EditConfig(int config, PTCHAR config_path)
|
void EditConfig(int config, const PTCHAR config_path)
|
||||||
{
|
{
|
||||||
TCHAR config_file[2*MAX_PATH];
|
TCHAR fullpath[MAX_PATH];
|
||||||
TCHAR fullpath[2*MAX_PATH];
|
TCHAR config_dir[MAX_PATH];
|
||||||
TCHAR config_dir[2*MAX_PATH];
|
TCHAR cmdline[2*MAX_PATH + 3]; /* space for execname, filename and " " */
|
||||||
TCHAR assocexe[2*MAX_PATH];
|
TCHAR assocexe[MAX_PATH];
|
||||||
DWORD assocexe_num;
|
DWORD assocexe_num;
|
||||||
|
|
||||||
STARTUPINFO start_info;
|
STARTUPINFO start_info;
|
||||||
|
@ -126,29 +128,35 @@ void EditConfig(int config, PTCHAR config_path)
|
||||||
// using "config"
|
// using "config"
|
||||||
_sntprintf_0(fullpath, L"%s\\%s", o.conn[config].config_dir, o.conn[config].config_file);
|
_sntprintf_0(fullpath, L"%s\\%s", o.conn[config].config_dir, o.conn[config].config_file);
|
||||||
_tcsncpy(config_dir, o.conn[config].config_dir, _countof(config_dir) - 1);
|
_tcsncpy(config_dir, o.conn[config].config_dir, _countof(config_dir) - 1);
|
||||||
_tcsncpy(config_file, o.conn[config].config_file, _countof(config_file) - 1);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// using "config_path"
|
// using "config_path"
|
||||||
_tcsncpy(fullpath, config_path, _countof(config_dir) - 1);
|
_tcsncpy(fullpath, config_path, _countof(fullpath) - 1);
|
||||||
|
fullpath[_countof(fullpath) - 1] = '\0';
|
||||||
_tcsncpy(config_dir, config_path, _countof(config_dir) - 1);
|
_tcsncpy(config_dir, config_path, _countof(config_dir) - 1);
|
||||||
|
config_dir[_countof(config_dir) - 1] = '\0';
|
||||||
PathRemoveFileSpec(config_dir);
|
PathRemoveFileSpec(config_dir);
|
||||||
_tcsncpy(config_file, config_path, _countof(config_file) - 1);
|
|
||||||
*config_file = PathFindFileName(config_file);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try first using file association */
|
/* Try first using file association */
|
||||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); /* Safe to init COM multiple times */
|
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); /* Safe to init COM multiple times */
|
||||||
|
assocexe_num = _countof(assocexe);
|
||||||
if (AssocQueryString(0, ASSOCSTR_EXECUTABLE, L".txt", NULL, assocexe, &assocexe_num) == S_OK)
|
if (AssocQueryString(0, ASSOCSTR_EXECUTABLE, L".txt", NULL, assocexe, &assocexe_num) == S_OK)
|
||||||
status = ShellExecuteW (o.hWnd, L"open", assocexe, fullpath, config_dir, SW_SHOWNORMAL);
|
{
|
||||||
if (status > (HINSTANCE) 32)
|
status = ShellExecuteW (o.hWnd, L"open", assocexe, fullpath, config_dir, SW_SHOWNORMAL);
|
||||||
return;
|
if (status > (HINSTANCE) 32)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
PrintDebug (L"Opening config file using ShellExecute with verb = open failed"
|
||||||
|
" for config '%s' using exec = '%s' (status = %lu)", fullpath, assocexe, status);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
PrintDebug (L"Opening config file using ShellExecute with verb = open failed"
|
{
|
||||||
" for config '%s' (status = %lu)", config_file, status);
|
PrintDebug (L"Querying associated exec for .txt failed");
|
||||||
|
}
|
||||||
|
|
||||||
_sntprintf_0(fullpath, _T("%s \"%s\""), o.editor, fullpath);
|
_sntprintf_0(cmdline, _T("\"%s\" \"%s\""), o.editor, fullpath);
|
||||||
|
|
||||||
/* fill in STARTUPINFO struct */
|
/* fill in STARTUPINFO struct */
|
||||||
GetStartupInfo(&start_info);
|
GetStartupInfo(&start_info);
|
||||||
|
@ -159,7 +167,7 @@ void EditConfig(int config, PTCHAR config_path)
|
||||||
start_info.hStdOutput = NULL;
|
start_info.hStdOutput = NULL;
|
||||||
|
|
||||||
if (!CreateProcess(NULL,
|
if (!CreateProcess(NULL,
|
||||||
fullpath, //commandline
|
cmdline,
|
||||||
NULL,
|
NULL,
|
||||||
NULL,
|
NULL,
|
||||||
TRUE,
|
TRUE,
|
||||||
|
|
Loading…
Reference in New Issue