mirror of https://github.com/OpenVPN/openvpn-gui
Fixes following pull request discussion
* Proper filter string size * Copy config to subdirectorypull/17/head
parent
01051c51be
commit
4c429d0b6b
34
main.c
34
main.c
|
@ -29,7 +29,6 @@
|
|||
#include <prsht.h>
|
||||
#include <pbt.h>
|
||||
#include <commdlg.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
#include "tray.h"
|
||||
#include "openvpn.h"
|
||||
|
@ -535,11 +534,9 @@ void
|
|||
ImportConfigFile()
|
||||
{
|
||||
|
||||
TCHAR filter[32];
|
||||
TCHAR filter[37];
|
||||
|
||||
memset(filter, 0, sizeof(filter));
|
||||
_sntprintf_0(filter, _T("*.%s *.%s"), o.ext_string, o.ext_string);
|
||||
filter[2 + _tcslen(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("");
|
||||
|
@ -559,26 +556,35 @@ ImportConfigFile()
|
|||
|
||||
if (GetOpenFileName(&fn))
|
||||
{
|
||||
|
||||
|
||||
TCHAR destination[MAX_PATH];
|
||||
PTCHAR fileName = source + fn.nFileOffset;
|
||||
|
||||
/* make sure full config path exists */
|
||||
SHCreateDirectoryEx(NULL, o.config_dir, NULL);
|
||||
|
||||
_sntprintf_0(destination, _T("%s\\%s"), o.config_dir, fileName);
|
||||
|
||||
destination[_tcslen(destination) - _tcslen(o.ext_string) - 1] = _T('\0');
|
||||
|
||||
if (!CopyFile(source, destination, TRUE))
|
||||
if (EnsureDirExists(destination))
|
||||
{
|
||||
if (GetLastError() == ERROR_FILE_EXISTS)
|
||||
|
||||
_sntprintf_0(destination, _T("%s\\%s"), destination, fileName);
|
||||
|
||||
if (!CopyFile(source, destination, TRUE))
|
||||
{
|
||||
fileName[_tcslen(fileName) - _tcslen(o.ext_string) - 1] = _T('\0');
|
||||
ShowLocalizedMsg(IDS_ERR_IMPORT_EXISTS, fileName);
|
||||
if (GetLastError() == ERROR_FILE_EXISTS)
|
||||
{
|
||||
fileName[_tcslen(fileName) - _tcslen(o.ext_string) - 1] = _T('\0');
|
||||
ShowLocalizedMsg(IDS_ERR_IMPORT_EXISTS, fileName);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue