Fixes following pull request discussion

* Proper filter string size
* Copy config to subdirectory
pull/17/head
Leonardo Basilio 2016-02-18 14:03:02 -02:00
parent 01051c51be
commit 4c429d0b6b
1 changed files with 20 additions and 14 deletions

24
main.c
View File

@ -29,7 +29,6 @@
#include <prsht.h> #include <prsht.h>
#include <pbt.h> #include <pbt.h>
#include <commdlg.h> #include <commdlg.h>
#include <shlobj.h>
#include "tray.h" #include "tray.h"
#include "openvpn.h" #include "openvpn.h"
@ -535,11 +534,9 @@ void
ImportConfigFile() ImportConfigFile()
{ {
TCHAR filter[32]; TCHAR filter[37];
memset(filter, 0, sizeof(filter)); _sntprintf_0(filter, _T("*.%s%c*.%s%c"), o.ext_string, _T('\0'), o.ext_string, _T('\0'));
_sntprintf_0(filter, _T("*.%s *.%s"), o.ext_string, o.ext_string);
filter[2 + _tcslen(o.ext_string)] = _T('\0');
OPENFILENAME fn; OPENFILENAME fn;
TCHAR source[MAX_PATH] = _T(""); TCHAR source[MAX_PATH] = _T("");
@ -563,22 +560,31 @@ ImportConfigFile()
TCHAR destination[MAX_PATH]; TCHAR destination[MAX_PATH];
PTCHAR fileName = source + fn.nFileOffset; 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); _sntprintf_0(destination, _T("%s\\%s"), o.config_dir, fileName);
destination[_tcslen(destination) - _tcslen(o.ext_string) - 1] = _T('\0');
if (EnsureDirExists(destination))
{
_sntprintf_0(destination, _T("%s\\%s"), destination, fileName);
if (!CopyFile(source, destination, TRUE)) if (!CopyFile(source, destination, TRUE))
{ {
if (GetLastError() == ERROR_FILE_EXISTS) if (GetLastError() == ERROR_FILE_EXISTS)
{ {
fileName[_tcslen(fileName) - _tcslen(o.ext_string) - 1] = _T('\0'); fileName[_tcslen(fileName) - _tcslen(o.ext_string) - 1] = _T('\0');
ShowLocalizedMsg(IDS_ERR_IMPORT_EXISTS, fileName); ShowLocalizedMsg(IDS_ERR_IMPORT_EXISTS, fileName);
return;
}
} }
else else
ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED); return;
} }
ShowLocalizedMsg(IDS_ERR_IMPORT_FAILED);
} }
} }