2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
< |
// $Id: VTBFileUtil2.cxx,v 1.4 2003/08/16 08:40:55 douglas Exp $ |
5 |
> |
// $Id: VTBFileUtil2.cxx,v 1.15 2003/09/12 04:26:54 douglas Exp $ |
6 |
|
|
7 |
|
#include "VTBFileUtil2.h" |
8 |
+ |
#include "Chooser.h" |
9 |
+ |
#include "DiscBrowse.h" |
10 |
+ |
#include "ScanUtility.h" |
11 |
|
|
12 |
|
#include <io.h> |
13 |
|
#include <fcntl.h> |
14 |
|
|
12 |
– |
#include "resource.h" |
13 |
– |
|
15 |
|
bool debug = false; |
16 |
|
string program; |
17 |
|
string programName = "Vance Thrift and Biller File Utility 2"; |
18 |
< |
string programVersion = "2.0alpha"; |
18 |
> |
string programVersion = "2.0"; |
19 |
> |
Gui gui; |
20 |
|
|
21 |
< |
HINSTANCE instance; |
22 |
< |
HICON icon; |
21 |
< |
Mode choiceMode = none; |
22 |
< |
bool choiceAlways = false; |
23 |
< |
UINT_PTR tips = 0; |
24 |
< |
|
25 |
< |
INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l); |
26 |
< |
INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l); |
27 |
< |
INT_PTR CALLBACK choice(HWND dialog, UINT msg, WPARAM w, LPARAM l); |
21 |
> |
static INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l); |
22 |
> |
static INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l); |
23 |
|
|
24 |
< |
inline void arguments(vector<string>& args, const string& command) |
24 |
> |
static inline void arguments(vector<string>& args, const string& command) |
25 |
|
{ |
26 |
|
istringstream line(command); |
27 |
|
string arg; |
39 |
|
line.get(); |
40 |
|
} |
41 |
|
|
42 |
< |
args.push_back(arg); |
42 |
> |
if (arg != "") |
43 |
> |
{ |
44 |
> |
args.push_back(arg); |
45 |
> |
} |
46 |
|
} |
47 |
|
while (line.good()); |
48 |
|
} |
49 |
|
|
50 |
< |
inline void munge(void) |
50 |
> |
static inline void munge(void) |
51 |
|
{ |
52 |
|
AllocConsole(); |
53 |
|
SetConsoleTitle(programName.c_str()); |
73 |
|
cerr.sync_with_stdio(); |
74 |
|
} |
75 |
|
|
76 |
< |
inline void usage(HWND parent) |
76 |
> |
void usage(HWND parent) |
77 |
|
{ |
78 |
< |
DialogBox(instance, MAKEINTRESOURCE(IDD_USAGE), parent, usage); |
81 |
< |
} |
82 |
< |
|
83 |
< |
inline void version(HWND parent) |
84 |
< |
{ |
85 |
< |
DialogBox(instance, MAKEINTRESOURCE(IDD_VERSION), parent, version); |
78 |
> |
DialogBox(gui.instance, MAKEINTRESOURCE(IDD_USAGE), parent, usage); |
79 |
|
} |
80 |
|
|
81 |
< |
inline void choice(Mode& mode, HWND parent) |
81 |
> |
void version(HWND parent) |
82 |
|
{ |
83 |
< |
DialogBox(instance, MAKEINTRESOURCE(IDD_CHOICE), parent, choice); |
91 |
< |
|
92 |
< |
mode = choiceMode; |
83 |
> |
DialogBox(gui.instance, MAKEINTRESOURCE(IDD_VERSION), parent, version); |
84 |
|
} |
85 |
|
|
86 |
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR |
89 |
|
vector<string> args; |
90 |
|
|
91 |
|
InitCommonControls(); |
92 |
+ |
CoInitialize(NULL); |
93 |
|
arguments(args, GetCommandLine()); |
94 |
|
|
103 |
– |
instance = hInstance; |
95 |
|
program = args[0]; |
96 |
|
|
97 |
|
Mode mode = none; |
98 |
|
|
99 |
< |
icon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VTB_ICON)); |
99 |
> |
gui.instance = hInstance; |
100 |
> |
gui.icon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VTB_ICON)); |
101 |
> |
gui.show = nShowCmd; |
102 |
> |
|
103 |
> |
if (toAnsi(toWide("Z:\\DouglasThrift")) != "Z:\\DouglasThrift") |
104 |
> |
{ |
105 |
> |
string message = "Could not find the Microsoft Layer for Unicode."; |
106 |
> |
|
107 |
> |
switch (MessageBox(NULL, message.c_str(), programName.c_str(), |
108 |
> |
MB_ABORTRETRYIGNORE | MB_ICONERROR)) |
109 |
> |
{ |
110 |
> |
case IDABORT: |
111 |
> |
return 1; |
112 |
> |
break; |
113 |
> |
case IDRETRY: |
114 |
> |
{ |
115 |
> |
string url = string("http://www.microsoft.com/downloads/detai") |
116 |
> |
+ "ls.aspx?FamilyID=73ba7bd7-ed06-4f0d-80a4-2a7eeaee17e2&D" |
117 |
> |
+ "isplayLang=en", message = string("Click OK when the Mi") |
118 |
> |
+ "crosoft Layer for Unicode is installed."; |
119 |
> |
|
120 |
> |
ShellExecute(NULL, NULL, url.c_str(), NULL, NULL, gui.show); |
121 |
> |
MessageBox(NULL, message.c_str(), programName.c_str(), MB_OK | |
122 |
> |
MB_ICONINFORMATION); |
123 |
> |
|
124 |
> |
STARTUPINFO start; |
125 |
> |
PROCESS_INFORMATION info; |
126 |
> |
|
127 |
> |
start.cb = sizeof(start); |
128 |
> |
start.lpReserved = NULL; |
129 |
> |
start.lpDesktop = NULL; |
130 |
> |
start.lpTitle = NULL; |
131 |
> |
start.dwFlags = STARTF_FORCEONFEEDBACK | STARTF_USESHOWWINDOW; |
132 |
> |
start.wShowWindow = gui.show; |
133 |
> |
start.cbReserved2 = 0; |
134 |
> |
start.lpReserved2 = NULL; |
135 |
> |
|
136 |
> |
CreateProcess(program.c_str(), GetCommandLine(), NULL, NULL, |
137 |
> |
FALSE, 0, NULL, NULL, &start, &info); |
138 |
> |
CloseHandle(info.hProcess); |
139 |
> |
CloseHandle(info.hThread); |
140 |
> |
} |
141 |
> |
return 0; |
142 |
> |
break; |
143 |
> |
case IDIGNORE: |
144 |
> |
break; |
145 |
> |
} |
146 |
> |
} |
147 |
|
|
148 |
|
for (unsigned index = 1; index < args.size(); index++) |
149 |
|
{ |
171 |
|
{ |
172 |
|
debug = true; |
173 |
|
|
136 |
– |
munge(); |
174 |
|
cerr.setf(ios_base::boolalpha); |
175 |
|
} |
176 |
|
} |
185 |
|
|
186 |
|
if (debug) |
187 |
|
{ |
188 |
+ |
munge(); |
189 |
|
cerr << "mode = "; |
190 |
|
|
191 |
|
switch (mode) |
207 |
|
cerr << "\n"; |
208 |
|
} |
209 |
|
|
210 |
+ |
License license; |
211 |
+ |
|
212 |
+ |
license.check(); |
213 |
+ |
|
214 |
|
if (mode == none) |
215 |
|
{ |
216 |
< |
choice(mode); |
216 |
> |
Chooser chooser; |
217 |
> |
|
218 |
> |
mode = chooser.choose(); |
219 |
|
|
220 |
|
if (debug) |
221 |
|
{ |
243 |
|
|
244 |
|
if (mode == disc) |
245 |
|
{ |
246 |
< |
MessageBox(NULL, "Disc Browse mode", programName.c_str(), |
247 |
< |
MB_ICONINFORMATION); |
246 |
> |
DiscBrowse browser; |
247 |
> |
|
248 |
> |
browser.run(); |
249 |
|
} |
250 |
|
else if (mode == scan) |
251 |
|
{ |
252 |
< |
MessageBox(NULL, "Scan Utility mode", programName.c_str(), |
253 |
< |
MB_ICONINFORMATION); |
252 |
> |
ScanUtility utility; |
253 |
> |
|
254 |
> |
utility.run(); |
255 |
|
} |
256 |
|
|
257 |
+ |
CoUninitialize(); |
258 |
+ |
|
259 |
|
if (debug) |
260 |
|
{ |
261 |
< |
cout << "Press enter key to exit . . ."; |
262 |
< |
cin.get(); |
215 |
< |
} |
261 |
> |
char cmd[MAX_PATH]; |
262 |
> |
char arg[MAX_PATH]; |
263 |
|
|
264 |
< |
return 0; |
265 |
< |
} |
264 |
> |
GetEnvironmentVariable("ComSpec", cmd, MAX_PATH); |
265 |
> |
StringCchPrintf(arg, MAX_PATH, "%s /c pause", cmd); |
266 |
|
|
267 |
< |
void tooltip(HWND tool, const string& tip) |
268 |
< |
{ |
222 |
< |
HWND tooltip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL, WS_POPUP |
223 |
< |
| TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, |
224 |
< |
CW_USEDEFAULT, CW_USEDEFAULT, tool, NULL, instance, NULL); |
225 |
< |
RECT rect; |
226 |
< |
|
227 |
< |
SetWindowPos(tooltip, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | |
228 |
< |
SWP_NOACTIVATE); |
229 |
< |
|
230 |
< |
GetClientRect(tool, &rect); |
231 |
< |
|
232 |
< |
TOOLINFO toolinfo; |
233 |
< |
char* ctip = new char[tip.length()]; |
234 |
< |
|
235 |
< |
sprintf(ctip, "%s", tip.c_str()); |
236 |
< |
|
237 |
< |
if (debug) cerr << "ctip = " << ctip << "\n"; |
238 |
< |
|
239 |
< |
toolinfo.cbSize = sizeof(TOOLINFO); |
240 |
< |
toolinfo.uFlags = TTF_SUBCLASS; |
241 |
< |
toolinfo.hwnd = tool; |
242 |
< |
toolinfo.hinst = instance; |
243 |
< |
toolinfo.uId = tips++; |
244 |
< |
toolinfo.lpszText = ctip; |
245 |
< |
toolinfo.rect.left = rect.left; |
246 |
< |
toolinfo.rect.top = rect.top; |
247 |
< |
toolinfo.rect.right = rect.right; |
248 |
< |
toolinfo.rect.bottom = rect.bottom; |
267 |
> |
STARTUPINFO start; |
268 |
> |
PROCESS_INFORMATION info; |
269 |
|
|
270 |
< |
SendMessage(tooltip, TTM_ADDTOOL, 0, LPARAM(LPTOOLINFO(&toolinfo))); |
270 |
> |
start.cb = sizeof(start); |
271 |
> |
start.lpReserved = NULL; |
272 |
> |
start.lpDesktop = NULL; |
273 |
> |
start.lpTitle = NULL; |
274 |
> |
start.dwFlags = STARTF_USESTDHANDLES; |
275 |
> |
start.cbReserved2 = 0; |
276 |
> |
start.lpReserved2 = NULL; |
277 |
> |
start.hStdInput = GetStdHandle(STD_INPUT_HANDLE); |
278 |
> |
start.hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); |
279 |
> |
start.hStdError = GetStdHandle(STD_ERROR_HANDLE); |
280 |
> |
|
281 |
> |
CreateProcess(cmd, arg, NULL, NULL, TRUE, 0, NULL, NULL, &start, &info); |
282 |
> |
CloseHandle(info.hProcess); |
283 |
> |
CloseHandle(info.hThread); |
284 |
> |
} |
285 |
> |
|
286 |
> |
return 0; |
287 |
|
} |
288 |
|
|
289 |
|
INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
292 |
|
{ |
293 |
|
case WM_INITDIALOG: |
294 |
|
center(dialog); |
295 |
< |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(icon)); |
295 |
> |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
296 |
|
SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); |
297 |
+ |
|
298 |
|
{ |
299 |
|
ostringstream usage; |
300 |
|
|
301 |
< |
usage << "Usage: VTBFileUtil [-help | -version | -disc | -scan]\n" |
302 |
< |
<< "\nOptions:\n" |
303 |
< |
<< " -help\t\tDisplay this information\n" |
304 |
< |
<< " -version\tDisplay version information\n" |
305 |
< |
<< " -disc\t\tStart in Disc Browse mode\n" |
306 |
< |
<< " -scan\t\tStart in Scan Utility mode\n"; |
301 |
> |
usage << "Usage: VTBFileUtil [-help | -version | -disc | -scan]\r" |
302 |
> |
<< "\n" |
303 |
> |
<< "\r\nOptions:\r\n" |
304 |
> |
<< " -help\t\tDisplay this information\r\n" |
305 |
> |
<< " -version\t\tDisplay version information\r\n" |
306 |
> |
<< " -disc\t\tStart in Disc Browse mode\r\n" |
307 |
> |
<< " -scan\t\tStart in Scan Utility mode\r\n"; |
308 |
|
|
309 |
< |
SendMessage(GetDlgItem(dialog, IDC_USAGE_TEXT), WM_SETTEXT, 0, |
272 |
< |
LPARAM(usage.str().c_str())); |
309 |
> |
SetDlgItemText(dialog, IDC_USAGE_TEXT, usage.str().c_str()); |
310 |
|
} |
311 |
|
break; |
312 |
|
case WM_COMMAND: |
331 |
|
{ |
332 |
|
case WM_INITDIALOG: |
333 |
|
center(dialog); |
334 |
< |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(icon)); |
334 |
> |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
335 |
|
SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); |
336 |
+ |
|
337 |
|
{ |
338 |
|
ostringstream version; |
339 |
|
|
340 |
< |
version << programName << " ( " << programVersion << " )\n\n" |
340 |
> |
version << programName << " (" << programVersion << ")\r\n\r\n" |
341 |
|
<< "Copyright © 2003, Douglas Thrift.\n"; |
342 |
|
|
343 |
< |
SendMessage(GetDlgItem(dialog, IDC_VERSION_TEXT), WM_SETTEXT, 0, |
306 |
< |
LPARAM(version.str().c_str())); |
343 |
> |
SetDlgItemText(dialog, IDC_VERSION_TEXT, version.str().c_str()); |
344 |
|
} |
345 |
|
break; |
346 |
|
case WM_COMMAND: |
351 |
|
EndDialog(dialog, w); |
352 |
|
return TRUE; |
353 |
|
default: |
317 |
– |
break; |
318 |
– |
} |
319 |
– |
break; |
320 |
– |
} |
321 |
– |
|
322 |
– |
return FALSE; |
323 |
– |
} |
324 |
– |
|
325 |
– |
INT_PTR CALLBACK choice(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
326 |
– |
{ |
327 |
– |
switch (msg) |
328 |
– |
{ |
329 |
– |
case WM_INITDIALOG: |
330 |
– |
center(dialog); |
331 |
– |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(icon)); |
332 |
– |
SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); |
333 |
– |
break; |
334 |
– |
case WM_COMMAND: |
335 |
– |
switch (LOWORD(w)) |
336 |
– |
{ |
337 |
– |
case IDC_CHOICE_DISC: |
338 |
– |
choiceMode = disc; |
339 |
– |
if (debug) cerr << "choiceMode = disc\n"; |
340 |
– |
EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE); |
341 |
– |
EnableWindow(GetDlgItem(dialog, IDOK), TRUE); |
342 |
– |
break; |
343 |
– |
case IDC_CHOICE_SCAN: |
344 |
– |
choiceMode = scan; |
345 |
– |
if (debug) cerr << "choiceMode = scan\n"; |
346 |
– |
EnableWindow(GetDlgItem(dialog, IDC_CHOICE_ALWAYS), TRUE); |
347 |
– |
EnableWindow(GetDlgItem(dialog, IDOK), TRUE); |
348 |
– |
break; |
349 |
– |
case IDC_CHOICE_ALWAYS: |
350 |
– |
choiceAlways = !choiceAlways; |
351 |
– |
if (debug) cerr << "choiceAlways = " << choiceAlways << "\n"; |
352 |
– |
break; |
353 |
– |
case IDCANCEL: |
354 |
– |
choiceMode = none; |
355 |
– |
case IDOK: |
356 |
– |
EndDialog(dialog, w); |
357 |
– |
return TRUE; |
358 |
– |
default: |
354 |
|
break; |
355 |
|
} |
356 |
|
break; |