ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/proj/trunk/VTBFileUtil2/ScanUtility.cxx
Revision: 271
Committed: 2003-08-19T22:49:34-07:00 (19 years, 5 months ago) by douglas
File size: 8656 byte(s)
Log Message:
Start page of ScanUtility pretty much works.

File Contents

# Content
1 // Vance Thrift and Biller File Utility 2
2 //
3 // Douglas Thrift
4 //
5 // $Id: ScanUtility.cxx,v 1.5 2003/08/20 05:49:34 douglas Exp $
6
7 #include "ScanUtility.h"
8
9 ScanUtility::ScanUtility()
10 {
11 number = count++;
12 utilities.insert(pair<unsigned, ScanUtility*>(number, this));
13 title = new char[programName.length() + 16];
14
15 sprintf(title, "%s - Scan Utility", programName.c_str());
16 loadDirs();
17
18 // start
19 wizard[0].dwSize = sizeof(wizard[0]);
20 wizard[0].dwFlags = PSP_DEFAULT | PSP_USEHICON | PSP_USETITLE |
21 PSP_USEHEADERTITLE | PSP_USEHEADERSUBTITLE;
22 wizard[0].hInstance = gui.instance;
23 wizard[0].pszTemplate = MAKEINTRESOURCE(IDD_START);
24 wizard[0].hIcon = gui.icon;
25 wizard[0].pszTitle = title;
26 wizard[0].pfnDlgProc = start;
27 wizard[0].lParam = number;
28 wizard[0].pszHeaderTitle = "Start";
29 wizard[0].pszHeaderSubTitle = "Change any settings before scanning.";
30 }
31
32 ScanUtility::~ScanUtility()
33 {
34 utilities.erase(number);
35 saveDirs();
36
37 delete [] title;
38 }
39
40 void ScanUtility::run(void)
41 {
42 PROPSHEETHEADER header;
43
44 // header
45 header.dwSize = sizeof(header);
46 header.dwFlags = PSH_DEFAULT | PSH_HEADER | PSH_PROPSHEETPAGE |
47 PSH_USEICONID | PSH_WIZARD97;
48 header.hwndParent = NULL;
49 header.hInstance = gui.instance;
50 header.pszIcon = MAKEINTRESOURCE(IDI_VTB_ICON);
51 header.nPages = 1;
52 header.nStartPage = 0;
53 header.ppsp = wizard;
54 header.pszbmHeader = MAKEINTRESOURCE(IDB_VTB_BMP);
55
56 PropertySheet(&header);
57 }
58
59 unsigned ScanUtility::count = 0;
60 map<unsigned, ScanUtility*> ScanUtility::utilities;
61 map<HWND, ScanUtility*> ScanUtility::windows;
62
63 void ScanUtility::loadDirs(void)
64 {
65 HKEY key;
66
67 if (RegOpenKeyEx(HKEY_CURRENT_USER,
68 "Software\\DouglasThrift\\VTBFileUtil2", 0, KEY_QUERY_VALUE, &key) ==
69 ERROR_SUCCESS)
70 {
71 DWORD type;
72 char data[MAX_PATH];
73 DWORD size = MAX_PATH;
74
75 if (RegQueryValueEx(key, "ScanDir", NULL, &type, LPBYTE(data), &size)
76 == ERROR_SUCCESS)
77 {
78 data[size - 1] = '\0';
79
80 switch (type)
81 {
82 case REG_EXPAND_SZ:
83 scanDir = data;
84 scanEnv = true;
85 break;
86 case REG_SZ:
87 scanDir = data;
88 scanEnv = false;
89 break;
90 default:
91 setScanDir();
92 break;
93 }
94 }
95 else
96 {
97 setScanDir();
98 }
99
100 size = MAX_PATH;
101
102 if (RegQueryValueEx(key, "SaveDir", NULL, &type, LPBYTE(data), &size)
103 == ERROR_SUCCESS)
104 {
105 data[size - 1] = '\0';
106
107 switch (type)
108 {
109 case REG_EXPAND_SZ:
110 saveDir = data;
111 saveEnv = true;
112 break;
113 case REG_SZ:
114 saveDir = data;
115 saveEnv = false;
116 break;
117 default:
118 setSaveDir();
119 break;
120 }
121 }
122 else
123 {
124 setSaveDir();
125 }
126
127 RegCloseKey(key);
128 }
129 else
130 {
131 setScanDir();
132 setSaveDir();
133 }
134
135 if (debug) cerr << "scanDir = " << scanDir << "\n"
136 << "scanEnv = " << scanEnv << "\n"
137 << "saveDir = " << saveDir << "\n"
138 << "saveEnv = " << saveEnv << "\n";
139 }
140
141 void ScanUtility::saveDirs(void)
142 {
143 HKEY key;
144
145 if (RegCreateKeyEx(HKEY_CURRENT_USER,
146 "Software\\DouglasThrift\\VTBFileUtil2", 0, NULL,
147 REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &key,
148 NULL) == ERROR_SUCCESS)
149 {
150 DWORD type;
151 char data[MAX_PATH];
152 DWORD size = MAX_PATH;
153
154 if (RegQueryValueEx(key, "ScanDir", NULL, &type, LPBYTE(data), &size)
155 == ERROR_SUCCESS)
156 {
157 data[size - 1] = '\0';
158 }
159 else
160 {
161 data[0] = '\0';
162 }
163
164 if (scanDir != data || type != (scanEnv ? REG_EXPAND_SZ : REG_SZ))
165 {
166 if (RegSetValueEx(key, "ScanDir", 0, scanEnv ? REG_EXPAND_SZ :
167 REG_SZ, LPBYTE(scanDir.c_str()), scanDir.length() + 1) !=
168 ERROR_SUCCESS)
169 {
170 error();
171 }
172 }
173
174 size = MAX_PATH;
175
176 if (RegQueryValueEx(key, "SaveDir", NULL, &type, LPBYTE(data), &size)
177 == ERROR_SUCCESS)
178 {
179 data[size - 1] = '\0';
180 }
181 else
182 {
183 data[0] = '\0';
184 }
185
186 if (saveDir != data || type != (saveEnv ? REG_EXPAND_SZ : REG_SZ))
187 {
188 if (RegSetValueEx(key, "SaveDir", 0, saveEnv ? REG_EXPAND_SZ :
189 REG_SZ, LPBYTE(saveDir.c_str()), saveDir.length() + 1) !=
190 ERROR_SUCCESS)
191 {
192 error();
193 }
194 }
195
196 RegCloseKey(key);
197 }
198 else
199 {
200 error();
201 }
202 }
203
204 void ScanUtility::setScanDir(HWND parent)
205 {
206 BROWSEINFO info;
207
208 info.hwndOwner = parent;
209 info.pidlRoot = NULL;
210 info.pszDisplayName = NULL;
211 info.lpszTitle = "Select the Scan Directory";
212 info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
213 info.lpfn = browse;
214 info.lParam = MAKELPARAM(number, true);
215 info.iImage = 0;
216
217 do
218 {
219 LPITEMIDLIST id = SHBrowseForFolder(&info);
220
221 if (id != NULL)
222 {
223 char folder[MAX_PATH];
224
225 if (SHGetPathFromIDList(id, folder))
226 {
227 scanDir = folder;
228 scanEnv = false;
229 }
230 }
231
232 LPMALLOC destruct;
233
234 SHGetMalloc(&destruct);
235 destruct->Free(id);
236 destruct->Release();
237
238 if (scanDir == "")
239 {
240 switch (MessageBox(parent, "Scan Directory needs to be selected.",
241 programName.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
242 {
243 case IDABORT:
244 exit(1);
245 break;
246 case IDRETRY:
247 break;
248 case IDIGNORE:
249 Beep(2200, 250);
250 Beep(1100, 500);
251 Beep(3300, 250);
252 exit(2);
253 break;
254 }
255 }
256 }
257 while (scanDir == "");
258 }
259
260 void ScanUtility::setSaveDir(HWND parent)
261 {
262 BROWSEINFO info;
263
264 info.hwndOwner = parent;
265 info.pidlRoot = NULL;
266 info.pszDisplayName = NULL;
267 info.lpszTitle = "Select the Save Directory";
268 info.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
269 info.lpfn = browse;
270 info.lParam = MAKELPARAM(number, false);
271 info.iImage = 0;
272
273 do
274 {
275 LPITEMIDLIST id = SHBrowseForFolder(&info);
276
277 if (id != NULL)
278 {
279 char folder[MAX_PATH];
280
281 if (SHGetPathFromIDList(id, folder))
282 {
283 saveDir = folder;
284 saveEnv = false;
285 }
286 }
287
288 LPMALLOC destruct;
289
290 SHGetMalloc(&destruct);
291 destruct->Free(id);
292 destruct->Release();
293
294 if (saveDir == "")
295 {
296 switch (MessageBox(parent, "Scan Directory needs to be selected.",
297 programName.c_str(), MB_ABORTRETRYIGNORE | MB_ICONERROR))
298 {
299 case IDABORT:
300 exit(1);
301 break;
302 case IDRETRY:
303 break;
304 case IDIGNORE:
305 Beep(2200, 250);
306 Beep(1100, 500);
307 Beep(3300, 250);
308 exit(2);
309 break;
310 }
311 }
312 }
313 while (saveDir == "");
314 }
315
316 int ScanUtility::browse(HWND dialog, UINT msg, LPARAM l, LPARAM d)
317 {
318 map<unsigned, ScanUtility*>::iterator itor = utilities.find(LOWORD(d));
319 ScanUtility* data = itor->second;
320
321 switch (msg)
322 {
323 case BFFM_INITIALIZED:
324 center(dialog);
325 SendMessage(dialog, BFFM_SETOKTEXT, 0,
326 LPARAM(toWide("&Select").c_str()));
327 SendMessage(dialog, BFFM_SETEXPANDED, FALSE, CSIDL_DRIVES);
328 if (HIWORD(d) ? data->scanEnv : data->saveEnv)
329 {
330 char folder[MAX_PATH];
331
332 ExpandEnvironmentStrings(HIWORD(d) ? data->scanDir.c_str() :
333 data->saveDir.c_str(), folder, MAX_PATH);
334 SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(folder));
335 }
336 else
337 {
338 SendMessage(dialog, BFFM_SETSELECTION, TRUE, LPARAM(HIWORD(d) ?
339 data->scanDir.c_str() : data->saveDir.c_str()));
340 }
341 break;
342 case BFFM_SELCHANGED:
343 {
344 IShellFolder* object;
345
346 SHGetDesktopFolder(&object);
347
348 STRRET thing;
349 char* folder;
350
351 object->GetDisplayNameOf(LPCITEMIDLIST(l), SHGDN_FORPARSING,
352 &thing);
353 StrRetToStr(&thing, LPCITEMIDLIST(l), &folder);
354 SendMessage(dialog, BFFM_SETSTATUSTEXT, 0, LPARAM(folder));
355
356 if (PathIsUNCServer(folder))
357 {
358 SendMessage(dialog, BFFM_ENABLEOK, 0, 0);
359 }
360
361 CoTaskMemFree(folder);
362 object->Release();
363 }
364 break;
365 }
366
367 return 0;
368 }
369
370 INT_PTR ScanUtility::start(HWND dialog, UINT msg, WPARAM w, LPARAM l)
371 {
372 map<HWND, ScanUtility*>::iterator itor = windows.find(dialog);
373 ScanUtility* data = itor->second;
374
375 switch (msg)
376 {
377 case WM_INITDIALOG:
378 center(GetParent(dialog));
379 {
380 LPPROPSHEETPAGE page = LPPROPSHEETPAGE(l);
381 map<unsigned, ScanUtility*>::iterator itor =
382 utilities.find(page->lParam);
383
384 windows.insert(pair<HWND, ScanUtility*>(dialog, itor->second));
385 }
386 break;
387 case WM_NOTIFY:
388 {
389 LPNMHDR nm = (LPNMHDR) l;
390
391 switch (nm->code)
392 {
393 case PSN_SETACTIVE:
394 PropSheet_SetWizButtons(GetParent(dialog), PSWIZB_NEXT);
395 {
396 char folder[44];
397
398 PathCompactPathEx(folder, data->scanDir.c_str(), 44, 0);
399 SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder);
400 PathCompactPathEx(folder, data->saveDir.c_str(), 44, 0);
401 SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
402 }
403 break;
404 }
405 }
406 break;
407 case WM_COMMAND:
408 switch (LOWORD(w))
409 {
410 case IDC_START_SCAN_BROWSE:
411 data->setScanDir(dialog);
412 {
413 char folder[44];
414
415 PathCompactPathEx(folder, data->scanDir.c_str(), 44, 0);
416 SetDlgItemText(dialog, IDC_START_SCAN_TEXT, folder);
417 }
418 break;
419 case IDC_START_SAVE_BROWSE:
420 data->setSaveDir(dialog);
421 {
422 char folder[44];
423
424 PathCompactPathEx(folder, data->saveDir.c_str(), 44, 0);
425 SetDlgItemText(dialog, IDC_START_SAVE_TEXT, folder);
426 }
427 break;
428 }
429 break;
430 }
431
432 return FALSE;
433 }