ReactOS  0.4.15-dev-1197-g8081ba9
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 
13 {
14  BOOL bRet = FALSE;
15  BROWSEINFOW bi;
16  ATL::CStringW szChooseFolderText;
17 
18  szChooseFolderText.LoadStringW(IDS_CHOOSE_FOLDER_TEXT);
19 
20  ZeroMemory(&bi, sizeof(bi));
21  bi.hwndOwner = hwnd;
22  bi.pidlRoot = NULL;
23  bi.lpszTitle = szChooseFolderText.GetString();
24  bi.ulFlags = BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE;
25 
27  {
28  ATL::CStringW szBuf;
29 
30  LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi);
31  if (lpItemList && SHGetPathFromIDListW(lpItemList, szBuf.GetBuffer(MAX_PATH)))
32  {
33  szBuf.ReleaseBuffer();
34  if (!szBuf.IsEmpty())
35  {
37  bRet = TRUE;
38  }
39  }
40  else
41  {
42  szBuf.ReleaseBuffer();
43  }
44 
45  CoTaskMemFree(lpItemList);
47  }
48 
49  return bRet;
50 }
51 
52 BOOL IsUrlValid(const WCHAR * Url)
53 {
54  URL_COMPONENTSW UrlComponmentInfo = { 0 };
55  UrlComponmentInfo.dwStructSize = sizeof(UrlComponmentInfo);
56  UrlComponmentInfo.dwSchemeLength = 1;
57 
58  BOOL bSuccess = InternetCrackUrlW(Url, wcslen(Url), 0, &UrlComponmentInfo);
59  if(!bSuccess)
60  {
61  return FALSE;
62  }
63 
64  switch(UrlComponmentInfo.nScheme)
65  {
70  // supported
71  return TRUE;
72 
73  default:
74  return FALSE;
75  }
76 }
77 
78 namespace
79 {
81  {
82  return (SendDlgItemMessageW(hDlg, nIDDlgItem, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE;
83  }
84 
86  {
88  SendDlgItemMessageW(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, Info->bUpdateAtStart, 0);
89  SendDlgItemMessageW(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0);
90  SendDlgItemMessageW(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info->bDelInstaller, 0);
91 
93  Info->szDownloadDir);
94 
96 
97  if (Info->Proxy == 2)
98  {
101  }
102  else
103  {
106  }
107 
109 
110  EnableWindow(GetDlgItem(hDlg, IDC_SOURCE_URL), Info->bUseSource);
111 
112  SetWindowTextW(GetDlgItem(hDlg, IDC_SOURCE_URL), Info->szSourceURL);
113  SetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), Info->szProxyServer);
114  SetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), Info->szNoProxyFor);
115  }
116 
118  {
119  switch (Msg)
120  {
121  case WM_INITDIALOG:
122  {
125  }
126  break;
127 
128  case WM_COMMAND:
129  {
130  switch (LOWORD(wParam))
131  {
132  case IDC_CHOOSE:
133  ChooseFolder(hDlg);
134  break;
135 
136  case IDC_SAVE_WINDOW_POS:
138  break;
139 
140  case IDC_UPDATE_AVLIST:
142  break;
143 
144  case IDC_LOG_ENABLED:
146  break;
147 
150  break;
151 
152  case IDC_SOURCE_DEFAULT:
155  break;
156 
157  case IDC_USE_SOURCE:
160  break;
161 
162  case IDC_PROXY_DEFAULT:
166  break;
167 
168  case IDC_NO_PROXY:
172  break;
173 
174  case IDC_USE_PROXY:
178  break;
179 
183  break;
184 
185  case IDOK:
186  {
187  ATL::CStringW szDir;
189  ATL::CStringW szProxy;
190  ATL::CStringW szNoProxy;
191  DWORD dwAttr;
192 
194  szDir.GetBuffer(MAX_PATH), MAX_PATH);
195  szDir.ReleaseBuffer();
196 
199  szSource.ReleaseBuffer();
200 
202  szProxy.GetBuffer(MAX_PATH), MAX_PATH);
203  szProxy.ReleaseBuffer();
206  szProxy.GetString(),
207  szProxy.GetLength() + 1);
208 
210  szNoProxy.GetBuffer(MAX_PATH), MAX_PATH);
211  szNoProxy.ReleaseBuffer();
214  szNoProxy.GetString(),
215  szNoProxy.GetLength() + 1);
216 
217  dwAttr = GetFileAttributesW(szDir.GetString());
218  if (dwAttr != INVALID_FILE_ATTRIBUTES &&
219  (dwAttr & FILE_ATTRIBUTE_DIRECTORY))
220  {
223  szDir.GetString(),
224  szDir.GetLength() + 1);
225  }
226  else
227  {
228  ATL::CStringW szMsgText;
229  szMsgText.LoadStringW(IDS_CHOOSE_FOLDER_ERROR);
230 
231  if (MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_YESNO) == IDYES)
232  {
233  if (CreateDirectoryW(szDir.GetString(), NULL))
234  {
235  EndDialog(hDlg, LOWORD(wParam));
236  }
237  }
238  else
239  {
241  break;
242  }
243  }
244 
245 
246  if(NewSettingsInfo.bUseSource && !IsUrlValid(szSource.GetString()))
247  {
248  ATL::CStringW szMsgText;
249  szMsgText.LoadStringW(IDS_URL_INVALID);
250 
251  MessageBoxW(hDlg, szMsgText.GetString(), NULL, 0);
253  break;
254  }
255  else
256  {
259  szSource.GetString(),
260  szSource.GetLength() + 1);
261  }
262 
265  EndDialog(hDlg, LOWORD(wParam));
266  }
267  break;
268 
269  case IDCANCEL:
270  EndDialog(hDlg, LOWORD(wParam));
271  break;
272  }
273  }
274  break;
275  }
276 
277  return FALSE;
278  }
279 }
280 
282 {
285  hwnd,
287 }
int GetLength() const
Definition: atlsimpstr.h:356
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
BOOL bUpdateAtStart
Definition: settings.h:8
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define IDC_USE_PROXY
Definition: resource.h:55
#define IDOK
Definition: winuser.h:824
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
#define IDC_USE_SOURCE
Definition: resource.h:59
#define IDYES
Definition: winuser.h:829
DWORD dwStructSize
Definition: wininet.h:211
#define TRUE
Definition: types.h:120
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
Definition: settings.cpp:167
#define IDC_DOWNLOAD_DIR_EDIT
Definition: resource.h:45
#define IDC_SOURCE_URL
Definition: resource.h:60
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
BOOL IsUrlValid(const WCHAR *Url)
Definition: settingsdlg.cpp:52
#define CALLBACK
Definition: compat.h:35
HWND hwndOwner
Definition: shlobj.h:1127
#define ZeroMemory
Definition: winbase.h:1648
_In_ int nIDDlgItem
Definition: winuser.h:4594
HWND WINAPI SetFocus(_In_opt_ HWND)
#define IDS_URL_INVALID
Definition: resource.h:105
struct @1610 Msg[]
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
UINT_PTR WPARAM
Definition: windef.h:207
SETTINGS_INFO NewSettingsInfo
Definition: settingsdlg.cpp:10
#define IDC_UPDATE_AVLIST
Definition: resource.h:44
VOID CreateSettingsDlg(HWND hwnd)
int32_t INT_PTR
Definition: typedefs.h:64
#define IDS_CHOOSE_FOLDER_ERROR
Definition: resource.h:104
int32_t INT
Definition: typedefs.h:58
static BOOLEAN bSuccess
Definition: drive.cpp:419
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
struct TraceInfo Info
WCHAR szSourceURL[INTERNET_MAX_URL_LENGTH]
Definition: settings.h:24
#define IDD_SETTINGS_DIALOG
Definition: resource.h:63
WCHAR szDownloadDir[MAX_PATH]
Definition: settings.h:10
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
void SaveSettings(void)
Definition: settings.c:115
INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
#define IDC_CHOOSE
Definition: resource.h:48
BOOL bUseSource
Definition: settings.h:23
#define IDC_LOG_ENABLED
Definition: resource.h:47
DWORD dwSchemeLength
Definition: wininet.h:213
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
#define FALSE
Definition: types.h:117
#define MB_YESNO
Definition: winuser.h:811
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:652
#define BIF_DONTGOBELOWDOMAIN
Definition: shlobj.h:1145
smooth NULL
Definition: ftsmooth.c:416
#define IDS_CHOOSE_FOLDER_TEXT
Definition: resource.h:103
#define INTERNET_MAX_URL_LENGTH
Definition: session.c:1418
LONG_PTR LPARAM
Definition: windef.h:208
#define IDC_PROXY_DEFAULT
Definition: resource.h:53
#define BM_GETCHECK
Definition: winuser.h:1900
#define DialogBoxW(i, t, p, f)
Definition: winuser.h:4374
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
LPCWSTR lpszTitle
Definition: shlobj.h:1130
#define IDC_DEL_AFTER_INSTALL
Definition: resource.h:46
#define BM_SETCHECK
Definition: winuser.h:1903
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:25
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL IsCheckedDlgItem(HWND hDlg, INT nIDDlgItem)
Definition: settingsdlg.cpp:80
#define _countof(array)
Definition: sndvol32.h:68
#define IDC_NO_PROXY_FOR
Definition: resource.h:57
INTERNET_SCHEME nScheme
Definition: wininet.h:214
#define IDC_DEFAULT_SETTINGS
Definition: resource.h:49
#define MAX_PATH
Definition: compat.h:34
PCXSTR GetString() const
Definition: atlsimpstr.h:361
unsigned long DWORD
Definition: ntddk_ex.h:95
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define BIF_USENEWUI
Definition: shlobj.h:1151
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static const WCHAR szSource[]
Definition: automation.c:501
#define WM_COMMAND
Definition: winuser.h:1722
PCIDLIST_ABSOLUTE pidlRoot
Definition: shlobj.h:1128
VOID InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info)
Definition: settingsdlg.cpp:85
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brsfolder.c:1357
BOOL ChooseFolder(HWND hwnd)
Definition: settingsdlg.cpp:12
bool IsEmpty() const
Definition: atlsimpstr.h:379
HWND WINAPI GetParent(_In_ HWND)
WCHAR szProxyServer[MAX_PATH]
Definition: settings.h:20
HINSTANCE hInst
Definition: dxdiag.c:13
UINT ulFlags
Definition: shlobj.h:1131
BOOL bLogEnabled
Definition: settings.h:9
#define BIF_RETURNONLYFSDIRS
Definition: shlobj.h:1144
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1412
void WINAPI DECLSPEC_HOTPATCH CoUninitialize(void)
Definition: compobj.c:2067
#define IDC_SAVE_WINDOW_POS
Definition: resource.h:43
#define IDC_NO_PROXY
Definition: resource.h:54
HRESULT WINAPI DECLSPEC_HOTPATCH CoInitializeEx(LPVOID lpReserved, DWORD dwCoInit)
Definition: compobj.c:2002
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)
Definition: atlsimpstr.h:423
unsigned int UINT
Definition: ndis.h:50
BOOL bDelInstaller
Definition: settings.h:11
#define BST_CHECKED
Definition: winuser.h:197
BOOL WINAPI InternetCrackUrlW(const WCHAR *lpszUrl, DWORD dwUrlLength, DWORD dwFlags, URL_COMPONENTSW *lpUC)
Definition: internet.c:1644
#define IDC_PROXY_SERVER
Definition: resource.h:56
#define BIF_VALIDATE
Definition: shlobj.h:1149
BOOL bSaveWndPos
Definition: settings.h:7
WCHAR szNoProxyFor[MAX_PATH]
Definition: settings.h:21
BOOL WINAPI CheckRadioButton(_In_ HWND, _In_ int, _In_ int, _In_ int)
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define IDCANCEL
Definition: winuser.h:825
#define IDC_SOURCE_DEFAULT
Definition: resource.h:58
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define SUCCEEDED(hr)
Definition: intsafe.h:49