2 |
|
// |
3 |
|
// Douglas Thrift |
4 |
|
// |
5 |
< |
// $Id: VTBFileUtil2.cxx,v 1.1 2003/08/16 00:12:57 douglas Exp $ |
5 |
> |
// $Id: VTBFileUtil2.cxx,v 1.13 2003/09/05 08:57:00 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> |
15 |
|
bool debug = false; |
16 |
|
string program; |
17 |
|
string programName = "Vance Thrift and Biller File Utility 2"; |
18 |
< |
unsigned programVersion = 0x00101000; |
18 |
> |
string programVersion = "2.0beta"; |
19 |
> |
Gui gui; |
20 |
|
|
21 |
< |
inline void arguments(vector<string>& args, const string& command) |
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 |
> |
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("Renegade Map Selector"); |
53 |
> |
SetConsoleTitle(programName.c_str()); |
54 |
|
|
55 |
|
int hin = _open_osfhandle(long(GetStdHandle(STD_INPUT_HANDLE)), _O_TEXT); |
56 |
|
int hout = _open_osfhandle(long(GetStdHandle(STD_OUTPUT_HANDLE)), _O_TEXT); |
73 |
|
cerr.sync_with_stdio(); |
74 |
|
} |
75 |
|
|
76 |
+ |
void usage(HWND parent) |
77 |
+ |
{ |
78 |
+ |
DialogBox(gui.instance, MAKEINTRESOURCE(IDD_USAGE), parent, usage); |
79 |
+ |
} |
80 |
+ |
|
81 |
+ |
void version(HWND parent) |
82 |
+ |
{ |
83 |
+ |
DialogBox(gui.instance, MAKEINTRESOURCE(IDD_VERSION), parent, version); |
84 |
+ |
} |
85 |
+ |
|
86 |
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR |
87 |
|
lpCmdLine, int nShowCmd) |
88 |
|
{ |
89 |
|
vector<string> args; |
90 |
|
|
91 |
+ |
InitCommonControls(); |
92 |
+ |
CoInitialize(NULL); |
93 |
|
arguments(args, GetCommandLine()); |
94 |
|
|
95 |
|
program = args[0]; |
96 |
|
|
97 |
+ |
Mode mode = none; |
98 |
+ |
|
99 |
+ |
gui.instance = hInstance; |
100 |
+ |
gui.icon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_VTB_ICON)); |
101 |
+ |
gui.show = nShowCmd; |
102 |
+ |
|
103 |
|
for (unsigned index = 1; index < args.size(); index++) |
104 |
|
{ |
105 |
|
if (args[index] == "-help") |
114 |
|
} |
115 |
|
else if (args[index] == "-disc") |
116 |
|
{ |
117 |
< |
// |
117 |
> |
mode = disc; |
118 |
|
} |
119 |
|
else if (args[index] == "-scan") |
120 |
|
{ |
121 |
< |
// |
121 |
> |
mode = scan; |
122 |
|
} |
123 |
|
else if (args[index] == "-D") |
124 |
|
{ |
126 |
|
{ |
127 |
|
debug = true; |
128 |
|
|
129 |
< |
munge(); |
129 |
> |
cerr.setf(ios_base::boolalpha); |
130 |
> |
} |
131 |
> |
} |
132 |
> |
else |
133 |
> |
{ |
134 |
> |
string message = "Unknown argument: " + args[index]; |
135 |
> |
|
136 |
> |
MessageBox(NULL, message.c_str(), programName.c_str(), |
137 |
> |
MB_ICONWARNING); |
138 |
> |
} |
139 |
> |
} |
140 |
> |
|
141 |
> |
if (debug) |
142 |
> |
{ |
143 |
> |
munge(); |
144 |
> |
cerr << "mode = "; |
145 |
> |
|
146 |
> |
switch (mode) |
147 |
> |
{ |
148 |
> |
case none: |
149 |
> |
cerr << "none"; |
150 |
> |
break; |
151 |
> |
case disc: |
152 |
> |
cerr << "disc"; |
153 |
> |
break; |
154 |
> |
case scan: |
155 |
> |
cerr << "scan"; |
156 |
> |
break; |
157 |
> |
default: |
158 |
> |
cerr << mode; |
159 |
> |
break; |
160 |
> |
} |
161 |
> |
|
162 |
> |
cerr << "\n"; |
163 |
> |
} |
164 |
> |
|
165 |
> |
License license; |
166 |
> |
|
167 |
> |
license.check(); |
168 |
> |
|
169 |
> |
if (mode == none) |
170 |
> |
{ |
171 |
> |
Chooser chooser; |
172 |
> |
|
173 |
> |
mode = chooser.choose(); |
174 |
> |
|
175 |
> |
if (debug) |
176 |
> |
{ |
177 |
> |
cerr << "mode = "; |
178 |
> |
|
179 |
> |
switch (mode) |
180 |
> |
{ |
181 |
> |
case none: |
182 |
> |
cerr << "none"; |
183 |
> |
break; |
184 |
> |
case disc: |
185 |
> |
cerr << "disc"; |
186 |
> |
break; |
187 |
> |
case scan: |
188 |
> |
cerr << "scan"; |
189 |
> |
break; |
190 |
> |
default: |
191 |
> |
cerr << mode; |
192 |
> |
break; |
193 |
|
} |
194 |
+ |
|
195 |
+ |
cerr << "\n"; |
196 |
|
} |
197 |
|
} |
198 |
|
|
199 |
+ |
if (mode == disc) |
200 |
+ |
{ |
201 |
+ |
DiscBrowse browser; |
202 |
+ |
|
203 |
+ |
browser.run(); |
204 |
+ |
} |
205 |
+ |
else if (mode == scan) |
206 |
+ |
{ |
207 |
+ |
ScanUtility utility; |
208 |
+ |
|
209 |
+ |
utility.run(); |
210 |
+ |
} |
211 |
+ |
|
212 |
+ |
CoUninitialize(); |
213 |
+ |
|
214 |
+ |
if (debug) |
215 |
+ |
{ |
216 |
+ |
cout << "Press enter key to exit . . ."; |
217 |
+ |
cin.get(); |
218 |
+ |
} |
219 |
+ |
|
220 |
|
return 0; |
221 |
|
} |
222 |
|
|
223 |
< |
void usage(void) |
223 |
> |
INT_PTR CALLBACK usage(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
224 |
|
{ |
225 |
< |
// |
225 |
> |
switch (msg) |
226 |
> |
{ |
227 |
> |
case WM_INITDIALOG: |
228 |
> |
center(dialog); |
229 |
> |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
230 |
> |
SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); |
231 |
> |
|
232 |
> |
{ |
233 |
> |
ostringstream usage; |
234 |
> |
|
235 |
> |
usage << "Usage: VTBFileUtil [-help | -version | -disc | -scan]\r" |
236 |
> |
<< "\n" |
237 |
> |
<< "\r\nOptions:\r\n" |
238 |
> |
<< " -help\t\tDisplay this information\r\n" |
239 |
> |
<< " -version\t\tDisplay version information\r\n" |
240 |
> |
<< " -disc\t\tStart in Disc Browse mode\r\n" |
241 |
> |
<< " -scan\t\tStart in Scan Utility mode\r\n"; |
242 |
> |
|
243 |
> |
SetDlgItemText(dialog, IDC_USAGE_TEXT, usage.str().c_str()); |
244 |
> |
} |
245 |
> |
break; |
246 |
> |
case WM_COMMAND: |
247 |
> |
switch (LOWORD(w)) |
248 |
> |
{ |
249 |
> |
case IDOK: |
250 |
> |
case IDCANCEL: |
251 |
> |
EndDialog(dialog, w); |
252 |
> |
return TRUE; |
253 |
> |
default: |
254 |
> |
break; |
255 |
> |
} |
256 |
> |
break; |
257 |
> |
} |
258 |
> |
|
259 |
> |
return FALSE; |
260 |
|
} |
261 |
|
|
262 |
< |
void version(void) |
262 |
> |
INT_PTR CALLBACK version(HWND dialog, UINT msg, WPARAM w, LPARAM l) |
263 |
|
{ |
264 |
< |
// |
264 |
> |
switch (msg) |
265 |
> |
{ |
266 |
> |
case WM_INITDIALOG: |
267 |
> |
center(dialog); |
268 |
> |
SendMessage(dialog, WM_SETICON, ICON_BIG, LPARAM(gui.icon)); |
269 |
> |
SendMessage(dialog, WM_SETTEXT, 0, LPARAM(programName.c_str())); |
270 |
> |
|
271 |
> |
{ |
272 |
> |
ostringstream version; |
273 |
> |
|
274 |
> |
version << programName << " (" << programVersion << ")\r\n\r\n" |
275 |
> |
<< "Copyright © 2003, Douglas Thrift.\n"; |
276 |
> |
|
277 |
> |
SetDlgItemText(dialog, IDC_VERSION_TEXT, version.str().c_str()); |
278 |
> |
} |
279 |
> |
break; |
280 |
> |
case WM_COMMAND: |
281 |
> |
switch (LOWORD(w)) |
282 |
> |
{ |
283 |
> |
case IDOK: |
284 |
> |
case IDCANCEL: |
285 |
> |
EndDialog(dialog, w); |
286 |
> |
return TRUE; |
287 |
> |
default: |
288 |
> |
break; |
289 |
> |
} |
290 |
> |
break; |
291 |
> |
} |
292 |
> |
|
293 |
> |
return FALSE; |
294 |
|
} |