ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/SearchInstaller/SearchInstaller.cpp
Revision: 368
Committed: 2008-08-23T02:44:00-07:00 (14 years, 5 months ago) by douglas
File size: 8316 byte(s)
Log Message:
Rearranged everything else.

File Contents

# Content
1 // Douglas Thrift's Search Engine Installer
2 //
3 // Douglas Thrift
4 //
5 // SearchInstaller.cpp
6
7 #include "SearchInstaller.h"
8 #include "Worker.h"
9
10 Worker worker;
11 HWND hwndBar;
12 HANDLE thread;
13 DWORD threadId;
14
15 int CALLBACK Splash(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
16 int CALLBACK Options(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
17 int CALLBACK Browse(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData);
18 int CALLBACK Confirm(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
19 int CALLBACK Progress(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
20 DWORD WINAPI Thread(LPVOID lpParameter);
21 int CALLBACK Complete(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
22
23 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR
24 lpCmdLine, int nCmdShow)
25 {
26 PROPSHEETPAGE psp = {0};
27 HPROPSHEETPAGE ahpsp[7] = {0};
28 PROPSHEETHEADER psh = {0};
29
30 // Splash
31 psp.dwSize = sizeof(psp);
32 psp.dwFlags = PSP_DEFAULT|PSP_HIDEHEADER;
33 psp.hInstance = hInstance;
34 psp.pfnDlgProc = Splash;
35 psp.pszTemplate = MAKEINTRESOURCE(IDD_SPLASH);
36
37 ahpsp[0] = CreatePropertySheetPage(&psp);
38
39 // Options
40 psp.dwFlags = PSP_DEFAULT|PSP_USEHEADERTITLE|PSP_USEHEADERSUBTITLE;
41 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_OPTIONS_TITLE);
42 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_OPTIONS_SUBTITLE);
43 psp.pfnDlgProc = Options;
44 psp.pszTemplate = MAKEINTRESOURCE(IDD_OPTIONS);
45
46 ahpsp[1] = CreatePropertySheetPage(&psp);
47
48 // Confirm
49 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_CONFIRM_TITLE);
50 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_CONFIRM_SUBTITLE);
51 psp.pfnDlgProc = Confirm;
52 psp.pszTemplate = MAKEINTRESOURCE(IDD_CONFIRM);
53
54 ahpsp[2] = CreatePropertySheetPage(&psp);
55
56 // Progress
57 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_PROGRESS_TITLE);
58 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_PROGRESS_SUBTITLE);
59 psp.pfnDlgProc = Progress;
60 psp.pszTemplate = MAKEINTRESOURCE(IDD_PROGRESS);
61
62 ahpsp[3] = CreatePropertySheetPage(&psp);
63
64 // Complete
65 psp.pszHeaderTitle = MAKEINTRESOURCE(IDS_COMPLETE_TITLE);
66 psp.pszHeaderSubTitle = MAKEINTRESOURCE(IDS_COMPLETE_SUBTITLE);
67 psp.pfnDlgProc = Complete;
68 psp.pszTemplate = MAKEINTRESOURCE(IDD_COMPLETE);
69
70 ahpsp[4] = CreatePropertySheetPage(&psp);
71
72 // Property Sheet
73 psh.dwSize = sizeof(psh);
74 psh.hInstance = hInstance;
75 psh.hwndParent = NULL;
76 psh.phpage = ahpsp;
77 psh.dwFlags = PSH_WIZARD97|PSH_HEADER;
78 psh.pszbmHeader = MAKEINTRESOURCE(IDB_BANNER_BMP);
79 psh.nStartPage = 0;
80 psh.nPages = 5;
81
82 PropertySheet(&psh);
83
84 return 0;
85 }
86
87 int CALLBACK Splash(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
88 {
89 switch (uMsg)
90 {
91 case WM_NOTIFY:
92 {
93 LPNMHDR lpnm = (LPNMHDR) lParam;
94
95 switch (lpnm->code)
96 {
97 case PSN_SETACTIVE:
98 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_NEXT);
99 break;
100 case PSN_WIZNEXT:
101 //
102 break;
103 case PSN_WIZBACK:
104 //
105 break;
106 case PSN_RESET:
107 //
108 break;
109 default:
110 break;
111 }
112 }
113 break;
114 default:
115 break;
116 }
117
118 return 0;
119 }
120
121 int CALLBACK Options(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
122 {
123 switch (uMsg)
124 {
125 case WM_INITDIALOG:
126 if (worker.getSingle())
127 {
128 EnableWindow(GetDlgItem(hwndDlg, IDC_OPTIONS_ALL), false);
129 }
130 break;
131 case WM_COMMAND:
132 switch(LOWORD (wParam))
133 {
134 case IDC_OPTIONS_ALL:
135 worker.setSingle(false);
136 break;
137 case IDC_OPTIONS_SINGLE:
138 worker.setSingle(true);
139 break;
140 case IDC_OPTIONS_TEMPLATE:
141 worker.setTemplates(!worker.getTemplates());
142 break;
143 case IDC_OPTIONS_BROWSE:
144 {
145 char* folder = new char[MAX_PATH + 1];
146
147 GetDlgItemText(hwndDlg, IDC_OPTIONS_FOLDER, folder,
148 MAX_PATH + 1);
149
150 if (strlen(folder) > 0) worker.setFolder(folder);
151 delete [] folder;
152 }
153
154 {
155 BROWSEINFO info;
156
157 info.hwndOwner = hwndDlg;
158 info.pidlRoot = NULL;
159 info.pszDisplayName = NULL;
160 info.lpszTitle = "Select the Destination Folder";
161 info.ulFlags = BIF_RETURNONLYFSDIRS;
162 info.lpfn = Browse;
163 info.lParam = 0;
164 info.iImage = 0;
165
166 LPITEMIDLIST id = SHBrowseForFolder(&info);
167
168 if (id != NULL)
169 {
170 char* folder = new char[MAX_PATH + 1];
171
172 SHGetPathFromIDList(id, folder);
173
174 if (strlen(folder) > 0) worker.setFolder(folder);
175 delete [] folder;
176 }
177
178 LPMALLOC destruct;
179
180 SHGetMalloc(&destruct);
181
182 destruct->Free(id);
183 destruct->Release();
184 }
185
186 SetDlgItemText(hwndDlg, IDC_OPTIONS_FOLDER,
187 worker.getFolder().c_str());
188 break;
189 default:
190 break;
191 }
192 break;
193 case WM_NOTIFY:
194 {
195 LPNMHDR lpnm = (LPNMHDR) lParam;
196
197 switch (lpnm->code)
198 {
199 case PSN_SETACTIVE:
200 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK |
201 PSWIZB_NEXT);
202
203 if (worker.getSingle())
204 {
205 CheckRadioButton(hwndDlg, IDC_OPTIONS_ALL,
206 IDC_OPTIONS_SINGLE, IDC_OPTIONS_SINGLE);
207 }
208 else
209 {
210 CheckRadioButton(hwndDlg, IDC_OPTIONS_ALL,
211 IDC_OPTIONS_SINGLE, IDC_OPTIONS_ALL);
212 }
213
214 if (worker.getTemplates())
215 {
216 CheckDlgButton(hwndDlg, IDC_OPTIONS_TEMPLATE, BST_CHECKED);
217 }
218 else
219 {
220 CheckDlgButton(hwndDlg, IDC_OPTIONS_TEMPLATE,
221 BST_UNCHECKED);
222 }
223
224 SetDlgItemText(hwndDlg, IDC_OPTIONS_FOLDER,
225 worker.getFolder().c_str());
226 break;
227 case PSN_WIZNEXT:
228 {
229 char* folder = new char[MAX_PATH + 1];
230
231 GetDlgItemText(hwndDlg, IDC_OPTIONS_FOLDER, folder,
232 MAX_PATH + 1);
233
234 if (strlen(folder) > 0) worker.setFolder(folder);
235 delete [] folder;
236 }
237 break;
238 case PSN_WIZBACK:
239 //
240 break;
241 case PSN_RESET:
242 //
243 break;
244 default:
245 break;
246 }
247 }
248 break;
249 default:
250 break;
251 }
252
253 return 0;
254 }
255
256 int CALLBACK Browse(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData)
257 {
258 switch (uMsg)
259 {
260 case BFFM_INITIALIZED:
261 {
262 unsigned short* select = new unsigned short[8];
263
264 MultiByteToWideChar(CP_ACP, 0, "&Select", -1, select, 8);
265
266 SendMessage(hwnd, BFFM_SETOKTEXT, 0, (LPARAM)select);
267
268 delete [] select;
269 }
270
271 SendMessage(hwnd, BFFM_SETSELECTION, true,
272 (LPARAM)worker.getFolder().c_str());
273 break;
274 case BFFM_SELCHANGED:
275 //
276 break;
277 default:
278 break;
279 }
280
281 return 0;
282 }
283
284 int CALLBACK Confirm(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
285 {
286 switch (uMsg)
287 {
288 case WM_NOTIFY:
289 {
290 LPNMHDR lpnm = (LPNMHDR) lParam;
291
292 switch (lpnm->code)
293 {
294 case PSN_SETACTIVE:
295 //
296 break;
297 case PSN_WIZNEXT:
298 //
299 break;
300 case PSN_WIZBACK:
301 //
302 break;
303 case PSN_RESET:
304 //
305 break;
306 default:
307 break;
308 }
309 }
310 break;
311 default:
312 break;
313 }
314
315 return 0;
316 }
317
318 int CALLBACK Progress(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
319 {
320 switch (uMsg)
321 {
322 case WM_INITDIALOG:
323 {
324 hwndBar = CreateWindowEx(0, PROGRESS_CLASS, (LPSTR) NULL, WS_CHILD
325 | WS_VISIBLE, 45, 33, 412, 24, hwndDlg, (HMENU) 0, NULL, NULL);
326 }
327 break;
328 case WM_NOTIFY:
329 {
330 LPNMHDR lpnm = (LPNMHDR) lParam;
331
332 switch (lpnm->code)
333 {
334 case PSN_SETACTIVE:
335 PropSheet_SetWizButtons(GetParent(hwndDlg), NULL);
336 thread = CreateThread(NULL, 0, Thread, NULL, 0, &threadId);
337 break;
338 case PSN_WIZNEXT:
339 CloseHandle(thread);
340 break;
341 case PSN_WIZBACK:
342 //
343 break;
344 case PSN_RESET:
345 CloseHandle(thread);
346 break;
347 default:
348 break;
349 }
350 }
351 break;
352 default:
353 break;
354 }
355
356 return 0;
357 }
358
359 DWORD WINAPI Thread(LPVOID lpParameter)
360 {
361 worker.work(hwndBar);
362
363 return 0;
364 }
365
366 int CALLBACK Complete(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
367 {
368 switch (uMsg)
369 {
370 case WM_COMMAND:
371 switch(LOWORD (wParam))
372 {
373 case IDC_COMPLETE_LICENSE:
374 ShellExecute(hwndDlg, NULL, "LICENSE.html", NULL,
375 worker.getFolder().c_str(), SW_SHOWNORMAL);
376 break;
377 case IDC_COMPLETE_README:
378 ShellExecute(hwndDlg, NULL, "README.html", NULL,
379 worker.getFolder().c_str(), SW_SHOWNORMAL);
380 break;
381 case IDC_COMPLETE_WEBSITE:
382 ShellExecute(hwndDlg, NULL,
383 "http://computers.douglasthrift.net/searchengine/", NULL, NULL,
384 SW_SHOWNORMAL);
385 break;
386 default:
387 break;
388 }
389 break;
390 case WM_NOTIFY:
391 {
392 LPNMHDR lpnm = (LPNMHDR) lParam;
393
394 switch (lpnm->code)
395 {
396 case PSN_SETACTIVE:
397 PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_FINISH);
398 break;
399 case PSN_WIZFINISH:
400 //
401 break;
402 case PSN_WIZBACK:
403 //
404 break;
405 case PSN_RESET:
406 //
407 break;
408 default:
409 break;
410 }
411 }
412 break;
413 default:
414 break;
415 }
416
417 return 0;
418 }