mirror of https://github.com/OpenVPN/openvpn-gui
Functionality to import configuration file from the command line
parent
c3099acc59
commit
9be38622e0
|
@ -59,7 +59,6 @@
|
||||||
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
|
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
|
||||||
static void ShowSettingsDialog();
|
static void ShowSettingsDialog();
|
||||||
void CloseApplication(HWND hwnd);
|
void CloseApplication(HWND hwnd);
|
||||||
void ImportConfigFile();
|
|
||||||
|
|
||||||
/* Class name and window title */
|
/* Class name and window title */
|
||||||
TCHAR szClassName[ ] = _T("OpenVPN-GUI");
|
TCHAR szClassName[ ] = _T("OpenVPN-GUI");
|
||||||
|
@ -160,6 +159,8 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance,
|
||||||
PrintDebug(_T("Shell32.dll version: 0x%lx"), shell32_version);
|
PrintDebug(_T("Shell32.dll version: 0x%lx"), shell32_version);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Parse command-line options */
|
||||||
|
ProcessCommandLine(&o, GetCommandLine());
|
||||||
|
|
||||||
/* Check if a previous instance is already running. */
|
/* Check if a previous instance is already running. */
|
||||||
if ((FindWindow (szClassName, NULL)) != NULL)
|
if ((FindWindow (szClassName, NULL)) != NULL)
|
||||||
|
@ -172,8 +173,6 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance,
|
||||||
UpdateRegistry(); /* Checks version change and update keys/values */
|
UpdateRegistry(); /* Checks version change and update keys/values */
|
||||||
|
|
||||||
GetRegistryKeys();
|
GetRegistryKeys();
|
||||||
/* Parse command-line options */
|
|
||||||
ProcessCommandLine(&o, GetCommandLine());
|
|
||||||
|
|
||||||
EnsureDirExists(o.config_dir);
|
EnsureDirExists(o.config_dir);
|
||||||
|
|
||||||
|
@ -364,7 +363,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (LOWORD(wParam) == IDM_IMPORT) {
|
if (LOWORD(wParam) == IDM_IMPORT) {
|
||||||
ImportConfigFile();
|
ImportConfigFile(NULL);
|
||||||
}
|
}
|
||||||
if (LOWORD(wParam) == IDM_SETTINGS) {
|
if (LOWORD(wParam) == IDM_SETTINGS) {
|
||||||
ShowSettingsDialog();
|
ShowSettingsDialog();
|
||||||
|
@ -528,16 +527,19 @@ CloseApplication(HWND hwnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ImportConfigFile()
|
ImportConfigFile(PTCHAR config_file)
|
||||||
{
|
{
|
||||||
|
TCHAR source[MAX_PATH] = _T("");
|
||||||
|
PTCHAR fileName;
|
||||||
|
BOOL dlgresult;
|
||||||
|
|
||||||
|
if (config_file == NULL)
|
||||||
|
{
|
||||||
|
OPENFILENAME fn;
|
||||||
TCHAR filter[2*_countof(o.ext_string)+5];
|
TCHAR filter[2*_countof(o.ext_string)+5];
|
||||||
|
|
||||||
_sntprintf_0(filter, _T("*.%s%c*.%s%c"), o.ext_string, _T('\0'), o.ext_string, _T('\0'));
|
_sntprintf_0(filter, _T("*.%s%c*.%s%c"), o.ext_string, _T('\0'), o.ext_string, _T('\0'));
|
||||||
|
|
||||||
OPENFILENAME fn;
|
|
||||||
TCHAR source[MAX_PATH] = _T("");
|
|
||||||
|
|
||||||
fn.lStructSize = sizeof(OPENFILENAME);
|
fn.lStructSize = sizeof(OPENFILENAME);
|
||||||
fn.hwndOwner = NULL;
|
fn.hwndOwner = NULL;
|
||||||
fn.lpstrFilter = filter;
|
fn.lpstrFilter = filter;
|
||||||
|
@ -551,11 +553,18 @@ ImportConfigFile()
|
||||||
fn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
|
fn.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST;
|
||||||
fn.lpstrDefExt = NULL;
|
fn.lpstrDefExt = NULL;
|
||||||
|
|
||||||
if (GetOpenFileName(&fn))
|
dlgresult = GetOpenFileName(&fn) && (fileName = source + fn.nFileOffset);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
|
fileName = PathFindFileName(config_file);
|
||||||
|
dlgresult = ShowLocalizedMsgEx(MB_YESNO, _T(PACKAGE_NAME), IDS_ASK_IMPORT_CONFIRM, fileName) == IDYES;
|
||||||
|
_tcscpy(source, config_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dlgresult)
|
||||||
|
{
|
||||||
TCHAR destination[MAX_PATH];
|
TCHAR destination[MAX_PATH];
|
||||||
PTCHAR fileName = source + fn.nFileOffset;
|
|
||||||
|
|
||||||
_sntprintf_0(destination, _T("%s\\%s"), o.config_dir, fileName);
|
_sntprintf_0(destination, _T("%s\\%s"), o.config_dir, fileName);
|
||||||
|
|
||||||
|
@ -570,7 +579,7 @@ ImportConfigFile()
|
||||||
{
|
{
|
||||||
if (GetLastError() == ERROR_FILE_EXISTS)
|
if (GetLastError() == ERROR_FILE_EXISTS)
|
||||||
{
|
{
|
||||||
fileName[_tcslen(fileName) - _tcslen(o.ext_string) - 1] = _T('\0');
|
PathRemoveExtension(fileName);
|
||||||
ShowLocalizedMsg(IDS_ERR_IMPORT_EXISTS, fileName);
|
ShowLocalizedMsg(IDS_ERR_IMPORT_EXISTS, fileName);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,4 +114,6 @@ void PrintDebugMsg(TCHAR *msg);
|
||||||
|
|
||||||
DWORD GetDllVersion(LPCTSTR lpszDllName);
|
DWORD GetDllVersion(LPCTSTR lpszDllName);
|
||||||
|
|
||||||
|
void ImportConfigFile(PTCHAR);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -292,6 +292,7 @@
|
||||||
#define IDS_ERR_IMPORT_EXISTS 1901
|
#define IDS_ERR_IMPORT_EXISTS 1901
|
||||||
#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_CONFIRM 1904
|
||||||
|
|
||||||
/* Save password related messages */
|
/* Save password related messages */
|
||||||
#define IDS_NFO_DELETE_PASS 2001
|
#define IDS_NFO_DELETE_PASS 2001
|
||||||
|
|
|
@ -87,6 +87,11 @@ add_option(options_t *options, int i, TCHAR **p)
|
||||||
ShowLocalizedMsgEx(MB_OK, caption, IDS_NFO_USAGE);
|
ShowLocalizedMsgEx(MB_OK, caption, IDS_NFO_USAGE);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
else if (streq(p[0], _T("import")) && p[1])
|
||||||
|
{
|
||||||
|
ImportConfigFile(p[1]);
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
else if (streq(p[0], _T("connect")) && p[1])
|
else if (streq(p[0], _T("connect")) && p[1])
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
|
|
|
@ -429,6 +429,7 @@ BEGIN
|
||||||
IDS_ERR_IMPORT_FAILED "Failed to import file. The following path could not be created.\n\n" \
|
IDS_ERR_IMPORT_FAILED "Failed to import file. The following path could not be created.\n\n" \
|
||||||
"%s\n\nMake sure you have the right permissions."
|
"%s\n\nMake sure you have the right permissions."
|
||||||
IDS_NFO_IMPORT_SUCCESS "File imported successfully."
|
IDS_NFO_IMPORT_SUCCESS "File imported successfully."
|
||||||
|
IDS_ASK_IMPORT_CONFIRM "Do you want to import file ""%s""?"
|
||||||
|
|
||||||
/* 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"""
|
||||||
|
|
Loading…
Reference in New Issue