5cda85e288522c1d1eff1cb810357b2d7db5c0d3
[reactos.git] / base / setup / reactos / drivepage.c
1 /*
2 * ReactOS applications
3 * Copyright (C) 2004-2008 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 /*
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS GUI first stage setup application
22 * FILE: base/setup/reactos/drivepage.c
23 * PROGRAMMERS: Matthias Kupfer
24 * Dmitry Chapyshev (dmitry@reactos.org)
25 */
26
27 #include "reactos.h"
28 #include "resource.h"
29
30 /* GLOBALS ******************************************************************/
31
32 #define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
33 static const int default_column_widths[MAX_LIST_COLUMNS] = {200, 150, 150};
34 static const int column_alignment[MAX_LIST_COLUMNS] = {LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT};
35
36 /* FUNCTIONS ****************************************************************/
37
38 static INT_PTR CALLBACK
39 MoreOptDlgProc(HWND hwndDlg,
40 UINT uMsg,
41 WPARAM wParam,
42 LPARAM lParam)
43 {
44 PSETUPDATA pSetupData;
45
46 /* Retrieve pointer to the global setup data */
47 pSetupData = (PSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
48
49 switch (uMsg)
50 {
51 case WM_INITDIALOG:
52 /* Save pointer to the global setup data */
53 pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
54 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pSetupData);
55
56 CheckDlgButton(hwndDlg, IDC_INSTFREELDR, BST_CHECKED);
57 SendMessage(GetDlgItem(hwndDlg, IDC_PATH),
58 WM_SETTEXT,
59 (WPARAM)0,
60 (LPARAM)pSetupData->InstallDir);
61 break;
62
63 case WM_COMMAND:
64 switch(LOWORD(wParam))
65 {
66 case IDOK:
67 SendMessage(GetDlgItem(hwndDlg, IDC_PATH),
68 WM_GETTEXT,
69 (WPARAM)sizeof(pSetupData->InstallDir) / sizeof(TCHAR),
70 (LPARAM)pSetupData->InstallDir);
71
72 EndDialog(hwndDlg, IDOK);
73 return TRUE;
74
75 case IDCANCEL:
76 EndDialog(hwndDlg, IDCANCEL);
77 return TRUE;
78 }
79 break;
80 }
81
82 return FALSE;
83 }
84
85 static INT_PTR CALLBACK
86 PartitionDlgProc(HWND hwndDlg,
87 UINT uMsg,
88 WPARAM wParam,
89 LPARAM lParam)
90 {
91 switch (uMsg)
92 {
93 case WM_INITDIALOG:
94 break;
95 case WM_COMMAND:
96 {
97 switch(LOWORD(wParam))
98 {
99 case IDOK:
100 EndDialog(hwndDlg, IDOK);
101 return TRUE;
102 case IDCANCEL:
103 EndDialog(hwndDlg, IDCANCEL);
104 return TRUE;
105 }
106 }
107 }
108 return FALSE;
109 }
110
111
112 static
113 BOOL
114 CreateListViewColumns(
115 HINSTANCE hInstance,
116 HWND hWndListView)
117 {
118 WCHAR szText[50];
119 int index;
120 LVCOLUMN lvC;
121
122 /* Create columns. */
123 lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
124 lvC.pszText = szText;
125
126 /* Load the column labels from the resource file. */
127 for (index = 0; index < MAX_LIST_COLUMNS; index++)
128 {
129 lvC.iSubItem = index;
130 lvC.cx = default_column_widths[index];
131 lvC.fmt = column_alignment[index];
132
133 LoadStringW(hInstance, IDS_LIST_COLUMN_FIRST + index, szText, 50);
134
135 if (ListView_InsertColumn(hWndListView, index, &lvC) == -1)
136 return FALSE;
137 }
138 return TRUE;
139 }
140
141
142 INT_PTR
143 CALLBACK
144 DriveDlgProc(
145 HWND hwndDlg,
146 UINT uMsg,
147 WPARAM wParam,
148 LPARAM lParam)
149 {
150 PSETUPDATA pSetupData;
151 #if 1
152 HDEVINFO h;
153 HWND hList;
154 SP_DEVINFO_DATA DevInfoData;
155 DWORD i;
156 #endif
157
158 /* Retrieve pointer to the global setup data */
159 pSetupData = (PSETUPDATA)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
160
161 switch (uMsg)
162 {
163 case WM_INITDIALOG:
164 {
165 /* Save pointer to the global setup data */
166 pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
167 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (DWORD_PTR)pSetupData);
168
169 CreateListViewColumns(pSetupData->hInstance,
170 GetDlgItem(hwndDlg, IDC_PARTITION));
171
172 #if 1
173 h = SetupDiGetClassDevs(&GUID_DEVCLASS_DISKDRIVE, NULL, NULL, DIGCF_PRESENT);
174 if (h != INVALID_HANDLE_VALUE)
175 {
176 hList =GetDlgItem(hwndDlg, IDC_PARTITION);
177 DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
178 for (i=0; SetupDiEnumDeviceInfo(h, i, &DevInfoData); i++)
179 {
180 DWORD DataT;
181 LPTSTR buffer = NULL;
182 DWORD buffersize = 0;
183
184 while (!SetupDiGetDeviceRegistryProperty(h,
185 &DevInfoData,
186 SPDRP_DEVICEDESC,
187 &DataT,
188 (PBYTE)buffer,
189 buffersize,
190 &buffersize))
191 {
192 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
193 {
194 if (buffer) LocalFree(buffer);
195 buffer = LocalAlloc(LPTR, buffersize * 2);
196 }
197 else
198 break;
199 }
200 if (buffer)
201 {
202 SendMessage(hList, LB_ADDSTRING, (WPARAM) 0, (LPARAM) buffer);
203 LocalFree(buffer);
204 }
205 }
206 SetupDiDestroyDeviceInfoList(h);
207 }
208 #endif
209 }
210 break;
211
212 case WM_COMMAND:
213 {
214 switch(LOWORD(wParam))
215 {
216 case IDC_PARTMOREOPTS:
217 DialogBoxParam(pSetupData->hInstance,
218 MAKEINTRESOURCE(IDD_BOOTOPTIONS),
219 hwndDlg,
220 MoreOptDlgProc,
221 (LPARAM)pSetupData);
222 break;
223 case IDC_PARTCREATE:
224 DialogBox(pSetupData->hInstance,
225 MAKEINTRESOURCE(IDD_PARTITION),
226 hwndDlg,
227 PartitionDlgProc);
228 break;
229 case IDC_PARTDELETE:
230 break;
231 }
232 break;
233 }
234
235 case WM_NOTIFY:
236 {
237 LPNMHDR lpnm = (LPNMHDR)lParam;
238
239 switch (lpnm->code)
240 {
241 case PSN_SETACTIVE:
242 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
243 break;
244
245 case PSN_QUERYCANCEL:
246 SetWindowLongPtr(hwndDlg,
247 DWLP_MSGRESULT,
248 MessageBox(GetParent(hwndDlg),
249 pSetupData->szAbortMessage,
250 pSetupData->szAbortTitle,
251 MB_YESNO | MB_ICONQUESTION) != IDYES);
252 return TRUE;
253
254 default:
255 break;
256 }
257 }
258 break;
259
260 default:
261 break;
262
263 }
264
265 return FALSE;
266 }
267
268 /* EOF */