ReactOS 0.4.15-dev-7887-g64a59a1
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:
127 {
130 }
131 break;
132
133 case WM_COMMAND:
134 {
135 switch (LOWORD(wParam))
136 {
137 case IDC_CHOOSE:
138 ChooseFolder(hDlg);
139 break;
140
143 break;
144
147 break;
148
149 case IDC_LOG_ENABLED:
151 break;
152
155 break;
156
160 break;
161
162 case IDC_USE_SOURCE:
165 break;
166
171 break;
172
173 case IDC_NO_PROXY:
177 break;
178
179 case IDC_USE_PROXY:
183 break;
184
188 break;
189
190 case IDOK:
191 {
192 CStringW szDir;
193 CStringW szSource;
194 CStringW szProxy;
195 CStringW szNoProxy;
196 DWORD dwAttr;
197
199 szDir.ReleaseBuffer();
200
204 szSource.ReleaseBuffer();
205
207 szProxy.ReleaseBuffer();
210 szProxy.GetLength() + 1);
211
213 szNoProxy.ReleaseBuffer();
216 szNoProxy.GetLength() + 1);
217
218 dwAttr = GetFileAttributesW(szDir);
219 if (dwAttr != INVALID_FILE_ATTRIBUTES && (dwAttr & FILE_ATTRIBUTE_DIRECTORY))
220 {
223 szDir.GetLength() + 1);
224 }
225 else
226 {
227 CStringW szMsgText;
228 szMsgText.LoadStringW(IDS_CHOOSE_FOLDER_ERROR);
229
230 if (MessageBoxW(hDlg, szMsgText, NULL, MB_YESNO) == IDYES)
231 {
232 if (CreateDirectoryW(szDir, NULL))
233 {
234 EndDialog(hDlg, LOWORD(wParam));
235 }
236 }
237 else
238 {
240 break;
241 }
242 }
243
244 if (NewSettingsInfo.bUseSource && !IsUrlValid(szSource))
245 {
246 CStringW szMsgText;
247 szMsgText.LoadStringW(IDS_URL_INVALID);
248
249 MessageBoxW(hDlg, szMsgText, NULL, MB_OK);
251 break;
252 }
253 else
254 {
257 szSource.GetLength() + 1);
258 }
259
262 EndDialog(hDlg, LOWORD(wParam));
263 }
264 break;
265
266 case IDCANCEL:
267 EndDialog(hDlg, LOWORD(wParam));
268 break;
269 }
270 }
271 break;
272 }
273
274 return FALSE;
275}
276} // namespace
277
278VOID
280{
282}
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:104
#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:102
#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:103
#define IDC_UPDATE_AVLIST
Definition: resource.h:44
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:20
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
Definition: settings.cpp:179
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 @1632 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
LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brsfolder.c:1419
#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:433
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:1353
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:1215
#define BIF_DONTGOBELOWDOMAIN
Definition: shlobj.h:1211
#define BIF_RETURNONLYFSDIRS
Definition: shlobj.h:1210
#define BIF_USENEWUI
Definition: shlobj.h:1217
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define _countof(array)
Definition: sndvol32.h:68
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:1194
UINT ulFlags
Definition: shlobj.h:1197
HWND hwndOwner
Definition: shlobj.h:1193
LPCWSTR lpszTitle
Definition: shlobj.h:1196
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:1412
#define ZeroMemory
Definition: winbase.h:1712
_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:831
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4399
#define WM_COMMAND
Definition: winuser.h:1740
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define WM_INITDIALOG
Definition: winuser.h:1739
#define MB_YESNO
Definition: winuser.h:817
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:830
#define BM_SETCHECK
Definition: winuser.h:1921
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:790
HWND WINAPI GetParent(_In_ HWND)
BOOL WINAPI CheckRadioButton(_In_ HWND, _In_ int, _In_ int, _In_ int)
_In_ int nIDDlgItem
Definition: winuser.h:4619
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDYES
Definition: winuser.h:835
#define BST_CHECKED
Definition: winuser.h:197
#define BM_GETCHECK
Definition: winuser.h:1918
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180