ReactOS  0.4.15-dev-499-g1f31905
settingsdlg.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Applications Manager
3  * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * FILE: base/applications/rapps/settingsdlg.cpp
5  * PURPOSE: Settings Dialog
6  * COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
7  * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
8  */
9 #include "rapps.h"
10 
12 
14 {
15  BOOL bRet = FALSE;
16  BROWSEINFOW bi;
17  ATL::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.GetString();
25  bi.ulFlags = BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE;
26 
28  {
29  ATL::CStringW szBuf;
30 
31  LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi);
32  if (lpItemList && SHGetPathFromIDListW(lpItemList, szBuf.GetBuffer(MAX_PATH)))
33  {
34  szBuf.ReleaseBuffer();
35  if (!szBuf.IsEmpty())
36  {
38  bRet = TRUE;
39  }
40  }
41  else
42  {
43  szBuf.ReleaseBuffer();
44  }
45 
46  CoTaskMemFree(lpItemList);
48  }
49 
50  return bRet;
51 }
52 
53 BOOL IsUrlValid(const WCHAR * Url)
54 {
55  URL_COMPONENTSW UrlComponmentInfo = { 0 };
56  UrlComponmentInfo.dwStructSize = sizeof(UrlComponmentInfo);
57  UrlComponmentInfo.dwSchemeLength = 1;
58 
59  BOOL bSuccess = InternetCrackUrlW(Url, wcslen(Url), 0, &UrlComponmentInfo);
60  if(!bSuccess)
61  {
62  return FALSE;
63  }
64 
65  switch(UrlComponmentInfo.nScheme)
66  {
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 
264  SaveSettings(GetParent(hDlg));
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: winmain.h:9
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define IDC_USE_PROXY
Definition: resource.h:54
#define TRUE
Definition: types.h:120
#define IDOK
Definition: winuser.h:824
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
#define IDC_USE_SOURCE
Definition: resource.h:58
#define IDYES
Definition: winuser.h:829
DWORD dwStructSize
Definition: wininet.h:211
#define IDC_DOWNLOAD_DIR_EDIT
Definition: resource.h:44
#define IDC_SOURCE_URL
Definition: resource.h:59
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1288
BOOL IsUrlValid(const WCHAR *Url)
Definition: settingsdlg.cpp:53
#define CALLBACK
Definition: compat.h:27
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:103
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
struct @1604 Msg[]
UINT_PTR WPARAM
Definition: windef.h:207
SETTINGS_INFO NewSettingsInfo
Definition: settingsdlg.cpp:11
#define IDC_UPDATE_AVLIST
Definition: resource.h:43
VOID CreateSettingsDlg(HWND hwnd)
int32_t INT_PTR
Definition: typedefs.h:63
#define IDS_CHOOSE_FOLDER_ERROR
Definition: resource.h:102
int32_t INT
Definition: typedefs.h:57
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: winmain.h:25
#define IDD_SETTINGS_DIALOG
Definition: resource.h:62
WCHAR szDownloadDir[MAX_PATH]
Definition: winmain.h:11
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:47
BOOL bUseSource
Definition: winmain.h:24
#define IDC_LOG_ENABLED
Definition: resource.h:46
DWORD dwSchemeLength
Definition: wininet.h:213
void ReleaseBuffer(_In_ int nNewLength=-1)
Definition: atlsimpstr.h:372
#define MB_YESNO
Definition: winuser.h:811
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define BIF_DONTGOBELOWDOMAIN
Definition: shlobj.h:1145
smooth NULL
Definition: ftsmooth.c:416
#define IDS_CHOOSE_FOLDER_TEXT
Definition: resource.h:101
#define INTERNET_MAX_URL_LENGTH
Definition: session.c:1418
SETTINGS_INFO SettingsInfo
Definition: winmain.cpp:18
LONG_PTR LPARAM
Definition: windef.h:208
#define IDC_PROXY_DEFAULT
Definition: resource.h:52
#define BM_GETCHECK
Definition: winuser.h:1900
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
Definition: winmain.cpp:43
#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:45
#define BM_SETCHECK
Definition: winuser.h:1903
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:56
INTERNET_SCHEME nScheme
Definition: wininet.h:214
#define IDC_DEFAULT_SETTINGS
Definition: resource.h:48
#define MAX_PATH
Definition: compat.h:26
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:1309
BOOL ChooseFolder(HWND hwnd)
Definition: settingsdlg.cpp:13
bool IsEmpty() const
Definition: atlsimpstr.h:379
HWND WINAPI GetParent(_In_ HWND)
WCHAR szProxyServer[MAX_PATH]
Definition: winmain.h:21
HINSTANCE hInst
Definition: dxdiag.c:13
UINT ulFlags
Definition: shlobj.h:1131
BOOL bLogEnabled
Definition: winmain.h:10
#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:42
#define IDC_NO_PROXY
Definition: resource.h:53
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: winmain.h:12
#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:55
#define BIF_VALIDATE
Definition: shlobj.h:1149
BOOL bSaveWndPos
Definition: winmain.h:8
WCHAR szNoProxyFor[MAX_PATH]
Definition: winmain.h:22
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:57
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:57