switched to use of localization functions

pull/1/head
Heiko Hund 2009-01-18 20:59:52 +00:00
parent 1ea8d5b8f7
commit 3d4aaeb5a4
11 changed files with 181 additions and 277 deletions

25
main.c
View File

@ -33,6 +33,7 @@
#include "proxy.h" #include "proxy.h"
#include "registry.h" #include "registry.h"
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "localization.h"
#ifndef DISABLE_CHANGE_PASSWORD #ifndef DISABLE_CHANGE_PASSWORD
#include <openssl/evp.h> #include <openssl/evp.h>
@ -87,7 +88,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
else else
{ {
/* can't load riched20.dll */ /* can't load riched20.dll */
ShowLocalizedMsg(GUI_NAME, ERR_LOAD_RICHED20, ""); ShowLocalizedMsg(GUI_NAME, ERR_LOAD_RICHED20);
exit(1); exit(1);
} }
@ -111,7 +112,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
if ((FindWindow (szClassName, NULL)) != NULL) if ((FindWindow (szClassName, NULL)) != NULL)
{ {
/* GUI already running */ /* GUI already running */
ShowLocalizedMsg(GUI_NAME, ERR_GUI_ALREADY_RUNNING, ""); ShowLocalizedMsg(GUI_NAME, ERR_GUI_ALREADY_RUNNING);
exit(1); exit(1);
} }
@ -143,8 +144,8 @@ int WINAPI WinMain (HINSTANCE hThisInstance,
wincl.cbSize = sizeof (WNDCLASSEX); wincl.cbSize = sizeof (WNDCLASSEX);
/* Use default icon and mouse-pointer */ /* Use default icon and mouse-pointer */
wincl.hIcon = LoadIcon (hThisInstance, MAKEINTRESOURCE(APP_ICON)); wincl.hIcon = LoadLocalizedIcon(APP_ICON);
wincl.hIconSm = LoadIcon (hThisInstance, MAKEINTRESOURCE(APP_ICON)); wincl.hIconSm = LoadLocalizedIcon(APP_ICON);
wincl.hCursor = LoadCursor (NULL, IDC_ARROW); wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
wincl.lpszMenuName = NULL; /* No menu */ wincl.lpszMenuName = NULL; /* No menu */
wincl.cbClsExtra = 0; /* No extra bytes after the window class */ wincl.cbClsExtra = 0; /* No extra bytes after the window class */
@ -239,7 +240,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
ShowProxySettingsDialog(); ShowProxySettingsDialog();
} }
if (LOWORD(wParam) == IDM_ABOUT) { if (LOWORD(wParam) == IDM_ABOUT) {
DialogBox(o.hInstance, (LPCTSTR)IDD_ABOUTDIALOG, NULL, (DLGPROC)AboutDialogFunc); LocalizedDialogBox(IDD_ABOUTDIALOG, AboutDialogFunc);
} }
if (LOWORD(wParam) == IDM_CLOSE) { if (LOWORD(wParam) == IDM_CLOSE) {
CloseApplication(hwnd); CloseApplication(hwnd);
@ -323,22 +324,18 @@ BOOL CALLBACK AboutDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPA
{ {
HICON hIcon; HICON hIcon;
TCHAR buf[1000]; TCHAR buf[1000];
char buf2[1000];
switch (msg) { switch (msg) {
case WM_INITDIALOG: case WM_INITDIALOG:
hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(APP_ICON), hIcon = LoadLocalizedIcon(APP_ICON);
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
if (hIcon) { if (hIcon) {
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon)); SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon));
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon)); SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon));
} }
/* Show version string */ /* Show version string */
myLoadString(TEXT_ABOUT_OPENVPNGUI); SetDlgItemText(hwndDlg, ID_TEXT_OPENVPNGUI, LoadLocalizedString(TEXT_ABOUT_OPENVPNGUI, GUI_VERSION));
mysnprintf(buf2, buf, GUI_VERSION);
SetDlgItemText(hwndDlg, ID_TEXT_OPENVPNGUI, buf2);
return FALSE; return FALSE;
@ -365,8 +362,7 @@ void CloseApplication(HWND hwnd)
if (o.service_running == SERVICE_CONNECTED) if (o.service_running == SERVICE_CONNECTED)
{ {
myLoadString(INFO_SERVICE_ACTIVE_EXIT); if (MessageBox(NULL, LoadLocalizedString(INFO_SERVICE_ACTIVE_EXIT), "Exit OpenVPN", MB_YESNO) == IDNO)
if (MessageBox(NULL, buf, "Exit OpenVPN", MB_YESNO) == IDNO)
{ {
return; return;
} }
@ -380,8 +376,7 @@ void CloseApplication(HWND hwnd)
} }
if (ask_exit) { if (ask_exit) {
/* aks for confirmation */ /* aks for confirmation */
myLoadString(INFO_ACTIVE_CONN_EXIT); if (MessageBox(NULL, LoadLocalizedString(INFO_ACTIVE_CONN_EXIT), "Exit OpenVPN", MB_YESNO) == IDNO)
if (MessageBox(NULL, buf, "Exit OpenVPN", MB_YESNO) == IDNO)
{ {
return; return;
} }

22
main.h
View File

@ -69,28 +69,6 @@ struct security_attributes
out [sizeof (out) - 1] = '\0'; \ out [sizeof (out) - 1] = '\0'; \
} }
/* Show Message */
#define ShowMsg(caption, args...) \
{ \
char x_msg[256]; \
mysnprintf (x_msg, args); \
MessageBox(NULL, x_msg, caption, MB_OK | MB_SETFOREGROUND); \
}
#define ShowLocalizedMsg(caption, id, args...) \
{ \
char x_msg[256]; \
TCHAR x_buf[1000]; \
LoadString(o.hInstance, id, x_buf, sizeof(x_buf)/sizeof(TCHAR)); \
mysnprintf(x_msg, x_buf, args); \
MessageBox(NULL, x_msg, caption, MB_OK | MB_SETFOREGROUND); \
}
#define myLoadString(id) \
{ \
LoadString(o.hInstance, id, buf, sizeof(buf)/sizeof(TCHAR)); \
}
#ifdef DEBUG #ifdef DEBUG
/* Print Debug Message */ /* Print Debug Message */
#define PrintDebug(args...) \ #define PrintDebug(args...) \

View File

@ -38,6 +38,7 @@
#include "viewlog.h" #include "viewlog.h"
#include "proxy.h" #include "proxy.h"
#include "passphrase.h" #include "passphrase.h"
#include "localization.h"
#include <richedit.h> #include <richedit.h>
extern struct options o; extern struct options o;
@ -61,7 +62,7 @@ int CreateExitEvent(int config)
if (GetLastError() == ERROR_ACCESS_DENIED) if (GetLastError() == ERROR_ACCESS_DENIED)
{ {
/* service mustn't be running, while using old version */ /* service mustn't be running, while using old version */
ShowLocalizedMsg(GUI_NAME, ERR_STOP_SERV_ON_OLD_VERSION, ""); ShowLocalizedMsg(GUI_NAME, ERR_STOP_SERV_ON_OLD_VERSION);
} }
else else
{ {
@ -168,7 +169,7 @@ int StartOpenVPN(int config)
if (is_connected) if (is_connected)
{ {
/* only one simultanious connection on old version */ /* only one simultanious connection on old version */
ShowLocalizedMsg(GUI_NAME, ERR_ONLY_ONE_CONN_OLD_VERSION, ""); ShowLocalizedMsg(GUI_NAME, ERR_ONLY_ONE_CONN_OLD_VERSION);
return(false); return(false);
} }
} }
@ -178,8 +179,7 @@ int StartOpenVPN(int config)
(ConfigFileOptionExist(config, "log-append "))) (ConfigFileOptionExist(config, "log-append ")))
{ {
TCHAR buf[1000]; TCHAR buf[1000];
myLoadString(ERR_OPTION_LOG_IN_CONFIG); if (MessageBox(NULL, LoadLocalizedString(ERR_OPTION_LOG_IN_CONFIG), GUI_NAME, MB_YESNO | MB_DEFBUTTON2 | MB_ICONWARNING) != IDYES)
if (MessageBox(NULL, buf, GUI_NAME, MB_YESNO | MB_DEFBUTTON2 | MB_ICONWARNING) != IDYES)
return(false); return(false);
} }
@ -229,13 +229,13 @@ int StartOpenVPN(int config)
if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION)) if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION))
{ {
/* Init Sec. Desc. failed */ /* Init Sec. Desc. failed */
ShowLocalizedMsg (GUI_NAME, ERR_INIT_SEC_DESC, ""); ShowLocalizedMsg (GUI_NAME, ERR_INIT_SEC_DESC);
goto failed; goto failed;
} }
if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE)) if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE))
{ {
/* set Dacl failed */ /* set Dacl failed */
ShowLocalizedMsg (GUI_NAME, ERR_SET_SEC_DESC_ACL, ""); ShowLocalizedMsg (GUI_NAME, ERR_SET_SEC_DESC_ACL);
goto failed; goto failed;
} }
@ -244,7 +244,7 @@ int StartOpenVPN(int config)
if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0)) if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0))
{ {
/* CreatePipe failed. */ /* CreatePipe failed. */
ShowLocalizedMsg(GUI_NAME, ERR_CREATE_PIPE_OUTPUT, ""); ShowLocalizedMsg(GUI_NAME, ERR_CREATE_PIPE_OUTPUT);
goto failed; goto failed;
} }
@ -256,7 +256,7 @@ int StartOpenVPN(int config)
TRUE,DUPLICATE_SAME_ACCESS)) TRUE,DUPLICATE_SAME_ACCESS))
{ {
/* DuplicateHandle failed. */ /* DuplicateHandle failed. */
ShowLocalizedMsg(GUI_NAME, ERR_DUP_HANDLE_ERR_WRITE, ""); ShowLocalizedMsg(GUI_NAME, ERR_DUP_HANDLE_ERR_WRITE);
goto failed; goto failed;
} }
@ -264,7 +264,7 @@ int StartOpenVPN(int config)
if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0)) if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0))
{ {
/* CreatePipe failed. */ /* CreatePipe failed. */
ShowLocalizedMsg(GUI_NAME, ERR_CREATE_PIPE_INPUT, ""); ShowLocalizedMsg(GUI_NAME, ERR_CREATE_PIPE_INPUT);
goto failed; goto failed;
} }
@ -279,7 +279,7 @@ int StartOpenVPN(int config)
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
/* Duplicate Handle failed. */ /* Duplicate Handle failed. */
ShowLocalizedMsg(GUI_NAME, ERR_DUP_HANDLE_OUTPUT_READ, ""); ShowLocalizedMsg(GUI_NAME, ERR_DUP_HANDLE_OUTPUT_READ);
goto failed; goto failed;
} }
@ -290,7 +290,7 @@ int StartOpenVPN(int config)
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
/* DuplicateHandle failed */ /* DuplicateHandle failed */
ShowLocalizedMsg(GUI_NAME, ERR_DUP_HANDLE_INPUT_WRITE, ""); ShowLocalizedMsg(GUI_NAME, ERR_DUP_HANDLE_INPUT_WRITE);
goto failed; goto failed;
} }
@ -298,7 +298,7 @@ int StartOpenVPN(int config)
if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp)) if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp))
{ {
/* Close Handle failed */ /* Close Handle failed */
ShowLocalizedMsg(GUI_NAME, ERR_CLOSE_HANDLE_TMP, ""); ShowLocalizedMsg(GUI_NAME, ERR_CLOSE_HANDLE_TMP);
CloseHandle (o.cnn[config].exit_event); CloseHandle (o.cnn[config].exit_event);
return(0); return(0);
} }
@ -347,7 +347,7 @@ int StartOpenVPN(int config)
!CloseHandle (hErrorWrite)) !CloseHandle (hErrorWrite))
{ {
/* CloseHandle failed */ /* CloseHandle failed */
ShowLocalizedMsg (GUI_NAME, ERR_CLOSE_HANDLE, ""); ShowLocalizedMsg (GUI_NAME, ERR_CLOSE_HANDLE);
CloseHandle (o.cnn[config].exit_event); CloseHandle (o.cnn[config].exit_event);
return(false); return(false);
} }
@ -371,7 +371,7 @@ int StartOpenVPN(int config)
if (hThread == NULL) if (hThread == NULL)
{ {
/* CreateThread failed */ /* CreateThread failed */
ShowLocalizedMsg (GUI_NAME, ERR_CREATE_THREAD_STATUS, ""); ShowLocalizedMsg (GUI_NAME, ERR_CREATE_THREAD_STATUS);
goto failed; goto failed;
} }
@ -404,9 +404,8 @@ void StopOpenVPN(int config)
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE);
SetMenuStatus(config, DISCONNECTING); SetMenuStatus(config, DISCONNECTING);
myLoadString(INFO_STATE_WAIT_TERM);
/* UserInfo: waiting for OpenVPN termination... */ /* UserInfo: waiting for OpenVPN termination... */
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_WAIT_TERM));
SetEvent(o.cnn[config].exit_event); SetEvent(o.cnn[config].exit_event);
} }
} }
@ -423,8 +422,7 @@ void SuspendOpenVPN(int config)
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE);
SetMenuStatus(config, DISCONNECTING); SetMenuStatus(config, DISCONNECTING);
myLoadString(INFO_STATE_WAIT_TERM); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_WAIT_TERM));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
SetEvent(o.cnn[config].exit_event); SetEvent(o.cnn[config].exit_event);
} }
} }
@ -476,7 +474,7 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
if (!hwndLogWindow) if (!hwndLogWindow)
{ {
/* Create RichEd LogWindow Failed */ /* Create RichEd LogWindow Failed */
ShowLocalizedMsg(GUI_NAME, ERR_CREATE_RICHED_LOGWINDOW, ""); ShowLocalizedMsg(GUI_NAME, ERR_CREATE_RICHED_LOGWINDOW);
return FALSE; return FALSE;
} }
@ -489,7 +487,7 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
strcpy(charformat.szFaceName, "MS Sans Serif"); strcpy(charformat.szFaceName, "MS Sans Serif");
if ((SendMessage(hwndLogWindow, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM) &charformat) && CFM_SIZE) == 0) { if ((SendMessage(hwndLogWindow, EM_SETCHARFORMAT, SCF_DEFAULT, (LPARAM) &charformat) && CFM_SIZE) == 0) {
/* set size failed */ /* set size failed */
ShowLocalizedMsg(GUI_NAME, ERR_SET_SIZE, ""); ShowLocalizedMsg(GUI_NAME, ERR_SET_SIZE);
} }
/* Set Size and Posision of controls */ /* Set Size and Posision of controls */
@ -574,11 +572,8 @@ BOOL CALLBACK StatusDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP
void SetStatusWinIcon(HWND hwndDlg, int IconID) void SetStatusWinIcon(HWND hwndDlg, int IconID)
{ {
HICON hIcon;
/* Set Window Icon */ /* Set Window Icon */
hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IconID), HICON hIcon = LoadLocalizedIcon(IconID);
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
if (hIcon) { if (hIcon) {
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon)); SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon));
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon)); SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon));
@ -668,7 +663,7 @@ int CheckVersion()
else else
{ {
/* CreateEvent failed */ /* CreateEvent failed */
ShowLocalizedMsg(GUI_NAME, ERR_VERSION_CREATE_EVENT, ""); ShowLocalizedMsg(GUI_NAME, ERR_VERSION_CREATE_EVENT);
return(false); return(false);
} }
} }
@ -694,13 +689,13 @@ int CheckVersion()
if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION)) if (!InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION))
{ {
/* Init Sec. Desc. failed */ /* Init Sec. Desc. failed */
ShowLocalizedMsg (GUI_NAME, ERR_INIT_SEC_DESC, ""); ShowLocalizedMsg (GUI_NAME, ERR_INIT_SEC_DESC);
return(0); return(0);
} }
if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE)) if (!SetSecurityDescriptorDacl (&sd, TRUE, NULL, FALSE))
{ {
/* Set Dacl failed */ /* Set Dacl failed */
ShowLocalizedMsg (GUI_NAME, ERR_SET_SEC_DESC_ACL, ""); ShowLocalizedMsg (GUI_NAME, ERR_SET_SEC_DESC_ACL);
return(0); return(0);
} }
@ -708,7 +703,7 @@ int CheckVersion()
if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0)) if (!CreatePipe(&hInputRead,&hInputWriteTmp,&sa,0))
{ {
/* create pipe failed */ /* create pipe failed */
ShowLocalizedMsg(GUI_NAME, ERR_CREATE_PIPE_INPUT_READ, ""); ShowLocalizedMsg(GUI_NAME, ERR_CREATE_PIPE_INPUT_READ);
return(0); return(0);
} }
@ -716,7 +711,7 @@ int CheckVersion()
if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0)) if (!CreatePipe(&hOutputReadTmp,&hOutputWrite,&sa,0))
{ {
/* CreatePipe failed */ /* CreatePipe failed */
ShowLocalizedMsg(GUI_NAME, ERR_CREATE_PIPE_OUTPUT, ""); ShowLocalizedMsg(GUI_NAME, ERR_CREATE_PIPE_OUTPUT);
return(0); return(0);
} }
@ -727,7 +722,7 @@ int CheckVersion()
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
/* DuplicateHandle failed */ /* DuplicateHandle failed */
ShowLocalizedMsg(GUI_NAME, ERR_DUP_HANDLE_OUTPUT_READ, ""); ShowLocalizedMsg(GUI_NAME, ERR_DUP_HANDLE_OUTPUT_READ);
return(0); return(0);
} }
@ -738,7 +733,7 @@ int CheckVersion()
DUPLICATE_SAME_ACCESS)) DUPLICATE_SAME_ACCESS))
{ {
/* DuplicateHandle failed */ /* DuplicateHandle failed */
ShowLocalizedMsg(GUI_NAME, ERR_DUP_HANDLE_INPUT_WRITE, ""); ShowLocalizedMsg(GUI_NAME, ERR_DUP_HANDLE_INPUT_WRITE);
return(0); return(0);
} }
@ -747,7 +742,7 @@ int CheckVersion()
if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp)) if (!CloseHandle(hOutputReadTmp) || !CloseHandle(hInputWriteTmp))
{ {
/* CloseHandle failed */ /* CloseHandle failed */
ShowLocalizedMsg(GUI_NAME, ERR_CLOSE_HANDLE_TMP, ""); ShowLocalizedMsg(GUI_NAME, ERR_CLOSE_HANDLE_TMP);
return(0); return(0);
} }
@ -856,7 +851,7 @@ int CheckVersion()
|| !CloseHandle (hInputRead) || !CloseHandle(exit_event)) || !CloseHandle (hInputRead) || !CloseHandle(exit_event))
{ {
/* CloseHandle failed */ /* CloseHandle failed */
ShowLocalizedMsg (GUI_NAME, ERR_CLOSE_HANDLE, ""); ShowLocalizedMsg (GUI_NAME, ERR_CLOSE_HANDLE);
return(0); return(0);
} }
@ -918,8 +913,7 @@ void ThreadOpenVPNStatus(int config)
{ {
/* UserInfo: Connecting */ /* UserInfo: Connecting */
TCHAR buf[1000]; TCHAR buf[1000];
myLoadString(INFO_STATE_CONNECTING); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_CONNECTING));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_CONNECTING); SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_CONNECTING);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), TRUE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), TRUE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), TRUE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), TRUE);
@ -930,17 +924,14 @@ void ThreadOpenVPNStatus(int config)
{ {
/* Create and Show Status Dialog */ /* Create and Show Status Dialog */
TCHAR buf[1000]; TCHAR buf[1000];
if (!(o.cnn[config].hwndStatus = CreateDialog (o.hInstance,
MAKEINTRESOURCE (IDD_STATUS), o.cnn[config].hwndStatus = CreateLocalizedDialog(IDD_STATUS, StatusDialogFunc);
NULL, (DLGPROC) StatusDialogFunc))) if (!o.cnn[config].hwndStatus)
ExitThread(1); ExitThread(1);
/* UserInfo: Connecting */ /* UserInfo: Connecting */
myLoadString(INFO_STATE_CONNECTING); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_CONNECTING));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, (LPCTSTR)buf);
SetDlgItemInt(o.cnn[config].hwndStatus, TEXT_CONFIG, (UINT)config, FALSE); SetDlgItemInt(o.cnn[config].hwndStatus, TEXT_CONFIG, (UINT)config, FALSE);
myLoadString(INFO_CONNECTION_XXX); SetWindowText(o.cnn[config].hwndStatus, LoadLocalizedString(INFO_CONNECTION_XXX, conn_name));
mysnprintf(msg, buf, conn_name);
SetWindowText(o.cnn[config].hwndStatus, msg);
if (o.silent_connection[0]=='0') if (o.silent_connection[0]=='0')
ShowWindow(o.cnn[config].hwndStatus, SW_SHOW); ShowWindow(o.cnn[config].hwndStatus, SW_SHOW);
@ -955,7 +946,7 @@ void ThreadOpenVPNStatus(int config)
if (hThread == NULL) if (hThread == NULL)
{ {
/* CreateThread failed */ /* CreateThread failed */
ShowLocalizedMsg (GUI_NAME, ERR_CREATE_THREAD_READ_STDOUT, ""); ShowLocalizedMsg (GUI_NAME, ERR_CREATE_THREAD_READ_STDOUT);
ExitThread(0); ExitThread(0);
} }

View File

@ -34,6 +34,7 @@
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "passphrase.h" #include "passphrase.h"
#include "tray.h" #include "tray.h"
#include "localization.h"
extern struct options o; extern struct options o;
@ -91,7 +92,7 @@ int ReadLineFromStdOut(HANDLE hStdOut, int config, char *line)
else else
{ {
/* error reading from pipe */ /* error reading from pipe */
ShowLocalizedMsg(GUI_NAME, ERR_READ_STDOUT_PIPE, ""); ShowLocalizedMsg(GUI_NAME, ERR_READ_STDOUT_PIPE);
return(-1); return(-1);
} }
} }
@ -150,7 +151,7 @@ int ReadLineFromStdOut(HANDLE hStdOut, int config, char *line)
else else
{ {
/* error reading from pipe */ /* error reading from pipe */
ShowLocalizedMsg(GUI_NAME, ERR_READ_STDOUT_PIPE, ""); ShowLocalizedMsg(GUI_NAME, ERR_READ_STDOUT_PIPE);
return(-1); return(-1);
} }
} }
@ -217,25 +218,21 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
o.cnn[config].failed_psw_attempts = 0; o.cnn[config].failed_psw_attempts = 0;
/* UserInfo: Connected */ /* UserInfo: Connected */
myLoadString(INFO_STATE_CONNECTED); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_CONNECTED));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_CONNECTED); SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_CONNECTED);
/* Show Tray Balloon msg */ /* Show Tray Balloon msg */
if (o.show_balloon[0] != '0') if (o.show_balloon[0] != '0')
{ {
myLoadString(INFO_NOW_CONNECTED); LoadLocalizedStringBuf(msg, sizeof(msg)/sizeof(*msg), INFO_NOW_CONNECTED, o.cnn[config].config_name)
mysnprintf(msg, buf, o.cnn[config].config_name);
if (strlen(o.cnn[config].ip) > 0) if (strlen(o.cnn[config].ip) > 0)
{ {
myLoadString(INFO_ASSIG_IP); ShowTrayBalloon(msg, LoadLocalizedString(INFO_ASSIG_IP, o.cnn[config].ip));
mysnprintf(msg2, buf, o.cnn[config].ip);
} }
else else
{ {
mysnprintf(msg2," "); ShowTrayBalloon(msg, " ");
} }
ShowTrayBalloon(msg, msg2);
} }
/* Hide Status Window */ /* Hide Status Window */
@ -259,7 +256,7 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
{ {
StopOpenVPN(config); StopOpenVPN(config);
/* Cert expired... */ /* Cert expired... */
ShowLocalizedMsg(GUI_NAME, ERR_CERT_EXPIRED, ""); ShowLocalizedMsg(GUI_NAME, ERR_CERT_EXPIRED);
} }
/* Check for "certificate is not yet valid" message */ /* Check for "certificate is not yet valid" message */
@ -267,7 +264,7 @@ void monitor_openvpnlog_while_connecting(int config, char *line)
{ {
StopOpenVPN(config); StopOpenVPN(config);
/* Cert not yet valid */ /* Cert not yet valid */
ShowLocalizedMsg(GUI_NAME, ERR_CERT_NOT_YET_VALID, ""); ShowLocalizedMsg(GUI_NAME, ERR_CERT_NOT_YET_VALID);
} }
/* Check for "Notified TAP-Win32 driver to set a DHCP IP" message */ /* Check for "Notified TAP-Win32 driver to set a DHCP IP" message */
@ -296,8 +293,7 @@ void monitor_openvpnlog_while_connected(int config, char *line)
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
/* Set Status Window Controls "ReConnecting" */ /* Set Status Window Controls "ReConnecting" */
myLoadString(INFO_STATE_RECONNECTING); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_RECONNECTING));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_CONNECTING); SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_CONNECTING);
} }
} }
@ -320,25 +316,21 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line)
SetTrayIcon(CONNECTED); SetTrayIcon(CONNECTED);
/* Set Status Window Controls "Connected" */ /* Set Status Window Controls "Connected" */
myLoadString(INFO_STATE_CONNECTED); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_CONNECTED));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_CONNECTED); SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_CONNECTED);
/* Show Tray Balloon msg */ /* Show Tray Balloon msg */
if (o.show_balloon[0] == '2') if (o.show_balloon[0] == '2')
{ {
myLoadString(INFO_NOW_CONNECTED); LoadLocalizedStringBuf(msg, sizeof(msg)/sizeof(*msg), INFO_NOW_CONNECTED, o.cnn[config].config_name)
mysnprintf(msg, buf, o.cnn[config].config_name);
if (strlen(o.cnn[config].ip) > 0) if (strlen(o.cnn[config].ip) > 0)
{ {
myLoadString(INFO_ASSIG_IP); ShowTrayBalloon(msg, LoadLocalizedString(INFO_ASSIG_IP, o.cnn[config].ip));
mysnprintf(msg2, buf, o.cnn[config].ip);
} }
else else
{ {
mysnprintf(msg2," "); ShowTrayBalloon(msg, " ");
} }
ShowTrayBalloon(msg, msg2);
} }
} }
@ -359,7 +351,7 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line)
{ {
/* Cert expired */ /* Cert expired */
StopOpenVPN(config); StopOpenVPN(config);
ShowLocalizedMsg(GUI_NAME, ERR_CERT_EXPIRED, ""); ShowLocalizedMsg(GUI_NAME, ERR_CERT_EXPIRED);
} }
/* Check for "certificate is not yet valid" message */ /* Check for "certificate is not yet valid" message */
@ -367,7 +359,7 @@ void monitor_openvpnlog_while_reconnecting(int config, char *line)
{ {
StopOpenVPN(config); StopOpenVPN(config);
/* Cert not yet valid */ /* Cert not yet valid */
ShowLocalizedMsg(GUI_NAME, ERR_CERT_NOT_YET_VALID, ""); ShowLocalizedMsg(GUI_NAME, ERR_CERT_NOT_YET_VALID);
} }
/* Check for "Notified TAP-Win32 driver to set a DHCP IP" message */ /* Check for "Notified TAP-Win32 driver to set a DHCP IP" message */
@ -503,8 +495,7 @@ void WatchOpenVPNProcess(int config)
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
/* Show Status Window */ /* Show Status Window */
myLoadString(INFO_STATE_DISCONNECTED); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_DISCONNECTED));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_DISCONNECTED); SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_DISCONNECTED);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE);
@ -535,8 +526,7 @@ void WatchOpenVPNProcess(int config)
else else
{ {
/* Show Status Window */ /* Show Status Window */
myLoadString(INFO_STATE_FAILED); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_FAILED));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_DISCONNECTED); SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_DISCONNECTED);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE);
@ -579,8 +569,7 @@ void WatchOpenVPNProcess(int config)
else else
{ {
/* Show Status Window */ /* Show Status Window */
myLoadString(INFO_STATE_FAILED_RECONN); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_FAILED_RECONN));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_DISCONNECTED); SetStatusWinIcon(o.cnn[config].hwndStatus, APP_ICON_DISCONNECTED);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_DISCONNECT), FALSE);
EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE); EnableWindow(GetDlgItem(o.cnn[config].hwndStatus, ID_RESTART), FALSE);
@ -635,8 +624,7 @@ void WatchOpenVPNProcess(int config)
/* Set connect_status = "SUSPENDED" */ /* Set connect_status = "SUSPENDED" */
o.cnn[config].connect_status=SUSPENDED; o.cnn[config].connect_status=SUSPENDED;
myLoadString(INFO_STATE_SUSPENDED); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_SUSPENDED));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
/* Change tray icon if no more connections is running */ /* Change tray icon if no more connections is running */
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();

View File

@ -27,6 +27,7 @@
#include <memory.h> #include <memory.h>
#include <windows.h> #include <windows.h>
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "localization.h"
extern struct options o; extern struct options o;
@ -183,9 +184,8 @@ add_option (struct options *options,
TCHAR usagetext[5000]; TCHAR usagetext[5000];
TCHAR usagecaption[200]; TCHAR usagecaption[200];
LoadString(o.hInstance, INFO_USAGE, usagetext, sizeof(usagetext) / sizeof(TCHAR)); LoadLocalizedStringBuf(usagecaption, sizeof(usagecaption)/sizeof(*usagecaption), INFO_USAGECAPTION);
LoadString(o.hInstance, INFO_USAGECAPTION, usagecaption, sizeof(usagetext) / sizeof(TCHAR)); MessageBox(NULL, LoadLocalizedString(INFO_USAGE), usagecaption, MB_OK);
MessageBox(NULL, usagetext, usagecaption, MB_OK);
exit(0); exit(0);
} }
else if (streq (p[0], "connect") && p[1]) else if (streq (p[0], "connect") && p[1])

View File

@ -26,6 +26,7 @@
#include "openvpn.h" #include "openvpn.h"
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "chartable.h" #include "chartable.h"
#include "localization.h"
#ifndef DISABLE_CHANGE_PASSWORD #ifndef DISABLE_CHANGE_PASSWORD
#include <openssl/pem.h> #include <openssl/pem.h>
@ -73,8 +74,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
if (strncmp(line, "Enter PEM pass phrase:", 22) == 0) if (strncmp(line, "Enter PEM pass phrase:", 22) == 0)
{ {
CLEAR(passphrase); CLEAR(passphrase);
if (DialogBox(o.hInstance, (LPCTSTR)IDD_PASSPHRASE, NULL, if (LocalizedDialogBox(IDD_PASSPHRASE, PassphraseDialogFunc) == IDCANCEL)
(DLGPROC)PassphraseDialogFunc) == IDCANCEL)
{ {
StopOpenVPN(config); StopOpenVPN(config);
} }
@ -88,14 +88,14 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
strlen(passphrase_ascii), &nCharsWritten, NULL)) strlen(passphrase_ascii), &nCharsWritten, NULL))
{ {
/* PassPhrase -> stdin failed */ /* PassPhrase -> stdin failed */
ShowLocalizedMsg(GUI_NAME, ERR_PASSPHRASE2STDIN, ""); ShowLocalizedMsg(GUI_NAME, ERR_PASSPHRASE2STDIN);
} }
} }
if (!WriteFile(o.cnn[config].hStdIn, "\r\n", if (!WriteFile(o.cnn[config].hStdIn, "\r\n",
2, &nCharsWritten, NULL)) 2, &nCharsWritten, NULL))
{ {
/* CR -> stdin failed */ /* CR -> stdin failed */
ShowLocalizedMsg(GUI_NAME, ERR_CR2STDIN, ""); ShowLocalizedMsg(GUI_NAME, ERR_CR2STDIN);
} }
/* Remove Passphrase prompt from lastline buffer */ /* Remove Passphrase prompt from lastline buffer */
line[0]='\0'; line[0]='\0';
@ -109,8 +109,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
if (strncmp(line, "Enter Private Key Password:", 27) == 0) if (strncmp(line, "Enter Private Key Password:", 27) == 0)
{ {
CLEAR(passphrase); CLEAR(passphrase);
if (DialogBox(o.hInstance, (LPCTSTR)IDD_PASSPHRASE, NULL, if (LocalizedDialogBox(IDD_PASSPHRASE, PassphraseDialogFunc) == IDCANCEL)
(DLGPROC)PassphraseDialogFunc) == IDCANCEL)
{ {
StopOpenVPN(config); StopOpenVPN(config);
} }
@ -124,7 +123,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
strlen(passphrase_ascii), &nCharsWritten, NULL)) strlen(passphrase_ascii), &nCharsWritten, NULL))
{ {
/* PassPhrase -> stdin failed */ /* PassPhrase -> stdin failed */
ShowLocalizedMsg(GUI_NAME, ERR_PASSPHRASE2STDIN, ""); ShowLocalizedMsg(GUI_NAME, ERR_PASSPHRASE2STDIN);
} }
} }
else else
@ -133,7 +132,7 @@ void CheckPrivateKeyPassphrasePrompt (char *line, int config)
1, &nCharsWritten, NULL)) 1, &nCharsWritten, NULL))
{ {
/* CR -> stdin failed */ /* CR -> stdin failed */
ShowLocalizedMsg(GUI_NAME, ERR_CR2STDIN, ""); ShowLocalizedMsg(GUI_NAME, ERR_CR2STDIN);
} }
} }
/* Remove Passphrase prompt from lastline buffer */ /* Remove Passphrase prompt from lastline buffer */
@ -155,10 +154,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (strncmp(line, "Enter Auth Username:", 20) == 0) if (strncmp(line, "Enter Auth Username:", 20) == 0)
{ {
CLEAR(user_auth); CLEAR(user_auth);
if (DialogBoxParam(o.hInstance, if (LocalizedDialogBoxParam(IDD_AUTH_PASSWORD, AuthPasswordDialogFunc,
(LPCTSTR)IDD_AUTH_PASSWORD,
NULL,
(DLGPROC)AuthPasswordDialogFunc,
(LPARAM)&user_auth) == IDCANCEL) (LPARAM)&user_auth) == IDCANCEL)
{ {
StopOpenVPN(config); StopOpenVPN(config);
@ -169,7 +165,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (!WriteFile(o.cnn[config].hStdIn, user_auth.username, if (!WriteFile(o.cnn[config].hStdIn, user_auth.username,
strlen(user_auth.username), &nCharsWritten, NULL)) strlen(user_auth.username), &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(GUI_NAME, ERR_AUTH_USERNAME2STDIN, ""); ShowLocalizedMsg(GUI_NAME, ERR_AUTH_USERNAME2STDIN);
} }
} }
else else
@ -177,7 +173,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (!WriteFile(o.cnn[config].hStdIn, "\n", if (!WriteFile(o.cnn[config].hStdIn, "\n",
1, &nCharsWritten, NULL)) 1, &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(GUI_NAME, ERR_CR2STDIN, ""); ShowLocalizedMsg(GUI_NAME, ERR_CR2STDIN);
} }
} }
@ -186,7 +182,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (!WriteFile(o.cnn[config].hStdIn, user_auth.password, if (!WriteFile(o.cnn[config].hStdIn, user_auth.password,
strlen(user_auth.password), &nCharsWritten, NULL)) strlen(user_auth.password), &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(GUI_NAME, ERR_AUTH_PASSWORD2STDIN, ""); ShowLocalizedMsg(GUI_NAME, ERR_AUTH_PASSWORD2STDIN);
} }
} }
else else
@ -194,7 +190,7 @@ void CheckAuthUsernamePrompt (char *line, int config)
if (!WriteFile(o.cnn[config].hStdIn, "\n", if (!WriteFile(o.cnn[config].hStdIn, "\n",
1, &nCharsWritten, NULL)) 1, &nCharsWritten, NULL))
{ {
ShowLocalizedMsg(GUI_NAME, ERR_CR2STDIN, ""); ShowLocalizedMsg(GUI_NAME, ERR_CR2STDIN);
} }
} }
@ -319,7 +315,7 @@ void ShowChangePassphraseDialog(int config)
if (hThread == NULL) if (hThread == NULL)
{ {
/* error creating thread */ /* error creating thread */
ShowLocalizedMsg (GUI_NAME, ERR_CREATE_PASS_THREAD, ""); ShowLocalizedMsg (GUI_NAME, ERR_CREATE_PASS_THREAD);
return; return;
} }
@ -346,16 +342,13 @@ void ChangePassphraseThread(int config)
} }
/* Show ChangePassphrase Dialog */ /* Show ChangePassphrase Dialog */
if (!(hwndChangePSW = CreateDialog (o.hInstance, hwndChangePSW = CreateLocalizedDialog(IDD_CHANGEPSW, ChangePassphraseDialogFunc);
MAKEINTRESOURCE (IDD_CHANGEPSW), if (!hwndChangePSW)
NULL, (DLGPROC) ChangePassphraseDialogFunc)))
return; return;
SetDlgItemText(hwndChangePSW, TEXT_KEYFILE, keyfilename); SetDlgItemText(hwndChangePSW, TEXT_KEYFILE, keyfilename);
SetDlgItemInt(hwndChangePSW, TEXT_KEYFORMAT, (UINT) keyfile_format, FALSE); SetDlgItemInt(hwndChangePSW, TEXT_KEYFORMAT, (UINT) keyfile_format, FALSE);
myLoadString(INFO_CHANGE_PWD); SetWindowText(hwndChangePSW, LoadLocalizedString(INFO_CHANGE_PWD, conn_name));
mysnprintf(msg, buf, conn_name);
SetWindowText(hwndChangePSW, msg);
ShowWindow(hwndChangePSW, SW_SHOW); ShowWindow(hwndChangePSW, SW_SHOW);
@ -384,8 +377,7 @@ BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam,
switch (msg) { switch (msg) {
case WM_INITDIALOG: case WM_INITDIALOG:
hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(APP_ICON), hIcon = LoadLocalizedIcon(APP_ICON);
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
if (hIcon) { if (hIcon) {
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon)); SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon));
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon)); SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon));
@ -401,7 +393,7 @@ BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam,
if (!ConfirmNewPassword (hwndDlg)) if (!ConfirmNewPassword (hwndDlg))
{ {
/* passwords don't match */ /* passwords don't match */
ShowLocalizedMsg(GUI_NAME, ERR_PWD_DONT_MATCH, ""); ShowLocalizedMsg(GUI_NAME, ERR_PWD_DONT_MATCH);
break; break;
} }
@ -415,8 +407,7 @@ BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam,
/* Check if the new password is empty. */ /* Check if the new password is empty. */
if (NewPasswordLengh(hwndDlg) == 0) if (NewPasswordLengh(hwndDlg) == 0)
{ {
myLoadString(INFO_EMPTY_PWD); if (MessageBox(NULL, LoadLocalizedString(INFO_EMPTY_PWD), GUI_NAME, MB_YESNO) != IDYES)
if (MessageBox(NULL, buf, GUI_NAME, MB_YESNO) != IDYES)
break; break;
} }
@ -437,7 +428,7 @@ BOOL CALLBACK ChangePassphraseDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam,
else else
{ {
/* Unknown key format */ /* Unknown key format */
ShowLocalizedMsg (GUI_NAME, ERR_UNKNOWN_KEYFILE_FORMAT, ""); ShowLocalizedMsg (GUI_NAME, ERR_UNKNOWN_KEYFILE_FORMAT);
} }
DestroyWindow(hwndDlg); DestroyWindow(hwndDlg);
@ -595,7 +586,7 @@ int ParseKeyFilenameLine(int config, char *keyfilename, unsigned int keyfilename
if (j >= (keyfilenamesize - 1)) if (j >= (keyfilenamesize - 1))
{ {
/* key filename to long */ /* key filename to long */
ShowLocalizedMsg(GUI_NAME, ERR_KEY_FILENAME_TO_LONG, ""); ShowLocalizedMsg(GUI_NAME, ERR_KEY_FILENAME_TO_LONG);
return(0); return(0);
} }
i++; i++;
@ -642,7 +633,7 @@ int ChangePasswordPEM(HWND hwndDlg)
ConvertUnicode2Ascii(oldpsw_unicode, oldpsw, sizeof(oldpsw)); ConvertUnicode2Ascii(oldpsw_unicode, oldpsw, sizeof(oldpsw));
if (!ConvertUnicode2Ascii(newpsw_unicode, newpsw, sizeof(newpsw))) if (!ConvertUnicode2Ascii(newpsw_unicode, newpsw, sizeof(newpsw)))
{ {
ShowLocalizedMsg(GUI_NAME, ERR_INVALID_CHARS_IN_PSW, ""); ShowLocalizedMsg(GUI_NAME, ERR_INVALID_CHARS_IN_PSW);
return(-1); return(-1);
} }
@ -660,7 +651,7 @@ int ChangePasswordPEM(HWND hwndDlg)
if (! (privkey = PEM_read_PrivateKey (fp, NULL, NULL, oldpsw))) if (! (privkey = PEM_read_PrivateKey (fp, NULL, NULL, oldpsw)))
{ {
/* wrong password */ /* wrong password */
ShowLocalizedMsg(GUI_NAME, ERR_OLD_PWD_INCORRECT, ""); ShowLocalizedMsg(GUI_NAME, ERR_OLD_PWD_INCORRECT);
fclose(fp); fclose(fp);
return(-1); return(-1);
} }
@ -710,7 +701,7 @@ int ChangePasswordPEM(HWND hwndDlg)
fclose(fp); fclose(fp);
/* signal success to user */ /* signal success to user */
ShowLocalizedMsg(GUI_NAME, INFO_PWD_CHANGED, ""); ShowLocalizedMsg(GUI_NAME, INFO_PWD_CHANGED);
return(1); return(1);
} }
@ -745,7 +736,7 @@ int ChangePasswordPKCS12(HWND hwndDlg)
ConvertUnicode2Ascii(oldpsw_unicode, oldpsw, sizeof(oldpsw)); ConvertUnicode2Ascii(oldpsw_unicode, oldpsw, sizeof(oldpsw));
if (!ConvertUnicode2Ascii(newpsw_unicode, newpsw, sizeof(newpsw))) if (!ConvertUnicode2Ascii(newpsw_unicode, newpsw, sizeof(newpsw)))
{ {
ShowLocalizedMsg(GUI_NAME, ERR_INVALID_CHARS_IN_PSW, ""); ShowLocalizedMsg(GUI_NAME, ERR_INVALID_CHARS_IN_PSW);
return(-1); return(-1);
} }
@ -769,7 +760,7 @@ int ChangePasswordPKCS12(HWND hwndDlg)
if (!PKCS12_parse(p12, oldpsw, &privkey, &cert, &ca)) if (!PKCS12_parse(p12, oldpsw, &privkey, &cert, &ca))
{ {
/* old password incorrect */ /* old password incorrect */
ShowLocalizedMsg(GUI_NAME, ERR_OLD_PWD_INCORRECT, ""); ShowLocalizedMsg(GUI_NAME, ERR_OLD_PWD_INCORRECT);
PKCS12_free(p12); PKCS12_free(p12);
return(-1); return(-1);
} }
@ -785,8 +776,7 @@ int ChangePasswordPKCS12(HWND hwndDlg)
if (!p12) if (!p12)
{ {
/* create failed */ /* create failed */
//ShowMsg(GUI_NAME, ERR_error_string(ERR_peek_last_error(), NULL)); ShowLocalizedMsg(GUI_NAME, ERR_CREATE_PKCS12);
ShowLocalizedMsg(GUI_NAME, ERR_CREATE_PKCS12, "");
return(0); return(0);
} }
@ -809,7 +799,7 @@ int ChangePasswordPKCS12(HWND hwndDlg)
PKCS12_free(p12); PKCS12_free(p12);
fclose(fp); fclose(fp);
/* signal success to user */ /* signal success to user */
ShowLocalizedMsg(GUI_NAME, INFO_PWD_CHANGED, ""); ShowLocalizedMsg(GUI_NAME, INFO_PWD_CHANGED);
return(1); return(1);
} }
@ -853,13 +843,13 @@ int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize,
if (found_key) if (found_key)
{ {
/* only one key option */ /* only one key option */
ShowLocalizedMsg(GUI_NAME, ERR_ONLY_ONE_KEY_OPTION, ""); ShowLocalizedMsg(GUI_NAME, ERR_ONLY_ONE_KEY_OPTION);
return(0); return(0);
} }
if (found_pkcs12) if (found_pkcs12)
{ {
/* key XOR pkcs12 */ /* key XOR pkcs12 */
ShowLocalizedMsg(GUI_NAME, ERR_ONLY_KEY_OR_PKCS12, ""); ShowLocalizedMsg(GUI_NAME, ERR_ONLY_KEY_OR_PKCS12);
return(0); return(0);
} }
found_key=1; found_key=1;
@ -872,13 +862,13 @@ int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize,
if (found_pkcs12) if (found_pkcs12)
{ {
/* only one pkcs12 option */ /* only one pkcs12 option */
ShowLocalizedMsg(GUI_NAME, ERR_ONLY_ONE_PKCS12_OPTION, ""); ShowLocalizedMsg(GUI_NAME, ERR_ONLY_ONE_PKCS12_OPTION);
return(0); return(0);
} }
if (found_key) if (found_key)
{ {
/* only key XOR pkcs12 */ /* only key XOR pkcs12 */
ShowLocalizedMsg(GUI_NAME, ERR_ONLY_KEY_OR_PKCS12, ""); ShowLocalizedMsg(GUI_NAME, ERR_ONLY_KEY_OR_PKCS12);
return(0); return(0);
} }
found_pkcs12=1; found_pkcs12=1;
@ -891,7 +881,7 @@ int GetKeyFilename(int config, char *keyfilename, unsigned int keyfilenamesize,
if ((!found_key) && (!found_pkcs12)) if ((!found_key) && (!found_pkcs12))
{ {
/* must have key or pkcs12 option */ /* must have key or pkcs12 option */
ShowLocalizedMsg(GUI_NAME, ERR_MUST_HAVE_KEY_OR_PKCS12, ""); ShowLocalizedMsg(GUI_NAME, ERR_MUST_HAVE_KEY_OR_PKCS12);
return(0); return(0);
} }

27
proxy.c
View File

@ -26,13 +26,13 @@
#include "proxy.h" #include "proxy.h"
#include "ieproxy.h" #include "ieproxy.h"
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "localization.h"
extern struct options o; extern struct options o;
void ShowProxySettingsDialog() void ShowProxySettingsDialog()
{ {
LocalizedDialogBox(IDD_PROXY, ProxySettingsDialogFunc);
DialogBox(o.hInstance, (LPCTSTR)IDD_PROXY, NULL, (DLGPROC)ProxySettingsDialogFunc);
} }
BOOL CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam) BOOL CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UNUSED LPARAM lParam)
@ -42,8 +42,7 @@ BOOL CALLBACK ProxySettingsDialogFunc (HWND hwndDlg, UINT msg, WPARAM wParam, UN
switch (msg) { switch (msg) {
case WM_INITDIALOG: case WM_INITDIALOG:
hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(APP_ICON), hIcon = LoadLocalizedIcon(APP_ICON);
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
if (hIcon) { if (hIcon) {
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon)); SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon));
SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon)); SendMessage(hwndDlg, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon));
@ -192,14 +191,14 @@ int CheckProxySettings(HWND hwndDlg)
if (strlen(text) == 0) if (strlen(text) == 0)
{ {
/* http_proxy_access not specified */ /* http_proxy_access not specified */
ShowLocalizedMsg(GUI_NAME, ERR_HTTP_PROXY_ADDRESS, ""); ShowLocalizedMsg(GUI_NAME, ERR_HTTP_PROXY_ADDRESS);
return(0); return(0);
} }
GetDlgItemText(hwndDlg, EDIT_PROXY_HTTP_PORT, text, sizeof(text)); GetDlgItemText(hwndDlg, EDIT_PROXY_HTTP_PORT, text, sizeof(text));
if (strlen(text) == 0) if (strlen(text) == 0)
{ {
/* http_proxy_port not specified */ /* http_proxy_port not specified */
ShowLocalizedMsg(GUI_NAME, ERR_HTTP_PROXY_PORT, ""); ShowLocalizedMsg(GUI_NAME, ERR_HTTP_PROXY_PORT);
return(0); return(0);
} }
else else
@ -208,7 +207,7 @@ int CheckProxySettings(HWND hwndDlg)
if ((port < 1) || (port > 65535)) if ((port < 1) || (port > 65535))
{ {
/* http_proxy_port range error */ /* http_proxy_port range error */
ShowLocalizedMsg(GUI_NAME, ERR_HTTP_PROXY_PORT_RANGE, ""); ShowLocalizedMsg(GUI_NAME, ERR_HTTP_PROXY_PORT_RANGE);
return(0); return(0);
} }
} }
@ -220,14 +219,14 @@ int CheckProxySettings(HWND hwndDlg)
if (strlen(text) == 0) if (strlen(text) == 0)
{ {
/* socks_proxy_address not specified */ /* socks_proxy_address not specified */
ShowLocalizedMsg(GUI_NAME, ERR_SOCKS_PROXY_ADDRESS, ""); ShowLocalizedMsg(GUI_NAME, ERR_SOCKS_PROXY_ADDRESS);
return(0); return(0);
} }
GetDlgItemText(hwndDlg, EDIT_PROXY_SOCKS_PORT, text, sizeof(text)); GetDlgItemText(hwndDlg, EDIT_PROXY_SOCKS_PORT, text, sizeof(text));
if (strlen(text) == 0) if (strlen(text) == 0)
{ {
/* socks_proxy_port not specified */ /* socks_proxy_port not specified */
ShowLocalizedMsg(GUI_NAME, ERR_SOCKS_PROXY_PORT, ""); ShowLocalizedMsg(GUI_NAME, ERR_SOCKS_PROXY_PORT);
return(0); return(0);
} }
else else
@ -236,7 +235,7 @@ int CheckProxySettings(HWND hwndDlg)
if ((port < 1) || (port > 65535)) if ((port < 1) || (port > 65535))
{ {
/* socks_proxy_port range error */ /* socks_proxy_port range error */
ShowLocalizedMsg(GUI_NAME, ERR_SOCKS_PROXY_PORT_RANGE, ""); ShowLocalizedMsg(GUI_NAME, ERR_SOCKS_PROXY_PORT_RANGE);
return(0); return(0);
} }
} }
@ -384,7 +383,7 @@ void GetProxyRegistrySettings()
if (!GetTempPath(sizeof(temp_path) - 1, temp_path)) if (!GetTempPath(sizeof(temp_path) - 1, temp_path))
{ {
/* Error getting TempPath - using C:\ */ /* Error getting TempPath - using C:\ */
ShowLocalizedMsg(GUI_NAME, ERR_GET_TEMP_PATH, ""); ShowLocalizedMsg(GUI_NAME, ERR_GET_TEMP_PATH);
strcpy(temp_path, "C:\\"); strcpy(temp_path, "C:\\");
} }
strncat(temp_path, "openvpn_authfile.txt", strncat(temp_path, "openvpn_authfile.txt",
@ -492,7 +491,7 @@ void ConstructProxyCmdLine(char *proxy_string_ptr, unsigned int size)
if (o.proxy_http_auth == PROXY_HTTP_ASK_AUTH) if (o.proxy_http_auth == PROXY_HTTP_ASK_AUTH)
{ {
/* Ask for Proxy username/password */ /* Ask for Proxy username/password */
DialogBox(o.hInstance, (LPCTSTR)IDD_PROXY_AUTH, NULL, (DLGPROC)ProxyAuthDialogFunc); LocalizedDialogBox(IDD_PROXY_AUTH, ProxyAuthDialogFunc);
mysnprintf(proxy_string, "--http-proxy %s %s %s", mysnprintf(proxy_string, "--http-proxy %s %s %s",
o.proxy_http_address, o.proxy_http_address,
o.proxy_http_port, o.proxy_http_port,
@ -536,7 +535,7 @@ void ConstructProxyCmdLine(char *proxy_string_ptr, unsigned int size)
if (o.proxy_http_auth == PROXY_HTTP_ASK_AUTH) if (o.proxy_http_auth == PROXY_HTTP_ASK_AUTH)
{ {
/* Ask for Proxy username/password */ /* Ask for Proxy username/password */
DialogBox(o.hInstance, (LPCTSTR)IDD_PROXY_AUTH, NULL, (DLGPROC)ProxyAuthDialogFunc); LocalizedDialogBox(IDD_PROXY_AUTH, ProxyAuthDialogFunc);
mysnprintf(proxy_string, "--http-proxy %s %s %s", mysnprintf(proxy_string, "--http-proxy %s %s %s",
ieproxy, pos+1, o.proxy_authfile) ieproxy, pos+1, o.proxy_authfile)
} }
@ -551,7 +550,7 @@ void ConstructProxyCmdLine(char *proxy_string_ptr, unsigned int size)
if (o.proxy_http_auth == PROXY_HTTP_ASK_AUTH) if (o.proxy_http_auth == PROXY_HTTP_ASK_AUTH)
{ {
/* Ask for Proxy username/password */ /* Ask for Proxy username/password */
DialogBox(o.hInstance, (LPCTSTR)IDD_PROXY_AUTH, NULL, (DLGPROC)ProxyAuthDialogFunc); LocalizedDialogBox(IDD_PROXY_AUTH, ProxyAuthDialogFunc);
mysnprintf(proxy_string, "--http-proxy %s 80 %s", mysnprintf(proxy_string, "--http-proxy %s 80 %s",
ieproxy, o.proxy_authfile) ieproxy, o.proxy_authfile)
} }

View File

@ -27,6 +27,7 @@
#include "options.h" #include "options.h"
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "registry.h" #include "registry.h"
#include "localization.h"
extern struct options o; extern struct options o;
@ -40,7 +41,7 @@ GetRegistryKeys()
if (!GetWindowsDirectory(windows_dir, sizeof(windows_dir))) { if (!GetWindowsDirectory(windows_dir, sizeof(windows_dir))) {
/* can't get windows dir */ /* can't get windows dir */
ShowLocalizedMsg(GUI_NAME, ERR_GET_WINDOWS_DIR, ""); ShowLocalizedMsg(GUI_NAME, ERR_GET_WINDOWS_DIR);
return(false); return(false);
} }
@ -49,13 +50,13 @@ GetRegistryKeys()
!= ERROR_SUCCESS) != ERROR_SUCCESS)
{ {
/* registry key not found */ /* registry key not found */
ShowLocalizedMsg(GUI_NAME, ERR_OPEN_REGISTRY, ""); ShowLocalizedMsg(GUI_NAME, ERR_OPEN_REGISTRY);
return(false); return(false);
} }
if (!GetRegistryValue(regkey, "", openvpn_path, sizeof(openvpn_path))) if (!GetRegistryValue(regkey, "", openvpn_path, sizeof(openvpn_path)))
{ {
/* error reading registry value */ /* error reading registry value */
ShowLocalizedMsg(GUI_NAME, ERR_READING_REGISTRY, ""); ShowLocalizedMsg(GUI_NAME, ERR_READING_REGISTRY);
return(false); return(false);
} }
if(openvpn_path[strlen(openvpn_path) - 1] != '\\') if(openvpn_path[strlen(openvpn_path) - 1] != '\\')
@ -114,7 +115,7 @@ GetRegistryKeys()
if ((o.psw_attempts < 1) || (o.psw_attempts > 9)) if ((o.psw_attempts < 1) || (o.psw_attempts > 9))
{ {
/* 0 <= passphrase_attempts <= 9 */ /* 0 <= passphrase_attempts <= 9 */
ShowLocalizedMsg(GUI_NAME, ERR_PASSPHRASE_ATTEMPTS, ""); ShowLocalizedMsg(GUI_NAME, ERR_PASSPHRASE_ATTEMPTS);
return(false); return(false);
} }
@ -124,7 +125,7 @@ GetRegistryKeys()
if ((o.connectscript_timeout < 0) || (o.connectscript_timeout > 99)) if ((o.connectscript_timeout < 0) || (o.connectscript_timeout > 99))
{ {
/* 0 <= connectscript_timeout <= 99 */ /* 0 <= connectscript_timeout <= 99 */
ShowLocalizedMsg(GUI_NAME, ERR_CONN_SCRIPT_TIMEOUT, ""); ShowLocalizedMsg(GUI_NAME, ERR_CONN_SCRIPT_TIMEOUT);
return(false); return(false);
} }
@ -134,7 +135,7 @@ GetRegistryKeys()
if ((o.disconnectscript_timeout <= 0) || (o.disconnectscript_timeout > 99)) if ((o.disconnectscript_timeout <= 0) || (o.disconnectscript_timeout > 99))
{ {
/* 0 < disconnectscript_timeout <= 99 */ /* 0 < disconnectscript_timeout <= 99 */
ShowLocalizedMsg(GUI_NAME, ERR_DISCONN_SCRIPT_TIMEOUT, ""); ShowLocalizedMsg(GUI_NAME, ERR_DISCONN_SCRIPT_TIMEOUT);
return(false); return(false);
} }
@ -144,7 +145,7 @@ GetRegistryKeys()
if ((o.preconnectscript_timeout <= 0) || (o.preconnectscript_timeout > 99)) if ((o.preconnectscript_timeout <= 0) || (o.preconnectscript_timeout > 99))
{ {
/* 0 < disconnectscript_timeout <= 99 */ /* 0 < disconnectscript_timeout <= 99 */
ShowLocalizedMsg(GUI_NAME, ERR_PRECONN_SCRIPT_TIMEOUT, ""); ShowLocalizedMsg(GUI_NAME, ERR_PRECONN_SCRIPT_TIMEOUT);
return(false); return(false);
} }
@ -193,7 +194,7 @@ int GetRegKey(const char name[], char *data, const char default_data[], DWORD le
&dwDispos) != ERROR_SUCCESS) &dwDispos) != ERROR_SUCCESS)
{ {
/* error creating registry key */ /* error creating registry key */
ShowLocalizedMsg(GUI_NAME, ERR_CREATE_REG_KEY, ""); ShowLocalizedMsg(GUI_NAME, ERR_CREATE_REG_KEY);
return(false); return(false);
} }
} }
@ -212,7 +213,7 @@ int GetRegKey(const char name[], char *data, const char default_data[], DWORD le
if (status != ERROR_SUCCESS) { if (status != ERROR_SUCCESS) {
/* can't open registry for writing */ /* can't open registry for writing */
ShowLocalizedMsg(GUI_NAME, ERR_OPEN_WRITE_REG, ""); ShowLocalizedMsg(GUI_NAME, ERR_OPEN_WRITE_REG);
return(false); return(false);
} }
if(RegSetValueEx(openvpn_key_write, if(RegSetValueEx(openvpn_key_write,

View File

@ -26,6 +26,7 @@
#include "main.h" #include "main.h"
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "options.h" #include "options.h"
#include "localization.h"
extern struct options o; extern struct options o;
@ -62,8 +63,7 @@ void RunConnectScript(int config, int run_as_service)
if (!run_as_service) if (!run_as_service)
{ {
/* UserInfo: Connect Script running */ /* UserInfo: Connect Script running */
myLoadString(INFO_STATE_CONN_SCRIPT); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_CONN_SCRIPT));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
} }
CLEAR (start_info); CLEAR (start_info);
@ -164,8 +164,7 @@ void RunDisconnectScript(int config, int run_as_service)
if (!run_as_service) if (!run_as_service)
{ {
/* UserInfo: Disconnect Script running */ /* UserInfo: Disconnect Script running */
myLoadString(INFO_STATE_DISCONN_SCRIPT); SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, LoadLocalizedString(INFO_STATE_DISCONN_SCRIPT));
SetDlgItemText(o.cnn[config].hwndStatus, TEXT_STATUS, buf);
} }
CLEAR (start_info); CLEAR (start_info);

View File

@ -28,6 +28,7 @@
#include "main.h" #include "main.h"
#include <stdio.h> #include <stdio.h>
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "localization.h"
extern struct options o; extern struct options o;
@ -57,7 +58,7 @@ int MyStartService()
if (NULL == schSCManager) { if (NULL == schSCManager) {
/* open SC manager failed */ /* open SC manager failed */
ShowLocalizedMsg(GUI_NAME, ERR_OPEN_SCMGR, ""); ShowLocalizedMsg(GUI_NAME, ERR_OPEN_SCMGR);
goto failed; goto failed;
} }
@ -68,7 +69,7 @@ int MyStartService()
if (schService == NULL) { if (schService == NULL) {
/* can't open VPN service */ /* can't open VPN service */
ShowLocalizedMsg(GUI_NAME, ERR_OPEN_VPN_SERVICE, ""); ShowLocalizedMsg(GUI_NAME, ERR_OPEN_VPN_SERVICE);
goto failed; goto failed;
} }
@ -82,7 +83,7 @@ int MyStartService()
NULL) ) // no arguments NULL) ) // no arguments
{ {
/* can't start */ /* can't start */
ShowLocalizedMsg(NULL, ERR_START_SERVICE, ""); ShowLocalizedMsg(NULL, ERR_START_SERVICE);
goto failed; goto failed;
} }
else else
@ -96,7 +97,7 @@ int MyStartService()
&ssStatus) ) // address of status information structure &ssStatus) ) // address of status information structure
{ {
/* query failed */ /* query failed */
ShowLocalizedMsg(GUI_NAME, ERR_QUERY_SERVICE, ""); ShowLocalizedMsg(GUI_NAME, ERR_QUERY_SERVICE);
goto failed; goto failed;
} }
@ -147,7 +148,7 @@ int MyStartService()
if (ssStatus.dwCurrentState != SERVICE_RUNNING) if (ssStatus.dwCurrentState != SERVICE_RUNNING)
{ {
/* service hasn't started */ /* service hasn't started */
ShowLocalizedMsg(GUI_NAME, ERR_SERVICE_START_FAILED, ""); ShowLocalizedMsg(GUI_NAME, ERR_SERVICE_START_FAILED);
goto failed; goto failed;
} }
@ -161,9 +162,7 @@ int MyStartService()
CheckAndSetTrayIcon(); CheckAndSetTrayIcon();
/* Show "OpenVPN Service Started" Tray Balloon msg */ /* Show "OpenVPN Service Started" Tray Balloon msg */
myLoadString(INFO_SERVICE_STARTED); ShowTrayBalloon(LoadLocalizedString(INFO_SERVICE_STARTED), " ");
mysnprintf(msg," ");
ShowTrayBalloon(buf, msg);
return(true); return(true);
@ -206,7 +205,7 @@ int MyStopService()
if (schService == NULL) { if (schService == NULL) {
/* can't open vpn service */ /* can't open vpn service */
ShowLocalizedMsg(GUI_NAME, ERR_OPEN_VPN_SERVICE, ""); ShowLocalizedMsg(GUI_NAME, ERR_OPEN_VPN_SERVICE);
return(false); return(false);
} }
@ -220,7 +219,7 @@ int MyStopService()
&ssStatus) ) // address of status info &ssStatus) ) // address of status info
{ {
/* stop failed */ /* stop failed */
ShowLocalizedMsg(GUI_NAME, ERR_STOP_SERVICE, ""); ShowLocalizedMsg(GUI_NAME, ERR_STOP_SERVICE);
return(false); return(false);
} }
@ -272,7 +271,7 @@ int CheckServiceStatus()
if (schService == NULL) { if (schService == NULL) {
/* open vpn service failed */ /* open vpn service failed */
ShowLocalizedMsg(GUI_NAME, ERR_OPEN_VPN_SERVICE, ""); ShowLocalizedMsg(GUI_NAME, ERR_OPEN_VPN_SERVICE);
o.service_running = SERVICE_NOACCESS; o.service_running = SERVICE_NOACCESS;
SetServiceMenuStatus(); SetServiceMenuStatus();
return(false); return(false);
@ -283,7 +282,7 @@ int CheckServiceStatus()
&ssStatus) ) // address of status information structure &ssStatus) ) // address of status information structure
{ {
/* query failed */ /* query failed */
ShowLocalizedMsg(GUI_NAME, ERR_QUERY_SERVICE, ""); ShowLocalizedMsg(GUI_NAME, ERR_QUERY_SERVICE);
return(false); return(false);
} }

120
tray.c
View File

@ -39,6 +39,7 @@
#include "openvpn.h" #include "openvpn.h"
#include "openvpn_config.h" #include "openvpn_config.h"
#include "openvpn-gui-res.h" #include "openvpn-gui-res.h"
#include "localization.h"
//POPUP MENU //POPUP MENU
HMENU hMenu; HMENU hMenu;
@ -86,8 +87,7 @@ void OnNotifyTray(LPARAM lParam)
else if (o.service_running == SERVICE_CONNECTED) else if (o.service_running == SERVICE_CONNECTED)
{ {
/* Stop OpenVPN service */ /* Stop OpenVPN service */
myLoadString(IDM_TEXT_ASK_STOP_SERVICE); if (MessageBox(NULL, LoadLocalizedString(IDM_TEXT_ASK_STOP_SERVICE), GUI_NAME, MB_YESNO | MB_SETFOREGROUND) == IDYES)
if (MessageBox(NULL, buf, GUI_NAME, MB_YESNO | MB_SETFOREGROUND) == IDYES)
{ {
MyStopService(); MyStopService();
} }
@ -196,57 +196,44 @@ void CreateItemList()
/* Create Main menu with actions */ /* Create Main menu with actions */
if (o.service_only[0]=='0') if (o.service_only[0]=='0')
{ {
myLoadString(IDM_TEXT_CONNECT); AppendMenu(hMenu,MF_STRING, IDM_CONNECTMENU, LoadLocalizedString(IDM_TEXT_CONNECT));
AppendMenu(hMenu,MF_STRING, IDM_CONNECTMENU, buf); AppendMenu(hMenu,MF_STRING, IDM_DISCONNECTMENU, LoadLocalizedString(IDM_TEXT_DISCONNECT));
myLoadString(IDM_TEXT_DISCONNECT); AppendMenu(hMenu,MF_STRING, IDM_STATUSMENU, LoadLocalizedString(IDM_TEXT_STATUS));
AppendMenu(hMenu,MF_STRING, IDM_DISCONNECTMENU, buf);
myLoadString(IDM_TEXT_STATUS);
AppendMenu(hMenu,MF_STRING, IDM_STATUSMENU, buf);
AppendMenu(hMenu,MF_SEPARATOR,0,0); AppendMenu(hMenu,MF_SEPARATOR,0,0);
} }
else else
{ {
myLoadString(IDM_TEXT_SERVICEONLY_START); AppendMenu(hMenu,MF_STRING, IDM_SERVICE_START, LoadLocalizedString(IDM_TEXT_SERVICEONLY_START));
AppendMenu(hMenu,MF_STRING, IDM_SERVICE_START, buf); AppendMenu(hMenu,MF_STRING, IDM_SERVICE_STOP, LoadLocalizedString(IDM_TEXT_SERVICEONLY_STOP));
myLoadString(IDM_TEXT_SERVICEONLY_STOP); AppendMenu(hMenu,MF_STRING, IDM_SERVICE_RESTART, LoadLocalizedString(IDM_TEXT_SERVICEONLY_RESTART));
AppendMenu(hMenu,MF_STRING, IDM_SERVICE_STOP, buf);
myLoadString(IDM_TEXT_SERVICEONLY_RESTART);
AppendMenu(hMenu,MF_STRING, IDM_SERVICE_RESTART, buf);
AppendMenu(hMenu,MF_SEPARATOR,0,0); AppendMenu(hMenu,MF_SEPARATOR,0,0);
} }
myLoadString(IDM_TEXT_VIEWLOG); AppendMenu(hMenu,MF_STRING, IDM_VIEWLOGMENU, LoadLocalizedString(IDM_TEXT_VIEWLOG));
AppendMenu(hMenu,MF_STRING, IDM_VIEWLOGMENU, buf);
if (o.allow_edit[0]=='1') if (o.allow_edit[0]=='1')
{ {
myLoadString(IDM_TEXT_EDITCONFIG); AppendMenu(hMenu,MF_STRING, IDM_EDITMENU, LoadLocalizedString(IDM_TEXT_EDITCONFIG));
AppendMenu(hMenu,MF_STRING, IDM_EDITMENU, buf);
} }
#ifndef DISABLE_CHANGE_PASSWORD #ifndef DISABLE_CHANGE_PASSWORD
if (o.allow_password[0]=='1') if (o.allow_password[0]=='1')
{ {
myLoadString(IDM_TEXT_PASSPHRASE); AppendMenu(hMenu,MF_STRING, IDM_PASSPHRASEMENU, LoadLocalizedString(IDM_TEXT_PASSPHRASE));
AppendMenu(hMenu,MF_STRING, IDM_PASSPHRASEMENU, buf);
} }
#endif #endif
AppendMenu(hMenu,MF_SEPARATOR,0,0); AppendMenu(hMenu,MF_SEPARATOR,0,0);
if (o.allow_service[0]=='1' && o.service_only[0]=='0') if (o.allow_service[0]=='1' && o.service_only[0]=='0')
{ {
myLoadString(IDM_TEXT_SERVICE); AppendMenu(hMenu,MF_POPUP,(UINT) hMenuService, LoadLocalizedString(IDM_TEXT_SERVICE));
AppendMenu(hMenu,MF_POPUP,(UINT) hMenuService, buf);
AppendMenu(hMenu,MF_SEPARATOR,0,0); AppendMenu(hMenu,MF_SEPARATOR,0,0);
} }
if (o.allow_proxy[0]=='1' && o.service_only[0]=='0') if (o.allow_proxy[0]=='1' && o.service_only[0]=='0')
{ {
myLoadString(IDM_TEXT_PROXY); AppendMenu(hMenu,MF_STRING ,IDM_PROXY, LoadLocalizedString(IDM_TEXT_PROXY));
AppendMenu(hMenu,MF_STRING ,IDM_PROXY, buf);
AppendMenu(hMenu,MF_SEPARATOR,0,0); AppendMenu(hMenu,MF_SEPARATOR,0,0);
} }
myLoadString(IDM_TEXT_ABOUT); AppendMenu(hMenu,MF_STRING ,IDM_ABOUT, LoadLocalizedString(IDM_TEXT_ABOUT));
AppendMenu(hMenu,MF_STRING ,IDM_ABOUT, buf); AppendMenu(hMenu,MF_STRING ,IDM_CLOSE, LoadLocalizedString(IDM_TEXT_CLOSE));
myLoadString(IDM_TEXT_CLOSE);
AppendMenu(hMenu,MF_STRING ,IDM_CLOSE, buf);
SetMenuStatus(0, DISCONNECTED); SetMenuStatus(0, DISCONNECTED);
@ -260,30 +247,23 @@ void CreateItemList()
AppendMenu(hMenu,MF_SEPARATOR,0,0); AppendMenu(hMenu,MF_SEPARATOR,0,0);
if (o.allow_service[0]=='1' && o.service_only[0]=='0') if (o.allow_service[0]=='1' && o.service_only[0]=='0')
{ {
myLoadString(IDM_TEXT_SERVICE); AppendMenu(hMenu,MF_POPUP,(UINT) hMenuService, LoadLocalizedString(IDM_TEXT_SERVICE));
AppendMenu(hMenu,MF_POPUP,(UINT) hMenuService, buf);
AppendMenu(hMenu,MF_SEPARATOR,0,0); AppendMenu(hMenu,MF_SEPARATOR,0,0);
} }
if (o.service_only[0]=='1') if (o.service_only[0]=='1')
{ {
myLoadString(IDM_TEXT_SERVICEONLY_START); AppendMenu(hMenu,MF_STRING, IDM_SERVICE_START, LoadLocalizedString(IDM_TEXT_SERVICEONLY_START));
AppendMenu(hMenu,MF_STRING, IDM_SERVICE_START, buf); AppendMenu(hMenu,MF_STRING, IDM_SERVICE_STOP, LoadLocalizedString(IDM_TEXT_SERVICEONLY_STOP));
myLoadString(IDM_TEXT_SERVICEONLY_STOP); AppendMenu(hMenu,MF_STRING, IDM_SERVICE_RESTART, LoadLocalizedString(IDM_TEXT_SERVICEONLY_RESTART));
AppendMenu(hMenu,MF_STRING, IDM_SERVICE_STOP, buf);
myLoadString(IDM_TEXT_SERVICEONLY_RESTART);
AppendMenu(hMenu,MF_STRING, IDM_SERVICE_RESTART, buf);
AppendMenu(hMenu,MF_SEPARATOR,0,0); AppendMenu(hMenu,MF_SEPARATOR,0,0);
} }
if (o.allow_proxy[0]=='1' && o.service_only[0]=='0') if (o.allow_proxy[0]=='1' && o.service_only[0]=='0')
{ {
myLoadString(IDM_TEXT_PROXY); AppendMenu(hMenu,MF_STRING ,IDM_PROXY, LoadLocalizedString(IDM_TEXT_PROXY));
AppendMenu(hMenu,MF_STRING ,IDM_PROXY, buf);
AppendMenu(hMenu,MF_SEPARATOR,0,0); AppendMenu(hMenu,MF_SEPARATOR,0,0);
} }
myLoadString(IDM_TEXT_ABOUT); AppendMenu(hMenu,MF_STRING ,IDM_ABOUT, LoadLocalizedString(IDM_TEXT_ABOUT));
AppendMenu(hMenu,MF_STRING ,IDM_ABOUT, buf); AppendMenu(hMenu,MF_STRING ,IDM_CLOSE, LoadLocalizedString(IDM_TEXT_CLOSE));
myLoadString(IDM_TEXT_CLOSE);
AppendMenu(hMenu,MF_STRING ,IDM_CLOSE, buf);
/* Create PopUp menus for every connection */ /* Create PopUp menus for every connection */
@ -291,25 +271,19 @@ void CreateItemList()
{ {
if (o.service_only[0]=='0') if (o.service_only[0]=='0')
{ {
myLoadString(IDM_TEXT_CONNECT); AppendMenu(hMenuConn[i],MF_STRING, (UINT_PTR)IDM_CONNECTMENU+i, LoadLocalizedString(IDM_TEXT_CONNECT));
AppendMenu(hMenuConn[i],MF_STRING, (UINT_PTR)IDM_CONNECTMENU+i, buf); AppendMenu(hMenuConn[i],MF_STRING, (UINT_PTR)IDM_DISCONNECTMENU+i, LoadLocalizedString(IDM_TEXT_DISCONNECT));
myLoadString(IDM_TEXT_DISCONNECT); AppendMenu(hMenuConn[i],MF_STRING, (UINT_PTR)IDM_STATUSMENU+i, LoadLocalizedString(IDM_TEXT_STATUS));
AppendMenu(hMenuConn[i],MF_STRING, (UINT_PTR)IDM_DISCONNECTMENU+i, buf);
myLoadString(IDM_TEXT_STATUS);
AppendMenu(hMenuConn[i],MF_STRING, (UINT_PTR)IDM_STATUSMENU+i, buf);
AppendMenu(hMenuConn[i],MF_SEPARATOR,0,0); AppendMenu(hMenuConn[i],MF_SEPARATOR,0,0);
} }
myLoadString(IDM_TEXT_VIEWLOG); AppendMenu(hMenuConn[i], MF_STRING, (UINT_PTR)IDM_VIEWLOGMENU+i, LoadLocalizedString(IDM_TEXT_VIEWLOG));
AppendMenu(hMenuConn[i],MF_STRING, (UINT_PTR)IDM_VIEWLOGMENU+i, buf);
if (o.allow_edit[0]=='1') { if (o.allow_edit[0]=='1') {
myLoadString(IDM_TEXT_EDITCONFIG); AppendMenu(hMenuConn[i], MF_STRING, (UINT_PTR)IDM_EDITMENU+i, LoadLocalizedString(IDM_TEXT_EDITCONFIG));
AppendMenu(hMenuConn[i],MF_STRING, (UINT_PTR)IDM_EDITMENU+i, buf);
} }
#ifndef DISABLE_CHANGE_PASSWORD #ifndef DISABLE_CHANGE_PASSWORD
if (o.allow_password[0]=='1') if (o.allow_password[0]=='1')
{ {
myLoadString(IDM_TEXT_PASSPHRASE); AppendMenu(hMenuConn[i], MF_STRING, (UINT_PTR)IDM_PASSPHRASEMENU+i, LoadLocalizedString(IDM_TEXT_PASSPHRASE));
AppendMenu(hMenuConn[i],MF_STRING, (UINT_PTR)IDM_PASSPHRASEMENU+i, buf);
} }
#endif #endif
@ -320,12 +294,9 @@ void CreateItemList()
/* Create Service menu */ /* Create Service menu */
if (o.allow_service[0]=='1' && o.service_only[0]=='0') if (o.allow_service[0]=='1' && o.service_only[0]=='0')
{ {
myLoadString(IDM_TEXT_SERVICE_START); AppendMenu(hMenuService,MF_STRING, IDM_SERVICE_START, LoadLocalizedString(IDM_TEXT_SERVICE_START));
AppendMenu(hMenuService,MF_STRING, IDM_SERVICE_START, buf); AppendMenu(hMenuService,MF_STRING, IDM_SERVICE_STOP, LoadLocalizedString(IDM_TEXT_SERVICE_STOP));
myLoadString(IDM_TEXT_SERVICE_STOP); AppendMenu(hMenuService,MF_STRING, IDM_SERVICE_RESTART, LoadLocalizedString(IDM_TEXT_SERVICE_RESTART));
AppendMenu(hMenuService,MF_STRING, IDM_SERVICE_STOP, buf);
myLoadString(IDM_TEXT_SERVICE_RESTART);
AppendMenu(hMenuService,MF_STRING, IDM_SERVICE_RESTART, buf);
} }
SetServiceMenuStatus(); SetServiceMenuStatus();
@ -336,8 +307,7 @@ BOOL LoadAppIcon()
{ {
// Load icon from resource // Load icon from resource
HICON hIcon = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(APP_ICON), HICON hIcon = LoadLocalizedIcon(APP_ICON);
IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
if (hIcon) { if (hIcon) {
SendMessage(o.hWnd, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon)); SendMessage(o.hWnd, WM_SETICON, (WPARAM) (ICON_SMALL), (LPARAM) (hIcon));
SendMessage(o.hWnd, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon)); //ALT+TAB icon SendMessage(o.hWnd, WM_SETICON, (WPARAM) (ICON_BIG), (LPARAM) (hIcon)); //ALT+TAB icon
@ -353,15 +323,14 @@ void ShowTrayIcon()
ni.cbSize = sizeof(ni); ni.cbSize = sizeof(ni);
ni.uID = 0; ni.uID = 0;
myLoadString(MSG_TIP); lstrcpyn(ni.szTip, LoadLocalizedString(MSG_TIP), sizeof(ni.szTip)/sizeof(*(ni.szTip)));
lstrcpyn(ni.szTip, buf, sizeof(ni.szTip));
ni.hWnd = o.hWnd; ni.hWnd = o.hWnd;
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON; // We want to use icon, tip, and callback message ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON; // We want to use icon, tip, and callback message
ni.uCallbackMessage = WM_NOTIFYICONTRAY; // Our custom callback message (WM_APP + 1) ni.uCallbackMessage = WM_NOTIFYICONTRAY; // Our custom callback message (WM_APP + 1)
//Load selected icon //Load selected icon
ni.hIcon = (HICON)LoadIcon(o.hInstance, MAKEINTRESOURCE(APP_ICON_DISCONNECTED)); ni.hIcon = LoadLocalizedIcon(APP_ICON_DISCONNECTED);
Shell_NotifyIcon(NIM_ADD, &ni); Shell_NotifyIcon(NIM_ADD, &ni);
@ -389,14 +358,11 @@ void SetTrayIcon(int connected)
ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON; // We want to use icon, tip, and callback message ni.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON; // We want to use icon, tip, and callback message
ni.uCallbackMessage = WM_NOTIFYICONTRAY; // Our custom callback message (WM_APP + 1) ni.uCallbackMessage = WM_NOTIFYICONTRAY; // Our custom callback message (WM_APP + 1)
myLoadString(MSG_TIP); strncpy(msg, LoadLocalizedString(MSG_TIP), sizeof(ni.szTip));
strncpy(msg, buf, sizeof(ni.szTip));
myLoadString(MSG_TIP_CONNECTED); strncpy(msg_connected, LoadLocalizedString(MSG_TIP_CONNECTED), sizeof(msg_connected));
strncpy(msg_connected, buf, sizeof(msg_connected));
myLoadString(MSG_TIP_CONNECTING); strncpy(msg_connecting, LoadLocalizedString(MSG_TIP_CONNECTING), sizeof(msg_connecting));
strncpy(msg_connecting, buf, sizeof(msg_connecting));
first_conn=1; first_conn=1;
for (i=0; i < o.num_configs; i++) for (i=0; i < o.num_configs; i++)
@ -437,14 +403,12 @@ void SetTrayIcon(int connected)
con_time=time(NULL); con_time=time(NULL);
strftime(connected_since, sizeof(connected_since), "%b %d, %H:%M", strftime(connected_since, sizeof(connected_since), "%b %d, %H:%M",
localtime(&o.cnn[config].connected_since)); localtime(&o.cnn[config].connected_since));
myLoadString(MSG_TIP_CONNECTED_SINCE); strncat(msg, LoadLocalizedString(MSG_TIP_CONNECTED_SINCE), sizeof(msg) - strlen(msg) - 1);
strncat(msg, buf, sizeof(msg) - strlen(msg) - 1);
strncat(msg, connected_since, sizeof(msg) - strlen(msg) - 1); strncat(msg, connected_since, sizeof(msg) - strlen(msg) - 1);
if (strlen(o.cnn[config].ip) > 0) if (strlen(o.cnn[config].ip) > 0)
{ {
char assigned_ip[100]; char assigned_ip[100];
myLoadString(MSG_TIP_ASSIGNED_IP); mysnprintf(assigned_ip, LoadLocalizedString(MSG_TIP_ASSIGNED_IP), o.cnn[config].ip);
mysnprintf(assigned_ip, buf, o.cnn[config].ip);
strncat(msg, assigned_ip, sizeof(msg) - strlen(msg) - 1); strncat(msg, assigned_ip, sizeof(msg) - strlen(msg) - 1);
} }
} }
@ -453,11 +417,11 @@ void SetTrayIcon(int connected)
//Load selected icon //Load selected icon
if (connected==2) if (connected==2)
ni.hIcon = (HICON)LoadIcon(o.hInstance, MAKEINTRESOURCE(APP_ICON_CONNECTED)); ni.hIcon = LoadLocalizedIcon(APP_ICON_CONNECTED);
else if (connected==1) else if (connected==1)
ni.hIcon = (HICON)LoadIcon(o.hInstance, MAKEINTRESOURCE(APP_ICON_CONNECTING)); ni.hIcon = LoadLocalizedIcon(APP_ICON_CONNECTING);
else if (connected==0) else if (connected==0)
ni.hIcon = (HICON)LoadIcon(o.hInstance, MAKEINTRESOURCE(APP_ICON_DISCONNECTED)); ni.hIcon = LoadLocalizedIcon(APP_ICON_DISCONNECTED);
Shell_NotifyIcon(NIM_MODIFY, &ni); Shell_NotifyIcon(NIM_MODIFY, &ni);
} }