fixup PR 76

Signed-off-by: Selva Nair <selva.nair@gmail.com>
pull/76/head
Selva Nair 2016-11-25 23:30:34 -05:00 committed by ValdikSS
parent 20c6ad51a7
commit 46f617259b
5 changed files with 48 additions and 29 deletions

29
main.c
View File

@ -173,10 +173,11 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance,
GetRegistryKeys();
EnsureDirExists(o.config_dir);
/* Parse command-line options */
ProcessCommandLine(&o, GetCommandLine());
EnsureDirExists(o.config_dir);
if (already_running)
{
ShowLocalizedMsg(IDS_ERR_GUI_ALREADY_RUNNING);
@ -540,11 +541,13 @@ ShowConfigFileDialog(PTCHAR config_file)
int dlgresult = 0;
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)
ImportConfigFile(config_file);
else
else if(dlgresult == IDNO)
EditConfig(0, config_file);
else
return;
}
@ -553,7 +556,7 @@ ImportConfigFile(PTCHAR config_file)
{
TCHAR source[MAX_PATH] = _T("");
PTCHAR fileName;
BOOL result = 1;
BOOL result = FALSE;
if (config_file == NULL)
{
@ -577,10 +580,17 @@ ImportConfigFile(PTCHAR config_file)
result = GetOpenFileName(&fn) && (fileName = source + fn.nFileOffset);
}
else
else if(PathFileExists(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)
@ -589,9 +599,9 @@ ImportConfigFile(PTCHAR config_file)
_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);
@ -612,11 +622,8 @@ ImportConfigFile(PTCHAR config_file)
}
}
ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED, destination);
}
}
#ifdef DEBUG

View File

@ -293,6 +293,7 @@
#define IDS_ERR_IMPORT_FAILED 1902
#define IDS_NFO_IMPORT_SUCCESS 1903
#define IDS_ASK_IMPORT_OR_EDIT 1904
#define IDS_ERR_PATH_NOT_FOUND 1905
/* Save password related messages */
#define IDS_NFO_DELETE_PASS 2001

View File

@ -262,6 +262,8 @@ InitOptions(options_t *opt)
CLEAR(*opt);
opt->netcmd_semaphore = InitSemaphore ();
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");
}

View File

@ -431,6 +431,7 @@ BEGIN
IDS_NFO_IMPORT_SUCCESS "File imported successfully."
IDS_ASK_IMPORT_OR_EDIT "Do you want to import ""%s""?\n" \
"Choose ""yes"" to import or ""no"" to edit config file."
IDS_ERR_PATH_NOT_FOUND "Specified path '%s' not found"
/* save/delete password */
IDS_NFO_DELETE_PASS "Press OK to delete saved passwords for config ""%s"""

View File

@ -41,7 +41,7 @@ extern options_t o;
void ViewLog(int config)
{
TCHAR filename[2*MAX_PATH];
TCHAR assocexe[2*MAX_PATH];
TCHAR assocexe[MAX_PATH];
DWORD assocexe_num;
STARTUPINFO start_info;
@ -57,12 +57,14 @@ void ViewLog(int config)
/* Try first using file association */
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)
status = ShellExecuteW (o.hWnd, L"open", assocexe, o.conn[config].log_path, o.log_dir, SW_SHOWNORMAL);
if (status > (HINSTANCE) 32) /* Success */
return;
else
{
assocexe_num = _countof(assocexe);
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);
if (status > (HINSTANCE) 32) /* Success */
@ -72,7 +74,7 @@ void ViewLog(int config)
" 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 */
GetStartupInfo(&start_info);
@ -102,12 +104,12 @@ void ViewLog(int config)
}
/* 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[2*MAX_PATH];
TCHAR config_dir[2*MAX_PATH];
TCHAR assocexe[2*MAX_PATH];
TCHAR fullpath[MAX_PATH];
TCHAR config_dir[MAX_PATH];
TCHAR cmdline[2*MAX_PATH + 3]; /* space for execname, filename and " " */
TCHAR assocexe[MAX_PATH];
DWORD assocexe_num;
STARTUPINFO start_info;
@ -126,29 +128,35 @@ void EditConfig(int config, PTCHAR config_path)
// using "config"
_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_file, o.conn[config].config_file, _countof(config_file) - 1);
}
else
{
// 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);
config_dir[_countof(config_dir) - 1] = '\0';
PathRemoveFileSpec(config_dir);
_tcsncpy(config_file, config_path, _countof(config_file) - 1);
*config_file = PathFindFileName(config_file);
}
/* Try first using file association */
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)
status = ShellExecuteW (o.hWnd, L"open", assocexe, fullpath, config_dir, SW_SHOWNORMAL);
if (status > (HINSTANCE) 32)
return;
{
status = ShellExecuteW (o.hWnd, L"open", assocexe, fullpath, config_dir, SW_SHOWNORMAL);
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
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 */
GetStartupInfo(&start_info);
@ -159,7 +167,7 @@ void EditConfig(int config, PTCHAR config_path)
start_info.hStdOutput = NULL;
if (!CreateProcess(NULL,
fullpath, //commandline
cmdline,
NULL,
NULL,
TRUE,