1 |
// Vance Thrift and Biller File Utility 2 |
2 |
// |
3 |
// Douglas Thrift |
4 |
// |
5 |
// $Id: DiscBrowse.cxx,v 1.4 2003/08/29 04:16:30 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 |
numberWidth = 56; |
43 |
nameWidth = 224; |
44 |
fileWidth = 152; |
45 |
sizeWidth = 72; |
46 |
|
47 |
// start |
48 |
wizard[0].dwSize = sizeof(wizard[0]); |
49 |
wizard[0].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | |
50 |
PSP_USEHEADERSUBTITLE; |
51 |
wizard[0].hInstance = gui.instance; |
52 |
wizard[0].pszTemplate = MAKEINTRESOURCE(IDD_BEGIN); |
53 |
wizard[0].pszTitle = title.c_str(); |
54 |
wizard[0].pfnDlgProc = start; |
55 |
wizard[0].lParam = number; |
56 |
wizard[0].pszHeaderTitle = "Start"; |
57 |
wizard[0].pszHeaderSubTitle = "Change any settings before browsing."; |
58 |
|
59 |
// browse |
60 |
wizard[1].dwSize = sizeof(wizard[1]); |
61 |
wizard[1].dwFlags = PSP_DEFAULT | PSP_USETITLE | PSP_USEHEADERTITLE | |
62 |
PSP_USEHEADERSUBTITLE; |
63 |
wizard[1].hInstance = gui.instance; |
64 |
wizard[1].pszTemplate = MAKEINTRESOURCE(IDD_BROWSE); |
65 |
wizard[1].pszTitle = title.c_str(); |
66 |
wizard[1].pfnDlgProc = browse; |
67 |
wizard[1].lParam = number; |
68 |
wizard[1].pszHeaderTitle = "Browse"; |
69 |
wizard[1].pszHeaderSubTitle = "View documents on the disc."; |
70 |
} |
71 |
|
72 |
DiscBrowse::~DiscBrowse() |
73 |
{ |
74 |
DestroyMenu(popup); |
75 |
browsers.erase(number); |
76 |
} |
77 |
|
78 |
void DiscBrowse::run(void) |
79 |
{ |
80 |
loadDir(); |
81 |
|
82 |
PROPSHEETHEADER header; |
83 |
|
84 |
// header |
85 |
header.dwSize = sizeof(header); |
86 |
header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_PROPSHEETPAGE | |
87 |
PSH_USEICONID | PSH_WIZARD97 | PSH_WIZARDHASFINISH; |
88 |
header.hwndParent = NULL; |
89 |
header.hInstance = gui.instance; |
90 |
header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON); |
91 |
header.nPages = 2; |
92 |
header.nStartPage = 0; |
93 |
header.ppsp = wizard; |
94 |
header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP); |
95 |
|
96 |
PropertySheet(&header); |
97 |
saveDir(); |
98 |
} |
99 |
|
100 |
unsigned DiscBrowse::count = 0; |
101 |
map<unsigned, DiscBrowse*> DiscBrowse::browsers; |
102 |
|
103 |
map<HWND, DiscBrowse*> DiscBrowse::windows; |
104 |
|
105 |
void DiscBrowse::loadDir(void) |
106 |
{ |
107 |
HKEY key; |
108 |
|
109 |
if (RegOpenKeyEx(HKEY_CURRENT_USER, |
110 |
"Software\\DouglasThrift\\VTBFileUtil2", 0, KEY_QUERY_VALUE, &key) == |
111 |
ERROR_SUCCESS) |
112 |
{ |
113 |
DWORD type; |
114 |
char data[MAX_PATH]; |
115 |
DWORD size = MAX_PATH; |
116 |
|
117 |
if (RegQueryValueEx(key, "DiscDir", NULL, &type, LPBYTE(data), &size) |
118 |
== ERROR_SUCCESS) |
119 |
{ |
120 |
data[size - 1] = '\0'; |
121 |
|
122 |
switch (type) |
123 |
{ |
124 |
case REG_EXPAND_SZ: |
125 |
{ |
126 |
char folder[MAX_PATH]; |
127 |
|
128 |
ExpandEnvironmentStrings(data, folder, MAX_PATH); |
129 |
|
130 |
discDir = folder; |
131 |
} |
132 |
break; |
133 |
case REG_SZ: |
134 |
discDir = data; |
135 |
break; |
136 |
default: |
137 |
setDiscDir(); |
138 |
break; |
139 |
} |
140 |
} |
141 |
else |
142 |
{ |
143 |
setDiscDir(); |
144 |
} |
145 |
|
146 |
RegCloseKey(key); |
147 |
} |
148 |
else |
149 |
{ |
150 |
setDiscDir(); |
151 |
} |
152 |
|
153 |
if (debug) cerr << "discDir = " << discDir << "\n"; |
154 |
} |
155 |
|
156 |
void DiscBrowse::saveDir(void) |
157 |
{ |
158 |
HKEY key; |
159 |
|
160 |
if (RegCreateKeyEx(HKEY_CURRENT_USER, |
161 |
"Software\\DouglasThrift\\VTBFileUtil2", 0, NULL, |
162 |
REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key, |
163 |
NULL) == ERROR_SUCCESS) |
164 |
{ |
165 |
DWORD type; |
166 |
char data[MAX_PATH]; |
167 |
DWORD size = MAX_PATH; |
168 |
|
169 |
if (RegQueryValueEx(key, "DiscDir", NULL, &type, LPBYTE(data), &size) |
170 |
== ERROR_SUCCESS) |
171 |
{ |
172 |
data[size - 1] = '\0'; |
173 |
} |
174 |
else |
175 |
{ |
176 |
data[0] = '\0'; |
177 |
} |
178 |
|
179 |
if (discDir != data || type != REG_SZ) |
180 |
{ |
181 |
if (RegSetValueEx(key, "DiscDir", 0, REG_SZ, |
182 |
LPBYTE(discDir.c_str()), discDir.length() + 1) != |
183 |
ERROR_SUCCESS) |
184 |
{ |
185 |
error(); |
186 |
} |
187 |
} |
188 |
|
189 |
RegCloseKey(key); |
190 |
} |
191 |
else |
192 |
{ |
193 |
error(); |
194 |
} |
195 |
} |
196 |
|
197 |
void DiscBrowse::setDiscDir(HWND parent) |
198 |
{ |
199 |
BROWSEINFO info; |
200 |
|
201 |
info.hwndOwner = parent; |
202 |
info.pidlRoot = NULL; |
203 |
info.pszDisplayName = NULL; |
204 |
info.lpszTitle = "Select the Disc"; |
205 |
info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; |
206 |
info.lpfn = browse; |
207 |
info.lParam = MAKELPARAM(number, true); |
208 |
info.iImage = 0; |
209 |
|
210 |
do |
211 |
{ |
212 |
LPITEMIDLIST id = SHBrowseForFolder(&info); |
213 |
|
214 |
if (id != NULL) |
215 |
{ |
216 |
char folder[MAX_PATH]; |
217 |
|
218 |
if (SHGetPathFromIDList(id, folder)) discDir = folder; |
219 |
} |
220 |
|
221 |
LPMALLOC destruct; |
222 |
|
223 |
SHGetMalloc(&destruct); |
224 |
destruct->Free(id); |
225 |
destruct->Release(); |
226 |
|
227 |
if (discDir == "") |
228 |
{ |
229 |
switch (MessageBox(parent, "Disc needs to be selected.", |
230 |
title.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR)) |
231 |
{ |
232 |
case IDABORT: |
233 |
exit(1); |
234 |
break; |
235 |
case IDRETRY: |
236 |
break; |
237 |
case IDIGNORE: |
238 |
Beep(2200, 250); |
239 |
Beep(1100, 500); |
240 |
Beep(3300, 250); |
241 |
exit(2); |
242 |
break; |
243 |
} |
244 |
} |
245 |
} |
246 |
while (discDir == ""); |
247 |
|
248 |
if (debug) cerr << "discDir = " << discDir << "\n"; |
249 |
} |
250 |
|
251 |
DiscBrowse* DiscBrowse::which(HWND window) |
252 |
{ |
253 |
map<HWND, DiscBrowse*>::iterator itor = windows.find(window); |
254 |
|
255 |
return itor->second; |
256 |
} |
257 |
|
258 |
DiscBrowse* DiscBrowse::which(HWND window, LPARAM l) |
259 |
{ |
260 |
LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l); |
261 |
map<unsigned, DiscBrowse*>::iterator itor = browsers.find(page->lParam); |
262 |
|
263 |
windows.insert(pair<HWND, DiscBrowse*>(window, itor->second)); |
264 |
|
265 |
return itor->second; |
266 |
} |
267 |
|
268 |
int DiscBrowse::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d) |
269 |
{ |
270 |
map<unsigned, DiscBrowse*>::iterator itor = browsers.find(LOWORD(d)); |
271 |
DiscBrowse* data = itor->second; |
272 |
|
273 |
switch (msg) |
274 |
{ |
275 |
case BFFM_INITIALIZED: |
276 |
center(dialog); |
277 |
SendMessage(dialog, BFFM_SETOKTEXT, 0, |
278 |
LPARAM(toWide("&Select").c_str())); |
279 |
SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES); |
280 |
SendMessage(dialog, BFFM_SETSELECTION, TRUE, |
281 |
LPARAM(data->discDir.c_str())); |
282 |
break; |
283 |
case BFFM_SELCHANGED: |
284 |
{ |
285 |
IShellFolder* object; |
286 |
|
287 |
SHGetDesktopFolder(&object); |
288 |
|
289 |
STRRET thing; |
290 |
char* folder; |
291 |
|
292 |
object->GetDisplayNameOf(LPCITEMIDLIST(l), SHGDN_FORPARSING, |
293 |
&thing); |
294 |
StrRetToStr(&thing, LPCITEMIDLIST(l), &folder); |
295 |
SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, LPARAM(folder)); |
296 |
|
297 |
if (PathIsUNCServer(folder)) |
298 |
{ |
299 |
SendMessage(dialog, BFFM_ENABLEOK, 0, 0); |
300 |
} |
301 |
|
302 |
CoTaskMemFree(folder); |
303 |
object->Release(); |
304 |
} |
305 |
break; |
306 |
} |
307 |
|
308 |
return 0; |
309 |
} |
310 |
|
311 |
INT_PTR DiscBrowse::start(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
312 |
{ |
313 |
DiscBrowse* data = which(dialog); |
314 |
|
315 |
switch (msg) |
316 |
{ |
317 |
case WM_INITDIALOG: |
318 |
center(GetParent(dialog)); |
319 |
SendMessage(GetParent(dialog), WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
320 |
|
321 |
data = which(dialog, l); |
322 |
break; |
323 |
case WM_NOTIFY: |
324 |
{ |
325 |
LPNMHDR nm = LPNMHDR(l); |
326 |
|
327 |
switch (nm->code) |
328 |
{ |
329 |
case PSN_SETACTIVE: |
330 |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_FINISH | |
331 |
PSWIZB_NEXT); |
332 |
|
333 |
{ |
334 |
SHFILEINFO info; |
335 |
|
336 |
SHGetFileInfo(data->discDir.c_str(), 0, &info, |
337 |
sizeof(info), SHGFI_ICONLOCATION); |
338 |
|
339 |
HICON icon = ExtractAssociatedIcon(gui.instance, |
340 |
info.szDisplayName, LPWORD(&info.iIcon)); |
341 |
|
342 |
SendDlgItemMessage(dialog, IDC_BEGIN_ICON, STM_SETIMAGE, |
343 |
IMAGE_ICON, LPARAM(icon)); |
344 |
} |
345 |
|
346 |
{ |
347 |
char folder[72]; |
348 |
|
349 |
PathCompactPathEx(folder, data->discDir.c_str(), 72, 0); |
350 |
SetDlgItemText(dialog, IDC_BEGIN_TEXT, folder); |
351 |
} |
352 |
break; |
353 |
} |
354 |
} |
355 |
break; |
356 |
case WM_COMMAND: |
357 |
switch (LOWORD(w)) |
358 |
{ |
359 |
case IDC_BEGIN_BROWSE: |
360 |
data->setDiscDir(dialog); |
361 |
|
362 |
{ |
363 |
SHFILEINFO info; |
364 |
|
365 |
SHGetFileInfo(data->discDir.c_str(), 0, &info, sizeof(info), |
366 |
SHGFI_ICONLOCATION); |
367 |
|
368 |
HICON icon = ExtractAssociatedIcon(gui.instance, |
369 |
info.szDisplayName, LPWORD(&info.iIcon)); |
370 |
|
371 |
SendDlgItemMessage(dialog, IDC_BEGIN_ICON, STM_SETIMAGE, |
372 |
IMAGE_ICON, LPARAM(icon)); |
373 |
} |
374 |
|
375 |
{ |
376 |
char folder[72]; |
377 |
|
378 |
PathCompactPathEx(folder, data->discDir.c_str(), 72, 0); |
379 |
SetDlgItemText(dialog, IDC_BEGIN_TEXT, folder); |
380 |
} |
381 |
break; |
382 |
} |
383 |
} |
384 |
|
385 |
return FALSE; |
386 |
} |
387 |
|
388 |
INT_PTR DiscBrowse::browse(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
389 |
{ |
390 |
DiscBrowse* data = which(dialog); |
391 |
|
392 |
switch (msg) |
393 |
{ |
394 |
case WM_INITDIALOG: |
395 |
data = which(dialog, l); |
396 |
|
397 |
{ |
398 |
LVCOLUMN number, name, file, size; |
399 |
|
400 |
number.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; |
401 |
number.cx = data->numberWidth; |
402 |
number.pszText = "Number"; |
403 |
number.iSubItem = 0; |
404 |
name.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; |
405 |
name.cx = data->nameWidth; |
406 |
name.pszText = "Client Name"; |
407 |
name.iSubItem = 1; |
408 |
file.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; |
409 |
file.fmt = LVCFMT_IMAGE; |
410 |
file.cx = data->fileWidth; |
411 |
file.pszText = "File Name"; |
412 |
file.iSubItem = 2; |
413 |
size.mask = LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH; |
414 |
size.cx = data->sizeWidth; |
415 |
size.pszText = "Size"; |
416 |
size.iSubItem = 3; |
417 |
|
418 |
ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 0, |
419 |
&file); |
420 |
ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 0, |
421 |
&number); |
422 |
ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 1, |
423 |
&name); |
424 |
ListView_InsertColumn(GetDlgItem(dialog, IDC_BROWSE_DISC), 3, |
425 |
&size); |
426 |
} |
427 |
break; |
428 |
case WM_NOTIFY: |
429 |
if (w == IDC_BROWSE_DISC) |
430 |
{ |
431 |
LPNMITEMACTIVATE ni = LPNMITEMACTIVATE(l); |
432 |
|
433 |
switch (ni->hdr.code) |
434 |
{ |
435 |
case NM_DBLCLK: |
436 |
// |
437 |
break; |
438 |
} |
439 |
} |
440 |
else |
441 |
{ |
442 |
LPNMHDR nm = LPNMHDR(l); |
443 |
|
444 |
switch (nm->code) |
445 |
{ |
446 |
case PSN_SETACTIVE: |
447 |
PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_BACK | |
448 |
PSWIZB_FINISH); |
449 |
break; |
450 |
} |
451 |
} |
452 |
break; |
453 |
} |
454 |
|
455 |
return FALSE; |
456 |
} |