From ece6aef6a61bcf18faaeb0cf38006ed6116ad1de Mon Sep 17 00:00:00 2001 From: Leonardo Basilio Date: Sun, 22 May 2016 15:04:57 -0300 Subject: [PATCH] Launch on startup setting --- localization.c | 52 +++++++++++++++++++++++++++++++++- localization.h | 2 +- main.c | 2 +- openvpn-gui-res.h | 1 + res/openvpn-gui-res-de.rc | 2 ++ res/openvpn-gui-res-dk.rc | 2 ++ res/openvpn-gui-res-en.rc | 2 ++ res/openvpn-gui-res-es.rc | 2 ++ res/openvpn-gui-res-fi.rc | 2 ++ res/openvpn-gui-res-fr.rc | 2 ++ res/openvpn-gui-res-it.rc | 2 ++ res/openvpn-gui-res-jp.rc | 2 ++ res/openvpn-gui-res-nl.rc | 2 ++ res/openvpn-gui-res-no.rc | 2 ++ res/openvpn-gui-res-pl.rc | 2 ++ res/openvpn-gui-res-pt.rc | 2 ++ res/openvpn-gui-res-ru.rc | 2 ++ res/openvpn-gui-res-se.rc | 2 ++ res/openvpn-gui-res-tr.rc | 2 ++ res/openvpn-gui-res-ua.rc | 2 ++ res/openvpn-gui-res-zh-hant.rc | 2 ++ 21 files changed, 88 insertions(+), 3 deletions(-) diff --git a/localization.c b/localization.c index e2facd6..b67b930 100644 --- a/localization.c +++ b/localization.c @@ -354,9 +354,54 @@ FillLangListProc(UNUSED HANDLE module, UNUSED PTSTR type, UNUSED PTSTR stringId, return TRUE; } +static BOOL +GetLaunchOnStartup() +{ + + WCHAR regPath[MAX_PATH], exePath[MAX_PATH]; + BOOL result = FALSE; + HKEY regkey; + + if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_READ, ®key) == ERROR_SUCCESS) { + + if (GetRegistryValue(regkey, L"OpenVPN-GUI", regPath, MAX_PATH) && + GetModuleFileNameW(NULL, exePath, MAX_PATH)) { + if (_wcsicmp(regPath, exePath) == 0) + result = TRUE; + } + + RegCloseKey(regkey); + + } + + return result; + +} + +static void +SetLaunchOnStartup(BOOL value) +{ + + WCHAR exePath[MAX_PATH]; + HKEY regkey; + + if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_WRITE, ®key) == ERROR_SUCCESS) { + + if (value) { + if (GetModuleFileNameW(NULL, exePath, MAX_PATH)) + SetRegistryValue(regkey, L"OpenVPN-GUI", exePath); + } + else + RegDeleteValue(regkey, L"OpenVPN-GUI"); + + RegCloseKey(regkey); + + } + +} INT_PTR CALLBACK -LanguageSettingsDlgProc(HWND hwndDlg, UINT msg, UNUSED WPARAM wParam, LPARAM lParam) +GeneralSettingsDlgProc(HWND hwndDlg, UINT msg, UNUSED WPARAM wParam, LPARAM lParam) { LPPSHNOTIFY psn; langProcData langData = { @@ -379,6 +424,9 @@ LanguageSettingsDlgProc(HWND hwndDlg, UINT msg, UNUSED WPARAM wParam, LPARAM lPa /* Clear language id data for the selected item */ ComboBox_SetItemData(langData.languages, ComboBox_GetCurSel(langData.languages), 0); + if (GetLaunchOnStartup()) + Button_SetCheck(GetDlgItem(hwndDlg, ID_CHK_STARTUP), BST_CHECKED); + break; case WM_NOTIFY: @@ -391,6 +439,8 @@ LanguageSettingsDlgProc(HWND hwndDlg, UINT msg, UNUSED WPARAM wParam, LPARAM lPa if (langId != 0) SetGUILanguage(langId); + SetLaunchOnStartup(Button_GetCheck(GetDlgItem(hwndDlg, ID_CHK_STARTUP)) == BST_CHECKED); + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR); return TRUE; } diff --git a/localization.h b/localization.h index 39eacd6..b0a84a6 100644 --- a/localization.h +++ b/localization.h @@ -32,6 +32,6 @@ LPCDLGTEMPLATE LocalizedDialogResource(const UINT); INT_PTR LocalizedDialogBoxParam(const UINT, DLGPROC, const LPARAM); HWND CreateLocalizedDialogParam(const UINT, DLGPROC, const LPARAM); HWND CreateLocalizedDialog(const UINT, DLGPROC); -INT_PTR CALLBACK LanguageSettingsDlgProc(HWND, UINT, WPARAM, LPARAM); +INT_PTR CALLBACK GeneralSettingsDlgProc(HWND, UINT, WPARAM, LPARAM); #endif diff --git a/main.c b/main.c index 5947b2c..2f7b293 100644 --- a/main.c +++ b/main.c @@ -486,7 +486,7 @@ ShowSettingsDialog() psp[page_number].dwFlags = PSP_DLGINDIRECT; psp[page_number].hInstance = o.hInstance; psp[page_number].pResource = LocalizedDialogResource(ID_DLG_GENERAL); - psp[page_number].pfnDlgProc = LanguageSettingsDlgProc; + psp[page_number].pfnDlgProc = GeneralSettingsDlgProc; psp[page_number].lParam = 0; psp[page_number].pfnCallback = NULL; ++page_number; diff --git a/openvpn-gui-res.h b/openvpn-gui-res.h index e163010..8057f0c 100644 --- a/openvpn-gui-res.h +++ b/openvpn-gui-res.h @@ -77,6 +77,7 @@ #define ID_DLG_GENERAL 230 #define ID_CMB_LANGUAGE 231 #define ID_TXT_LANGUAGE 232 +#define ID_CHK_STARTUP 233 /* Proxy Auth Dialog */ #define ID_DLG_PROXY_AUTH 250 diff --git a/res/openvpn-gui-res-de.rc b/res/openvpn-gui-res-de.rc index 126bf63..2e97c33 100644 --- a/res/openvpn-gui-res-de.rc +++ b/res/openvpn-gui-res-de.rc @@ -130,6 +130,8 @@ BEGIN GROUPBOX "Benutzeroberfläche", 201, 6, 12, 235, 30 LTEXT "Sprache:", ID_TXT_LANGUAGE, 17, 25, 29, 12 COMBOBOX ID_CMB_LANGUAGE, 51, 23, 177, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-dk.rc b/res/openvpn-gui-res-dk.rc index 1c3c35a..98581a6 100644 --- a/res/openvpn-gui-res-dk.rc +++ b/res/openvpn-gui-res-dk.rc @@ -131,6 +131,8 @@ BEGIN GROUPBOX "Brugergrænseflade", 201, 6, 12, 235, 30 LTEXT "Language:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 57, 23, 171, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-en.rc b/res/openvpn-gui-res-en.rc index a35f3a5..f5756ef 100644 --- a/res/openvpn-gui-res-en.rc +++ b/res/openvpn-gui-res-en.rc @@ -130,6 +130,8 @@ BEGIN GROUPBOX "User Interface", 201, 6, 12, 235, 30 LTEXT "Language:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 57, 23, 171, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-es.rc b/res/openvpn-gui-res-es.rc index a1c37fa..3589f75 100644 --- a/res/openvpn-gui-res-es.rc +++ b/res/openvpn-gui-res-es.rc @@ -129,6 +129,8 @@ BEGIN GROUPBOX "Interfaz del Usuario", 201, 6, 12, 235, 30 LTEXT "Idioma:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 45, 23, 183, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-fi.rc b/res/openvpn-gui-res-fi.rc index 1d7a3bd..9939838 100644 --- a/res/openvpn-gui-res-fi.rc +++ b/res/openvpn-gui-res-fi.rc @@ -131,6 +131,8 @@ BEGIN GROUPBOX "Käyttöliittymä", 201, 6, 12, 235, 30 LTEXT "Kieli:", ID_TXT_LANGUAGE, 17, 25, 36, 12 COMBOBOX ID_CMB_LANGUAGE, 37, 23, 191, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-fr.rc b/res/openvpn-gui-res-fr.rc index e92a78b..b301770 100644 --- a/res/openvpn-gui-res-fr.rc +++ b/res/openvpn-gui-res-fr.rc @@ -129,6 +129,8 @@ BEGIN GROUPBOX "L'interface utilisateur", 201, 6, 12, 235, 30 LTEXT "Langue:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 47, 23, 181, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-it.rc b/res/openvpn-gui-res-it.rc index f91c0d2..34cf6bb 100644 --- a/res/openvpn-gui-res-it.rc +++ b/res/openvpn-gui-res-it.rc @@ -129,6 +129,8 @@ BEGIN GROUPBOX "Superficie di Lavoro", 201, 6, 12, 235, 30 LTEXT "Idioma:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 43, 23, 185, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-jp.rc b/res/openvpn-gui-res-jp.rc index 41b570a..5b02265 100644 --- a/res/openvpn-gui-res-jp.rc +++ b/res/openvpn-gui-res-jp.rc @@ -132,6 +132,8 @@ BEGIN GROUPBOX "ユーザーインターフェイス", 201, 6, 12, 235, 30 LTEXT "言語:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 39, 23, 189, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-nl.rc b/res/openvpn-gui-res-nl.rc index f54e8a5..4471d01 100644 --- a/res/openvpn-gui-res-nl.rc +++ b/res/openvpn-gui-res-nl.rc @@ -129,6 +129,8 @@ BEGIN GROUPBOX "Gebruikersinterface", 201, 6, 12, 235, 30 LTEXT "Taal:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 37, 23, 191, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-no.rc b/res/openvpn-gui-res-no.rc index 9ea2fd7..5543b63 100644 --- a/res/openvpn-gui-res-no.rc +++ b/res/openvpn-gui-res-no.rc @@ -130,6 +130,8 @@ BEGIN GROUPBOX "Brukergrensesnitt", 201, 6, 12, 235, 30 LTEXT "Språk:", ID_TXT_LANGUAGE, 17, 25, 23, 12 COMBOBOX ID_CMB_LANGUAGE, 42, 23, 186, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-pl.rc b/res/openvpn-gui-res-pl.rc index 6c3e0c8..d80d9be 100644 --- a/res/openvpn-gui-res-pl.rc +++ b/res/openvpn-gui-res-pl.rc @@ -131,6 +131,8 @@ BEGIN GROUPBOX "Interfejs Użytkownika", 201, 6, 12, 235, 30 LTEXT "Język:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 42, 23, 186, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-pt.rc b/res/openvpn-gui-res-pt.rc index 6bb25dd..bae295e 100644 --- a/res/openvpn-gui-res-pt.rc +++ b/res/openvpn-gui-res-pt.rc @@ -129,6 +129,8 @@ BEGIN GROUPBOX "Interface do Usuário", 201, 6, 12, 235, 30 LTEXT "Idioma:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 57, 23, 171, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Inicialização", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Executar ao iniciar o Windows", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-ru.rc b/res/openvpn-gui-res-ru.rc index d24341b..d72c320 100644 --- a/res/openvpn-gui-res-ru.rc +++ b/res/openvpn-gui-res-ru.rc @@ -131,6 +131,8 @@ BEGIN GROUPBOX "Интерфейс пользователя", 201, 6, 12, 235, 30 LTEXT "Язык:", ID_TXT_LANGUAGE, 17, 25, 23, 12 COMBOBOX ID_CMB_LANGUAGE, 42, 23, 186, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-se.rc b/res/openvpn-gui-res-se.rc index ddecb56..b9e89d8 100644 --- a/res/openvpn-gui-res-se.rc +++ b/res/openvpn-gui-res-se.rc @@ -129,6 +129,8 @@ BEGIN GROUPBOX "Användargränssnitt", 201, 6, 12, 235, 30 LTEXT "Språk:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 42, 23, 186, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-tr.rc b/res/openvpn-gui-res-tr.rc index efd0672..9dfd794 100644 --- a/res/openvpn-gui-res-tr.rc +++ b/res/openvpn-gui-res-tr.rc @@ -131,6 +131,8 @@ BEGIN GROUPBOX "Kullanıcı Arayüzü", 201, 6, 12, 235, 30 LTEXT "Dil:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 31, 23, 197, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-ua.rc b/res/openvpn-gui-res-ua.rc index ef97937..5d388ea 100644 --- a/res/openvpn-gui-res-ua.rc +++ b/res/openvpn-gui-res-ua.rc @@ -129,6 +129,8 @@ BEGIN GROUPBOX "Інтерфейс користувача", 201, 6, 12, 235, 30 LTEXT "Мова:", ID_TXT_LANGUAGE, 17, 25, 23, 12 COMBOBOX ID_CMB_LANGUAGE, 42, 23, 186, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */ diff --git a/res/openvpn-gui-res-zh-hant.rc b/res/openvpn-gui-res-zh-hant.rc index be3325b..93d5cf2 100644 --- a/res/openvpn-gui-res-zh-hant.rc +++ b/res/openvpn-gui-res-zh-hant.rc @@ -131,6 +131,8 @@ BEGIN GROUPBOX "使用者介面", 201, 6, 12, 235, 30 LTEXT "語言:", ID_TXT_LANGUAGE, 17, 25, 52, 12 COMBOBOX ID_CMB_LANGUAGE, 40, 23, 188, 400, CBS_DROPDOWNLIST | WS_TABSTOP + GROUPBOX "Startup", 202, 6, 47, 235, 30 + AUTOCHECKBOX "Launch on Windows startup", ID_CHK_STARTUP, 17, 59, 200, 12 END /* About Dialog */