Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[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: Eric Kohl
24 * Matthias Kupfer
25 * Dmitry Chapyshev (dmitry@reactos.org)
26 */
27
28 #include "reactos.h"
29 #include "resource.h"
30
31 /* GLOBALS ******************************************************************/
32
33 #define MAX_LIST_COLUMNS (IDS_LIST_COLUMN_LAST - IDS_LIST_COLUMN_FIRST + 1)
34 static const int default_column_widths[MAX_LIST_COLUMNS] = {200, 150, 150};
35 static const int column_alignment[MAX_LIST_COLUMNS] = {LVCFMT_LEFT, LVCFMT_LEFT, LVCFMT_LEFT};
36
37 /* FUNCTIONS ****************************************************************/
38
39 static INT_PTR CALLBACK
40 MoreOptDlgProc(HWND hwndDlg,
41 UINT uMsg,
42 WPARAM wParam,
43 LPARAM lParam)
44 {
45 PSETUPDATA pSetupData;
46
47 /* Retrieve pointer to the global setup data */
48 pSetupData = (PSETUPDATA)GetWindowLongPtr (hwndDlg, GWL_USERDATA);
49
50 switch (uMsg)
51 {
52 case WM_INITDIALOG:
53 /* Save pointer to the global setup data */
54 pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
55 SetWindowLongPtr(hwndDlg, GWL_USERDATA, (DWORD_PTR)pSetupData);
56
57 CheckDlgButton(hwndDlg, IDC_INSTFREELDR, BST_CHECKED);
58 SendMessage(GetDlgItem(hwndDlg, IDC_PATH),
59 WM_SETTEXT,
60 (WPARAM)0,
61 (LPARAM)pSetupData->InstallDir);
62 break;
63
64 case WM_COMMAND:
65 switch(LOWORD(wParam))
66 {
67 case IDOK:
68 SendMessage(GetDlgItem(hwndDlg, IDC_PATH),
69 WM_GETTEXT,
70 (WPARAM)sizeof(pSetupData->InstallDir) / sizeof(TCHAR),
71 (LPARAM)pSetupData->InstallDir);
72
73 EndDialog(hwndDlg, IDOK);
74 return TRUE;
75
76 case IDCANCEL:
77 EndDialog(hwndDlg, IDCANCEL);
78 return TRUE;
79 }
80 break;
81 }
82
83 return FALSE;
84 }
85
86 static INT_PTR CALLBACK
87 PartitionDlgProc(HWND hwndDlg,
88 UINT uMsg,
89 WPARAM wParam,
90 LPARAM lParam)
91 {
92 switch (uMsg)
93 {
94 case WM_INITDIALOG:
95 break;
96 case WM_COMMAND:
97 {
98 switch(LOWORD(wParam))
99 {
100 case IDOK:
101 EndDialog(hwndDlg, IDOK);
102 return TRUE;
103 case IDCANCEL:
104 EndDialog(hwndDlg, IDCANCEL);
105 return TRUE;
106 }
107 }
108 }
109 return FALSE;
110 }
111
112
113 static
114 BOOL
115 CreateListViewColumns(
116 HINSTANCE hInstance,
117 HWND hWndListView)
118 {
119 WCHAR szText[50];
120 int index;
121 LVCOLUMN lvC;
122
123 /* Create columns. */
124 lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
125 lvC.pszText = szText;
126
127 /* Load the column labels from the resource file. */
128 for (index = 0; index < MAX_LIST_COLUMNS; index++)
129 {
130 lvC.iSubItem = index;
131 lvC.cx = default_column_widths[index];
132 lvC.fmt = column_alignment[index];
133
134 LoadStringW(hInstance, IDS_LIST_COLUMN_FIRST + index, szText, 50);
135
136 if (ListView_InsertColumn(hWndListView, index, &lvC) == -1)
137 return FALSE;
138 }
139 return TRUE;
140 }
141
142
143 INT_PTR
144 CALLBACK
145 DriveDlgProc(
146 HWND hwndDlg,
147 UINT uMsg,
148 WPARAM wParam,
149 LPARAM lParam)
150 {
151 PSETUPDATA pSetupData;
152 #if 1
153 HDEVINFO h;
154 HWND hList;
155 SP_DEVINFO_DATA DevInfoData;
156 DWORD i;
157 #endif
158
159 /* Retrieve pointer to the global setup data */
160 pSetupData = (PSETUPDATA)GetWindowLongPtr (hwndDlg, GWL_USERDATA);
161
162 switch (uMsg)
163 {
164 case WM_INITDIALOG:
165 {
166 /* Save pointer to the global setup data */
167 pSetupData = (PSETUPDATA)((LPPROPSHEETPAGE)lParam)->lParam;
168 SetWindowLongPtr(hwndDlg, GWL_USERDATA, (DWORD_PTR)pSetupData);
169
170 CreateListViewColumns(pSetupData->hInstance,
171 GetDlgItem(hwndDlg, IDC_PARTITION));
172
173 #if 1
174 h = SetupDiGetClassDevs(&GUID_DEVCLASS_DISKDRIVE, NULL, NULL, DIGCF_PRESENT);
175 if (h != INVALID_HANDLE_VALUE)
176 {
177 hList =GetDlgItem(hwndDlg, IDC_PARTITION);
178 DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
179 for (i=0; SetupDiEnumDeviceInfo(h, i, &DevInfoData); i++)
180 {
181 DWORD DataT;
182 LPTSTR buffer = NULL;
183 DWORD buffersize = 0;
184
185 while (!SetupDiGetDeviceRegistryProperty(h,
186 &DevInfoData,
187 SPDRP_DEVICEDESC,
188 &DataT,
189 (PBYTE)buffer,
190 buffersize,
191 &buffersize))
192 {
193 if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
194 {
195 if (buffer) LocalFree(buffer);
196 buffer = LocalAlloc(LPTR, buffersize * 2);
197 }
198 else
199 break;
200 }
201 if (buffer)
202 {
203 SendMessage(hList, LB_ADDSTRING, (WPARAM) 0, (LPARAM) buffer);
204 LocalFree(buffer);
205 }
206 }
207 SetupDiDestroyDeviceInfoList(h);
208 }
209 #endif
210 }
211 break;
212
213 case WM_COMMAND:
214 {
215 switch(LOWORD(wParam))
216 {
217 case IDC_PARTMOREOPTS:
218 DialogBoxParam(pSetupData->hInstance,
219 MAKEINTRESOURCE(IDD_BOOTOPTIONS),
220 hwndDlg,
221 (DLGPROC)MoreOptDlgProc,
222 (LPARAM)pSetupData);
223 break;
224 case IDC_PARTCREATE:
225 DialogBox(pSetupData->hInstance,
226 MAKEINTRESOURCE(IDD_PARTITION),
227 hwndDlg,
228 (DLGPROC) PartitionDlgProc);
229 break;
230 case IDC_PARTDELETE:
231 break;
232 }
233 break;
234 }
235
236 case WM_NOTIFY:
237 {
238 LPNMHDR lpnm = (LPNMHDR)lParam;
239
240 switch (lpnm->code)
241 {
242 case PSN_SETACTIVE:
243 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT | PSWIZB_BACK);
244 break;
245
246 case PSN_QUERYCANCEL:
247 SetWindowLongPtr(hwndDlg,
248 DWL_MSGRESULT,
249 MessageBox(GetParent(hwndDlg),
250 pSetupData->szAbortMessage,
251 pSetupData->szAbortTitle,
252 MB_YESNO | MB_ICONQUESTION) != IDYES);
253 return TRUE;
254
255 default:
256 break;
257 }
258 }
259 break;
260
261 default:
262 break;
263
264 }
265
266 return FALSE;
267 }
268
269 /* EOF */