Skip to content

Commit

Permalink
refactor option handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
d12fk committed Apr 9, 2010
1 parent b0c1bd5 commit a6e6d88
Show file tree
Hide file tree
Showing 18 changed files with 632 additions and 648 deletions.
2 changes: 1 addition & 1 deletion localization.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "options.h"
#include "registry.h"

extern struct options o;
extern options_t o;

static const LANGID fallbackLangId = MAKELANGID(LANG_ENGLISH, SUBLANG_NEUTRAL);
static LANGID gui_language;
Expand Down
20 changes: 10 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ TCHAR szClassName[ ] = _T("OpenVPN-GUI");
TCHAR szTitleText[ ] = _T("OpenVPN");

/* Options structure */
struct options o;
options_t o;

int WINAPI WinMain (HINSTANCE hThisInstance,
UNUSED HINSTANCE hPrevInstance,
Expand All @@ -68,7 +68,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance,


/* initialize options to default state */
init_options (&o);
InitOptions(&o);

#ifdef DEBUG
/* Open debug file for output */
Expand Down Expand Up @@ -109,7 +109,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance,


/* Parse command-line options */
Createargcargv(&o, GetCommandLine());
ProcessCommandLine(&o, GetCommandLine());

/* Check if a previous instance is already running. */
if ((FindWindow (szClassName, NULL)) != NULL)
Expand Down Expand Up @@ -224,7 +224,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
StopOpenVPN(LOWORD(wParam) - IDM_DISCONNECTMENU);
}
if ( (LOWORD(wParam) >= IDM_STATUSMENU) && (LOWORD(wParam) < IDM_STATUSMENU + MAX_CONFIGS) ) {
ShowWindow(o.cnn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW);
ShowWindow(o.conn[LOWORD(wParam) - IDM_STATUSMENU].hwndStatus, SW_SHOW);
}
if ( (LOWORD(wParam) >= IDM_VIEWLOGMENU) && (LOWORD(wParam) < IDM_VIEWLOGMENU + MAX_CONFIGS) ) {
ViewLog(LOWORD(wParam) - IDM_VIEWLOGMENU);
Expand Down Expand Up @@ -281,13 +281,13 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
/* Suspend running connections */
for (i=0; i<o.num_configs; i++)
{
if (o.cnn[i].connect_status == CONNECTED)
if (o.conn[i].state == connected)
SuspendOpenVPN(i);
}

/* Wait for all connections to suspend */
for (i=0; i<10; i++, Sleep(500))
if (CountConnectedState(SUSPENDING) == 0) break;
if (CountConnState(suspending) == 0) break;
}
return FALSE;

Expand All @@ -296,11 +296,11 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
for (i=0; i<o.num_configs; i++)
{
/* Restart suspend connections */
if (o.cnn[i].connect_status == SUSPENDED)
if (o.conn[i].state == suspended)
StartOpenVPN(i);

/* If some connection never reached SUSPENDED state */
if (o.cnn[i].connect_status == SUSPENDING)
if (o.conn[i].state == suspending)
StopOpenVPN(i);
}
return FALSE;
Expand Down Expand Up @@ -392,7 +392,7 @@ void CloseApplication(HWND hwnd)
{
int i, ask_exit=0;

if (o.service_running == SERVICE_CONNECTED)
if (o.service_state == service_connected)
{
if (MessageBox(NULL, LoadLocalizedString(IDS_NFO_SERVICE_ACTIVE_EXIT), _T("Exit OpenVPN"), MB_YESNO) == IDNO)
{
Expand All @@ -401,7 +401,7 @@ void CloseApplication(HWND hwnd)
}

for (i=0; i < o.num_configs; i++) {
if (o.cnn[i].connect_status != 0) {
if (o.conn[i].state != disconnected) {
ask_exit=1;
break;
}
Expand Down
Loading

0 comments on commit a6e6d88

Please sign in to comment.