ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/DiscBrowse.cxx
Revision: 284
Committed: 2003-09-01T23:05:56-07:00 (21 years, 9 months ago) by douglas
File size: 11195 byte(s)
Log Message:
Did stuff, fixed errors.

File Contents

# Content
1 // Vance Thrift and Biller File Utility 2
2 //
3 // Douglas Thrift
4 //
5 // $Id: DiscBrowse.cxx,v 1.5 2003/09/02 06:05:56 douglas Exp $
6
7 #include "DiscBrowse.h"
8
9 DiscBrowse::DiscBrowse()
10 {
11 number = count++;
12
13 browsers.insert(pair<unsigned, DiscBrowse*>(number, this));
14
15 title = programName + " - Disc Browse";
16
17 popup = CreatePopupMenu();
18
19 MENUITEMINFO open, separator, properties;
20
21 open.cbSize = sizeof(open);
22 open.fMask = MIIM_ID | MIIM_STATE | MIIM_TYPE;
23 open.fType = MFT_STRING;
24 open.fState = MFS_DEFAULT;
25 open.wID = 1;
26 open.dwTypeData = "&Open";
27 open.cch = 5;
28 separator.cbSize = sizeof(open);
29 separator.fMask = MIIM_TYPE;
30 separator.fType = MFT_SEPARATOR;
31 properties.cbSize = sizeof(open);
32 properties.fMask = MIIM_ID | MIIM_TYPE;
33 properties.fType = MFT_STRING;
34 properties.wID = 2;
35 properties.dwTypeData = "P&roperties";
36 properties.cch = 11;
37
38 InsertMenuItem(popup, 0, TRUE, &open);
39 InsertMenuItem(popup, 1, TRUE, &separator);
40 InsertMenuItem(popup, 2, TRUE, &properties);
41
42 // start
43 wizard[0].dwSize = sizeof(wizard[0]);
44 wizard[0].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE |
45 PSP_USEHEADERSUBTITLE;
46 wizard[0].hInstance = gui.instance;
47 wizard[0].pszTemplate = MAKEINTRESOURCE(IDD_BEGIN);
48 wizard[0].pszTitle = title.c_str();
49 wizard[0].pfnDlgProc = start;
50 wizard[0].lParam = number;
51 wizard[0].pszHeaderTitle = "Start";
52 wizard[0].pszHeaderSubTitle = "Change any settings before browsing.";
53
54 // browse
55 wizard[1].dwSize = sizeof(wizard[1]);
56 wizard[1].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE |
57 PSP_USEHEADERSUBTITLE;
58 wizard[1].hInstance = gui.instance;
59 wizard[1].pszTemplate = MAKEINTRESOURCE(IDD_BROWSE);
60 wizard[1].pszTitle = title.c_str();
61 wizard[1].pfnDlgProc = browse;
62 wizard[1].lParam = number;
63 wizard[1].pszHeaderTitle = "Browse";
64 wizard[1].pszHeaderSubTitle = "View documents on the disc.";
65 }
66
67 DiscBrowse::~DiscBrowse()
68 {
69 DestroyMenu(popup);
70 browsers.erase(number);
71 }
72
73 void DiscBrowse::run(void)
74 {
75 loadDir();
76
77 PROPSHEETHEADER header;
78
79 // header
80 header.dwSize = sizeof(header);
81 header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_PROPSHEETPAGE |
82 PSH_USEICONID | PSH_WIZARD97 | PSH_WIZARDHASFINISH;
83 header.hwndParent = NULL;
84 header.hInstance = gui.instance;
85 header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON);
86 header.nPages = 2;
87 header.nStartPage = 0;
88 header.ppsp = wizard;
89 header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP);
90
91 PropertySheet(&header);
92 saveDir();
93 }
94
95 unsigned DiscBrowse::count = 0;
96 map<unsigned, DiscBrowse*> DiscBrowse::browsers;
97
98 map<HWND, DiscBrowse*> DiscBrowse::windows;
99
100 void DiscBrowse::loadDir(void)
101 {
102 HKEY key;
103
104 if (RegOpenKeyEx(HKEY_CURRENT_USER,
105 "Software\\DouglasThrift\\VTBFileUtil2", 0, KEY_QUERY_VALUE, &key) ==
106 ERROR_SUCCESS)
107 {
108 DWORD type;
109 char data[MAX_PATH];
110 DWORD size = MAX_PATH;
111
112 if (RegQueryValueEx(key, "DiscDir", NULL, &type, LPBYTE(data), &size)
113 == ERROR_SUCCESS)
114 {
115 data[size - 1] = '\0';
116
117 switch (type)
118 {
119 case REG_EXPAND_SZ:
120 {
121 char folder[MAX_PATH];
122
123 ExpandEnvironmentStrings(data, folder, MAX_PATH);
124
125 discDir = folder;
126 }
127 break;
128 case REG_SZ:
129 discDir = data;
130 break;
131 default:
132 setDiscDir();
133 break;
134 }
135 }
136 else
137 {
138 setDiscDir();
139 }
140
141 RegCloseKey(key);
142 }
143 else
144 {
145 setDiscDir();
146 }
147
148 if (debug) cerr << "discDir = " << discDir << "\n";
149 }
150
151 void DiscBrowse::saveDir(void)
152 {
153 HKEY key;
154
155 if (RegCreateKeyEx(HKEY_CURRENT_USER,
156 "Software\\DouglasThrift\\VTBFileUtil2", 0, NULL,
157 REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key,
158 NULL) == ERROR_SUCCESS)
159 {
160 DWORD type;
161 char data[MAX_PATH];
162 DWORD size = MAX_PATH;
163
164 if (RegQueryValueEx(key, "DiscDir", NULL, &type, LPBYTE(data), &size)
165 == ERROR_SUCCESS)
166 {
167 data[size - 1] = '\0';
168 }
169 else
170 {
171 data[0] = '\0';
172 }
173
174 if (discDir != data || type != REG_SZ)
175 {
176 if (RegSetValueEx(key, "DiscDir", 0, REG_SZ,
177 LPBYTE(discDir.c_str()), discDir.length() + 1) !=
178 ERROR_SUCCESS)
179 {
180 error();
181 }
182 }
183
184 RegCloseKey(key);
185 }
186 else
187 {
188 error();
189 }
190 }
191
192 void DiscBrowse::setDiscDir(HWND parent)
193 {
194 BROWSEINFO info;
195
196 info.hwndOwner = parent;
197 info.pidlRoot = NULL;
198 info.pszDisplayName = NULL;
199 info.lpszTitle = "Select the Disc";
200 info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
201 info.lpfn = browse;
202 info.lParam = MAKELPARAM(number, true);
203 info.iImage = 0;
204
205 do
206 {
207 LPITEMIDLIST id = SHBrowseForFolder(&info);
208
209 if (id != NULL)
210 {
211 char folder[MAX_PATH];
212
213 if (SHGetPathFromIDList(id, folder)) discDir = folder;
214 }
215
216 LPMALLOC destruct;
217
218 SHGetMalloc(&destruct);
219 destruct->Free(id);
220 destruct->Release();
221
222 if (discDir == "")
223 {
224 switch (MessageBox(parent, "Disc needs to be selected.",
225 title.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
226 {
227 case IDABORT:
228 exit(1);
229 break;
230 case IDRETRY:
231 break;
232 case IDIGNORE:
233 Beep(2200, 250);
234 Beep(1100, 500);
235 Beep(3300, 250);
236 exit(2);
237 break;
238 }
239 }
240 }
241 while (discDir == "");
242
243 if (debug) cerr << "discDir = " << discDir << "\n";
244 }
245
246 void DiscBrowse::populate(HWND parent)
247 {
248 set<IndividualClient> clients;
249
250 do
251 {
252 string client = discDir + "\\*_*." + IndividualClient::getExtension();
253 WIN32_FIND_DATA found;
254 HANDLE finder = FindFirstFile(client.c_str(), &found);
255
256 if (finder != INVALID_HANDLE_VALUE)
257 {
258 do
259 {
260 clients.insert(IndividualClient(found.cFileName));
261 }
262 while (FindNextFile(finder, &found));
263
264 FindClose(finder);
265 }
266
267 if (clients.empty())
268 {
269 if (MessageBox(parent, "No client documents found.",
270 title.c_str(), MB_RETRYCANCEL | MB_ICONQUESTION) == IDCANCEL)
271 break;
272 }
273 }
274 while (clients.empty());
275
276 if (!clients.empty())
277 {
278 if (debug) cerr << "clients = {\n";
279
280 for (set<IndividualClient>::iterator itor = clients.begin(); itor !=
281 clients.end(); itor++)
282 {
283 IndividualClient client = *itor;
284
285 if (debug) cerr << " {\n"
286 << " number = " << client.getNumber() << "\n"
287 << " name = " << client.getName() << "\n"
288 << " file = " << client.getFile() << "\n"
289 << " }\n";
290 }
291
292 if (debug) cerr << "}\n";
293 }
294 }
295
296 DiscBrowse* DiscBrowse::which(HWND window)
297 {
298 map<HWND, DiscBrowse*>::iterator itor = windows.find(window);
299
300 return itor->second;
301 }
302
303 DiscBrowse* DiscBrowse::which(HWND window, LPARAM l)
304 {
305 LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
306 map<unsigned, DiscBrowse*>::iterator itor = browsers.find(page->lParam);
307
308 windows.insert(pair<HWND, DiscBrowse*>(window, itor->second));
309
310 return itor->second;
311 }
312
313 int DiscBrowse::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d)
314 {
315 map<unsigned, DiscBrowse*>::iterator itor = browsers.find(LOWORD(d));
316 DiscBrowse* data = itor->second;
317
318 switch (msg)
319 {
320 case BFFM_INITIALIZED:
321 center(dialog);
322 SendMessage(dialog, BFFM_SETOKTEXT, 0,
323 LPARAM(toWide("&Select").c_str()));
324 SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES);
325 SendMessage(dialog, BFFM_SETSELECTION, TRUE,
326 LPARAM(data->discDir.c_str()));
327 break;
328 case BFFM_SELCHANGED:
329 {
330 SHFILEINFO info;
331
332 SHGetFileInfo(LPCSTR(l), 0, &info, sizeof(info), SHGFI_DISPLAYNAME
333 | SHGFI_PIDL);
334 SendMessage(dialog, BFFM_SETSTATUSTEXT, 0,
335 LPARAM(info.szDisplayName));
336
337 char folder[MAX_PATH];
338
339 if (!SHGetPathFromIDList(LPCITEMIDLIST(l), folder))
340 {
341 SendMessage(dialog, BFFM_ENABLEOK, 0, 0);
342 }
343 }
344 break;
345 }
346
347 return 0;
348 }
349
350 INT_PTR DiscBrowse::start(HWND dialog, UINT msg, WPARAM w, LPARAM l)
351 {
352 DiscBrowse* data = which(dialog);
353
354 switch (msg)
355 {
356 case WM_INITDIALOG:
357 center(GetParent(dialog));
358 SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon));
359
360 data = which(dialog, l);
361 break;
362 case WM_NOTIFY:
363 {
364 LPNMHDR nm = LPNMHDR(l);
365
366 switch (nm->code)
367 {
368 case PSN_SETACTIVE:
369 PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH |
370 PSWIZB_NEXT);
371
372 {
373 SHFILEINFO info;
374
375 SHGetFileInfo(data->discDir.c_str(), 0, &info,
376 sizeof(info), SHGFI_ICONLOCATION);
377
378 HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
379 info.iIcon);
380
381 SendDlgItemMessage(dialog, IDC_BEGIN_ICON, STM_SETIMAGE,
382 IMAGE_ICON, LPARAM(icon));
383 }
384
385 {
386 SHFILEINFO info;
387
388 SHGetFileInfo(data->discDir.c_str(), 0, &info,
389 sizeof(info), SHGFI_DISPLAYNAME);
390
391 SetDlgItemText(dialog, IDC_BEGIN_TEXT, info.szDisplayName);
392 }
393 break;
394 case PSN_WIZNEXT:
395 SetCurrentDirectory(data->discDir.c_str());
396 break;
397 }
398 }
399 break;
400 case WM_COMMAND:
401 switch (LOWORD(w))
402 {
403 case IDC_BEGIN_BROWSE:
404 data->setDiscDir(dialog);
405
406 {
407 SHFILEINFO info;
408
409 SHGetFileInfo(data->discDir.c_str(), 0, &info, sizeof(info),
410 SHGFI_ICONLOCATION);
411
412 HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
413 info.iIcon);
414
415 SendDlgItemMessage(dialog, IDC_BEGIN_ICON, STM_SETIMAGE,
416 IMAGE_ICON, LPARAM(icon));
417 }
418
419 {
420 SHFILEINFO info;
421
422 SHGetFileInfo(data->discDir.c_str(), 0, &info,
423 sizeof(info), SHGFI_DISPLAYNAME);
424
425 SetDlgItemText(dialog, IDC_BEGIN_TEXT, info.szDisplayName);
426 }
427 break;
428 }
429 }
430
431 return FALSE;
432 }
433
434 INT_PTR DiscBrowse::browse(HWND dialog, UINT msg, WPARAM w, LPARAM l)
435 {
436 DiscBrowse* data = which(dialog);
437
438 switch (msg)
439 {
440 case WM_INITDIALOG:
441 data = which(dialog, l);
442
443 {
444 LVCOLUMN number, name, file, size;
445
446 number.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
447 number.cx = 56;
448 number.pszText = "Number";
449 number.iSubItem = 0;
450 name.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
451 name.cx = 224;
452 name.pszText = "Client Name";
453 name.iSubItem = 1;
454 file.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
455 file.fmt = LVCFMT_IMAGE;
456 file.cx = 152;
457 file.pszText = "File Name";
458 file.iSubItem = 2;
459 size.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH;
460 size.cx = 68;
461 size.pszText = "Size";
462 size.iSubItem = 3;
463
464 ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 0,
465 &file);
466 ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 0,
467 &number);
468 ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 1,
469 &name);
470 ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 3,
471 &size);
472 }
473 break;
474 case WM_NOTIFY:
475 if (w == IDC_BROWSE_DISC)
476 {
477 LPNMITEMACTIVATE ni = LPNMITEMACTIVATE(l);
478
479 switch (ni->hdr.code)
480 {
481 case NM_DBLCLK:
482 if (ni->iItem != -1)
483 {
484 //
485 }
486 break;
487 }
488 }
489 else
490 {
491 LPNMHDR nm = LPNMHDR(l);
492
493 switch (nm->code)
494 {
495 case PSN_SETACTIVE:
496 PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK |
497 PSWIZB_FINISH);
498 data->populate(dialog);
499
500 {
501 SHFILEINFO info;
502
503 SHGetFileInfo(data->discDir.c_str(), 0, &info,
504 sizeof(info), SHGFI_ICONLOCATION);
505
506 HICON icon = ExtractIcon(gui.instance, info.szDisplayName,
507 info.iIcon);
508
509 SendDlgItemMessage(dialog, IDC_BROWSE_ICON, STM_SETIMAGE,
510 IMAGE_ICON, LPARAM(icon));
511 }
512
513 {
514 SHFILEINFO info;
515
516 SHGetFileInfo(data->discDir.c_str(), 0, &info,
517 sizeof(info), SHGFI_DISPLAYNAME);
518
519 SetDlgItemText(dialog, IDC_BROWSE_TEXT,
520 info.szDisplayName);
521 }
522 break;
523 case PSN_WIZBACK:
524 ListView_DeleteAllItems(GetDlgItem(dialog, IDC_BROWSE_DISC));
525 break;
526 }
527 }
528 break;
529 }
530
531 return FALSE;
532 }