Merge pull request #47 from selvanair/rescan-configs

Rescan configs
pull/52/head
Samuli Seppänen 2016-05-25 10:02:39 +03:00
commit 03c305bd4b
2 changed files with 20 additions and 17 deletions

View File

@ -62,10 +62,13 @@ match(const WIN32_FIND_DATA *find, const TCHAR *ext)
} }
static bool static bool
CheckReadAccess (const TCHAR *path) CheckReadAccess (const TCHAR *dir, const TCHAR *file)
{ {
HANDLE h; HANDLE h;
bool ret = FALSE; bool ret = FALSE;
TCHAR path[MAX_PATH];
_sntprintf_0 (path, _T("%s\\%s"), dir, file);
h = CreateFile (path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, h = CreateFile (path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
@ -127,7 +130,6 @@ BuildFileList0(const TCHAR *config_dir, bool warn_duplicates)
HANDLE find_handle; HANDLE find_handle;
TCHAR find_string[MAX_PATH]; TCHAR find_string[MAX_PATH];
TCHAR subdir_table[MAX_CONFIG_SUBDIRS][MAX_PATH]; TCHAR subdir_table[MAX_CONFIG_SUBDIRS][MAX_PATH];
TCHAR fullpath[MAX_PATH];
int subdirs = 0; int subdirs = 0;
int i; int i;
@ -148,8 +150,6 @@ BuildFileList0(const TCHAR *config_dir, bool warn_duplicates)
match_t match_type = match(&find_obj, o.ext_string); match_t match_type = match(&find_obj, o.ext_string);
if (match_type == match_file) if (match_type == match_file)
{ {
_sntprintf_0(fullpath, _T("%s\\%s"), config_dir, find_obj.cFileName);
if (ConfigAlreadyExists(find_obj.cFileName)) if (ConfigAlreadyExists(find_obj.cFileName))
{ {
if (warn_duplicates) if (warn_duplicates)
@ -157,7 +157,7 @@ BuildFileList0(const TCHAR *config_dir, bool warn_duplicates)
continue; continue;
} }
if (CheckReadAccess (fullpath)) if (CheckReadAccess (config_dir, find_obj.cFileName))
AddConfigFileToList(o.num_configs++, find_obj.cFileName, config_dir); AddConfigFileToList(o.num_configs++, find_obj.cFileName, config_dir);
} }
else if (match_type == match_dir) else if (match_type == match_dir)
@ -204,7 +204,8 @@ BuildFileList0(const TCHAR *config_dir, bool warn_duplicates)
continue; continue;
} }
AddConfigFileToList(o.num_configs++, find_obj.cFileName, subdir_table[i]); if (CheckReadAccess (subdir_table[i], find_obj.cFileName))
AddConfigFileToList(o.num_configs++, find_obj.cFileName, subdir_table[i]);
} while (FindNextFile(find_handle, &find_obj)); } while (FindNextFile(find_handle, &find_obj));
FindClose(find_handle); FindClose(find_handle);
@ -216,7 +217,13 @@ BuildFileList()
{ {
static bool issue_warnings = true; static bool issue_warnings = true;
o.num_configs = 0; /*
* If no connections are active reset num_configs and rescan
* to make a new list. Else we keep all current configs and
* rescan to add any new one's found
*/
if (CountConnState(disconnected) == o.num_configs)
o.num_configs = 0;
BuildFileList0 (o.config_dir, issue_warnings); BuildFileList0 (o.config_dir, issue_warnings);

16
tray.c
View File

@ -182,8 +182,7 @@ OnNotifyTray(LPARAM lParam)
case WM_RBUTTONUP: case WM_RBUTTONUP:
/* Recreate popup menus */ /* Recreate popup menus */
DestroyPopupMenus(); DestroyPopupMenus();
if (CountConnState(disconnected) == o.num_configs) BuildFileList();
BuildFileList();
CreatePopupMenus(); CreatePopupMenus();
GetCursorPos(&pt); GetCursorPos(&pt);
@ -206,16 +205,13 @@ OnNotifyTray(LPARAM lParam)
else { else {
int disconnected_conns = CountConnState(disconnected); int disconnected_conns = CountConnState(disconnected);
if (disconnected_conns == o.num_configs) { DestroyPopupMenus();
/* Reread configs and recreate menus if no connection is running */ BuildFileList();
DestroyPopupMenus(); CreatePopupMenus();
BuildFileList();
CreatePopupMenus();
/* Start connection if only one config exist */ /* Start connection if only one config exist */
if (o.num_configs == 1 && o.conn[0].state == disconnected) if (o.num_configs == 1 && o.conn[0].state == disconnected)
StartOpenVPN(&o.conn[0]); StartOpenVPN(&o.conn[0]);
}
else if (disconnected_conns == o.num_configs - 1) { else if (disconnected_conns == o.num_configs - 1) {
/* Show status window if only one connection is running */ /* Show status window if only one connection is running */
int i; int i;