ReactOS 0.4.16-dev-197-g92996da
settingsdlg.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Settings Dialog
5 * COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
6 * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
7 */
8#include "rapps.h"
9
11
12BOOL
14{
15 BOOL bRet = FALSE;
16 BROWSEINFOW bi;
17 CStringW szChooseFolderText;
18
19 szChooseFolderText.LoadStringW(IDS_CHOOSE_FOLDER_TEXT);
20
21 ZeroMemory(&bi, sizeof(bi));
22 bi.hwndOwner = hwnd;
23 bi.pidlRoot = NULL;
24 bi.lpszTitle = szChooseFolderText;
25 bi.ulFlags =
26 BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE;
27
29 {
30 CStringW szBuf;
31
32 LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi);
33 if (lpItemList && SHGetPathFromIDListW(lpItemList, szBuf.GetBuffer(MAX_PATH)))
34 {
35 szBuf.ReleaseBuffer();
36 if (!szBuf.IsEmpty())
37 {
39 bRet = TRUE;
40 }
41 }
42 else
43 {
44 szBuf.ReleaseBuffer();
45 }
46
47 CoTaskMemFree(lpItemList);
49 }
50
51 return bRet;
52}
53
54BOOL
55IsUrlValid(const WCHAR *Url)
56{
57 URL_COMPONENTSW UrlComponmentInfo = {0};
58 UrlComponmentInfo.dwStructSize = sizeof(UrlComponmentInfo);
59 UrlComponmentInfo.dwSchemeLength = 1;
60
61 BOOL bSuccess = InternetCrackUrlW(Url, wcslen(Url), 0, &UrlComponmentInfo);
62 if (!bSuccess)
63 {
64 return FALSE;
65 }
66
67 switch (UrlComponmentInfo.nScheme)
68 {
73 // supported
74 return TRUE;
75
76 default:
77 return FALSE;
78 }
79}
80
81namespace
82{
83inline BOOL
85{
86 return (SendDlgItemMessageW(hDlg, nIDDlgItem, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE;
87}
88
89VOID
91{
93 SendDlgItemMessageW(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, Info->bUpdateAtStart, 0);
94 SendDlgItemMessageW(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0);
96
98
100
101 if (Info->Proxy == 2)
102 {
105 }
106 else
107 {
110 }
111
113
114 EnableWindow(GetDlgItem(hDlg, IDC_SOURCE_URL), Info->bUseSource);
115
116 SetWindowTextW(GetDlgItem(hDlg, IDC_SOURCE_URL), Info->szSourceURL);
117 SetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), Info->szProxyServer);
118 SetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), Info->szNoProxyFor);
119}
120
123{
124 switch (Msg)
125 {
126 case WM_INITDIALOG:
129 return TRUE;
130
131 case WM_COMMAND:
132 {
133 switch (LOWORD(wParam))
134 {
135 case IDC_CHOOSE:
136 ChooseFolder(hDlg);
137 break;
138
141 break;
142
145 break;
146
147 case IDC_LOG_ENABLED:
149 break;
150
153 break;
154
158 break;
159
160 case IDC_USE_SOURCE:
163 break;
164
169 break;
170
171 case IDC_NO_PROXY:
175 break;
176
177 case IDC_USE_PROXY:
181 break;
182
186 break;
187
188 case IDOK:
189 {
190 CStringW szDir;
191 CStringW szSource;
192 CStringW szProxy;
193 CStringW szNoProxy;
194 DWORD dwAttr;
195
197 szDir.ReleaseBuffer();
198
202 szSource.ReleaseBuffer();
203
205 szProxy.ReleaseBuffer();
208 szProxy.GetLength() + 1);
209
211 szNoProxy.ReleaseBuffer();
214 szNoProxy.GetLength() + 1);
215
216 dwAttr = GetFileAttributesW(szDir);
217 if (dwAttr != INVALID_FILE_ATTRIBUTES && (dwAttr & FILE_ATTRIBUTE_DIRECTORY))
218 {
221 szDir.GetLength() + 1);
222 }
223 else
224 {
225 CStringW szMsgText;
226 szMsgText.LoadStringW(IDS_CHOOSE_FOLDER_ERROR);
227
228 if (MessageBoxW(hDlg, szMsgText, NULL, MB_YESNO) == IDYES)
229 {
230 if (CreateDirectoryW(szDir, NULL))
231 {
232 EndDialog(hDlg, LOWORD(wParam));
233 }
234 }
235 else
236 {
238 break;
239 }
240 }
241
242 if (NewSettingsInfo.bUseSource && !IsUrlValid(szSource))
243 {
244 CStringW szMsgText;
245 szMsgText.LoadStringW(IDS_URL_INVALID);
246
247 MessageBoxW(hDlg, szMsgText, NULL, MB_OK);
249 break;
250 }
251 else
252 {
255 szSource.GetLength() + 1);
256 }
257
260 EndDialog(hDlg, LOWORD(wParam));
261 }
262 break;
263
264 case IDCANCEL:
265 EndDialog(hDlg, LOWORD(wParam));
266 break;
267 }
268 }
269 break;
270 }
271
272 return FALSE;
273}
274} // namespace
275
276VOID
278{
280}
void SaveSettings(void)
Definition: settings.c:115
#define IDC_PROXY_SERVER
Definition: resource.h:56
#define IDC_LOG_ENABLED
Definition: resource.h:47
#define IDC_NO_PROXY
Definition: resource.h:54
#define IDS_URL_INVALID
Definition: resource.h:110
#define IDC_USE_SOURCE
Definition: resource.h:59
#define IDC_DEL_AFTER_INSTALL
Definition: resource.h:46
#define IDC_NO_PROXY_FOR
Definition: resource.h:57
#define IDC_USE_PROXY
Definition: resource.h:55
#define IDD_SETTINGS_DIALOG
Definition: resource.h:63
#define IDC_PROXY_DEFAULT
Definition: resource.h:53
#define IDS_CHOOSE_FOLDER_TEXT
Definition: resource.h:108
#define IDC_CHOOSE
Definition: resource.h:48
#define IDC_SAVE_WINDOW_POS
Definition: resource.h:43
#define IDC_DEFAULT_SETTINGS
Definition: resource.h:49
#define IDC_SOURCE_URL
Definition: resource.h:60
#define IDC_DOWNLOAD_DIR_EDIT
Definition: resource.h:45
#define IDC_SOURCE_DEFAULT
Definition: resource.h:58
#define IDS_CHOOSE_FOLDER_ERROR
Definition: resource.h:109
#define IDC_UPDATE_AVLIST
Definition: resource.h:44
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:21
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
Definition: settings.cpp:210
EXTERN_C LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brfolder.cpp:1361
static void __cdecl CopyChars(_Out_writes_to_(nDestLen, nChars) XCHAR *pchDest, _In_ size_t nDestLen, _In_reads_opt_(nChars) const XCHAR *pchSrc, _In_ int nChars) noexcept
Definition: atlsimpstr.h:438
bool IsEmpty() const noexcept
Definition: atlsimpstr.h:394
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:387
int GetLength() const noexcept
Definition: atlsimpstr.h:362
struct @1636 Msg[]
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define MAX_PATH
Definition: compat.h:34
#define CALLBACK
Definition: compat.h:35
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
#define INTERNET_MAX_URL_LENGTH
Definition: session.c:1418
BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwFlags, URL_COMPONENTSW *lpUC)
Definition: internet.c:1625
static BOOLEAN bSuccess
Definition: drive.cpp:477
HINSTANCE hInst
Definition: dxdiag.c:13
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:50
INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
BOOL IsCheckedDlgItem(HWND hDlg, INT nIDDlgItem)
Definition: settingsdlg.cpp:84
VOID InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info)
Definition: settingsdlg.cpp:90
unsigned int UINT
Definition: ndis.h:50
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
@ COINIT_APARTMENTTHREADED
Definition: objbase.h:278
#define LOWORD(l)
Definition: pedump.c:82
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1348
SETTINGS_INFO NewSettingsInfo
Definition: settingsdlg.cpp:10
VOID CreateSettingsDlg(HWND hwnd)
BOOL IsUrlValid(const WCHAR *Url)
Definition: settingsdlg.cpp:55
BOOL ChooseFolder(HWND hwnd)
Definition: settingsdlg.cpp:13
#define BIF_VALIDATE
Definition: shlobj.h:1222
#define BIF_DONTGOBELOWDOMAIN
Definition: shlobj.h:1218
#define BIF_RETURNONLYFSDIRS
Definition: shlobj.h:1217
#define BIF_USENEWUI
Definition: shlobj.h:1224
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define _countof(array)
Definition: sndvol32.h:70
WCHAR szDownloadDir[MAX_PATH]
Definition: settings.h:10
BOOL bUseSource
Definition: settings.h:23
BOOL bLogEnabled
Definition: settings.h:9
BOOL bDelInstaller
Definition: settings.h:11
WCHAR szSourceURL[INTERNET_MAX_URL_LENGTH]
Definition: settings.h:24
WCHAR szNoProxyFor[MAX_PATH]
Definition: settings.h:21
BOOL bUpdateAtStart
Definition: settings.h:8
WCHAR szProxyServer[MAX_PATH]
Definition: settings.h:20
BOOL bSaveWndPos
Definition: settings.h:7
DWORD dwStructSize
Definition: wininet.h:211
INTERNET_SCHEME nScheme
Definition: wininet.h:214
DWORD dwSchemeLength
Definition: wininet.h:213
PCIDLIST_ABSOLUTE pidlRoot
Definition: shlobj.h:1201
UINT ulFlags
Definition: shlobj.h:1204
HWND hwndOwner
Definition: shlobj.h:1200
LPCWSTR lpszTitle
Definition: shlobj.h:1203
int32_t INT_PTR
Definition: typedefs.h:64
int32_t INT
Definition: typedefs.h:58
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
_Must_inspect_result_ _In_ WDFCHILDLIST _In_ PWDF_CHILD_LIST_ITERATOR _Out_ WDFDEVICE _Inout_opt_ PWDF_CHILD_RETRIEVE_INFO Info
Definition: wdfchildlist.h:690
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1384
#define ZeroMemory
Definition: winbase.h:1736
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
UINT_PTR WPARAM
Definition: windef.h:207
#define INTERNET_SCHEME_FTP
Definition: winhttp.h:44
#define INTERNET_SCHEME_HTTP
Definition: winhttp.h:42
#define INTERNET_SCHEME_HTTPS
Definition: winhttp.h:43
@ INTERNET_SCHEME_FILE
Definition: wininet.h:143
#define IDCANCEL
Definition: winuser.h:834
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4402
#define WM_COMMAND
Definition: winuser.h:1743
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define WM_INITDIALOG
Definition: winuser.h:1742
#define MB_YESNO
Definition: winuser.h:820
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:833
#define BM_SETCHECK
Definition: winuser.h:1924
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
HWND WINAPI SetFocus(_In_opt_ HWND)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define MB_OK
Definition: winuser.h:793
HWND WINAPI GetParent(_In_ HWND)
BOOL WINAPI CheckRadioButton(_In_ HWND, _In_ int, _In_ int, _In_ int)
_In_ int nIDDlgItem
Definition: winuser.h:4622
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDYES
Definition: winuser.h:838
#define BST_CHECKED
Definition: winuser.h:197
#define BM_GETCHECK
Definition: winuser.h:1921
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180