1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
|
#include <windowsx.h>
#include <Input.h>
#include <Output.h>
#include <Buffer.h>
#include <BLua.h>
#include <LuaHandle.h>
#include <Main.h>
#include <ConfigFile.h>
#include "cdabstract.h"
#include "cdutils.h"
#include "isobuilder.h"
#include "luacd.h"
#include "luapsx.h"
#include "luapatch-res.h"
#include "luapatch-languages.h"
static int myprint(lua_State * _L) {
Lua * L = Lua::find(_L);
String t = L->tostring();
char * tc = t.strdup();
Base::printm(M_STATUS, "%s\n", tc);
free(tc);
return 0;
}
class Luabasecdtool : public LuaObject {
public:
static void pushstatics(Lua *) throw (GeneralException);
};
typedef void basecdtool;
enum basecdtool_t {
BASECDTOOL_LOAD = 0,
};
struct lua_functypes_t basecdtool_functions[] = {
{ BASECDTOOL_LOAD, "load", 0, 1, { LUA_STRING | LUA_OBJECT } },
{ -1, 0, 0, 0, 0 }
};
class sLua_basecdtool : public Base {
public:
DECLARE_FUNCTION(basecdtool, BASECDTOOL_LOAD);
private:
static int basecdtool_proceed_statics(Lua * L, int n, int caller);
};
void Luabasecdtool::pushstatics(Lua * L) throw (GeneralException ) {
CHECK_FUNCTIONS(basecdtool);
PUSH_FUNCTION(basecdtool, BASECDTOOL_LOAD);
}
int sLua_basecdtool::basecdtool_proceed_statics(Lua * L, int n, int caller) {
int r = 0;
switch (caller) {
case BASECDTOOL_LOAD:
if (!n) {
L->load(&Input("cd-tool.lua"));
} else {
if (L->isstring(1)) {
L->load(&Input(L->tostring(1)));
} else {
Handle * t = (Handle *) LuaObject::getme(L, 1);
L->load(t);
}
}
}
return r;
}
bool Verify(HWND);
bool quit = false;
bool canprobe;
bool fromdrive = false;
String source, dest, patch;
int langid;
void translate(int ownerid, HWND hW) {
struct trad_t * t;
struct texts_t * txt;
for (t = trads; t->trad && t->langid != langid; t++);
if (!t->trad)
return;
for (txt = t->trad; txt->str; txt++) {
if (txt->owner == ownerid) {
if (txt->id == -1) {
SetWindowText(hW, txt->str);
} else {
SetDlgItemText(hW, txt->id, txt->str);
}
}
}
}
const char * GetString(int id) {
struct trad_t * t;
struct texts_t * txt;
int oldlangid = langid;
const char * r;
for (t = trads; t->trad && t->langid != langid; t++);
if (!t->trad) {
oldlangid = langid;
langid = LANG_NEUTRAL;
r = GetString(id);
langid = oldlangid;
return r;
}
for (txt = t->trad; txt->str; txt++) {
if ((txt->owner == 0) && (txt->id == id))
return txt->str;
}
if (langid == LANG_NEUTRAL)
return NULL;
oldlangid = langid;
langid = LANG_NEUTRAL;
r = GetString(id);
langid = oldlangid;
return r;
}
void ChooseFile(HWND hW, int iFType) {
OPENFILENAME ofn;
char szB[260];
BOOL b;
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hW;
ofn.hInstance = NULL;
switch (iFType) {
case DEST_SELECT:
ofn.lpstrFilter = GetString(ISODEST);
GetDlgItemText(hW, IDC_DEST, szB, 259);
break;
case SOURCE_SELECT:
ofn.lpstrFilter = GetString(ISOSOURCE);
GetDlgItemText(hW, IDC_SOURCE, szB, 259);
break;
case PATCH_SELECT:
ofn.lpstrFilter = GetString(PATCH);
GetDlgItemText(hW, IDC_PATCH, szB, 259);
break;
}
ofn.lpstrCustomFilter=NULL;
ofn.nMaxCustFilter=0;
ofn.nFilterIndex=0;
ofn.lpstrFile = szB;
ofn.nMaxFile = 259;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.lpstrTitle = NULL;
ofn.nFileOffset=0;
ofn.nFileExtension=0;
ofn.lpstrDefExt=0;
ofn.lCustData=0;
ofn.lpfnHook=NULL;
ofn.lpTemplateName=NULL;
if (iFType == DEST_SELECT) {
ofn.Flags = OFN_CREATEPROMPT |
OFN_NOCHANGEDIR |
OFN_HIDEREADONLY |
OFN_OVERWRITEPROMPT;
b = GetSaveFileName(&ofn);
} else {
ofn.Flags = OFN_FILEMUSTEXIST |
OFN_NOCHANGEDIR |
OFN_HIDEREADONLY;
b = GetOpenFileName(&ofn);
}
if (b) {
switch (iFType) {
case DEST_SELECT:
SetDlgItemText(hW, IDC_DEST, szB);
break;
case SOURCE_SELECT:
SetDlgItemText(hW, IDC_SOURCE, szB);
break;
case PATCH_SELECT:
SetDlgItemText(hW, IDC_PATCH, szB);
break;
}
}
}
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
RECT r;
POINT p;
int bwidth, bheight, wsize;
HWND button;
switch (uMsg) {
case WM_INITDIALOG:
translate(IDD_ABOUT, hW);
button = GetDlgItem(hW, IDOK);
GetWindowRect(button, &r);
p.x = r.left;
p.y = r.top;
ScreenToClient(hW, &p);
bwidth = r.right - r.left;
bheight = r.bottom - r.top;
GetWindowRect(hW, &r);
wsize = r.right - r.left;
MoveWindow(button, wsize / 2 - bwidth / 2, p.y, bwidth, bheight, TRUE);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK: EndDialog(hW, 0); return TRUE;
}
break;
}
return FALSE;
}
BOOL CALLBACK FileSelectDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
RECT r;
POINT p;
int bwidth, bheight, wsize;
HWND button, control;
switch (uMsg) {
case WM_INITDIALOG:
translate(IDD_FILESELECT, hW);
control = GetDlgItem(hW, IDC_SOURCETYPE);
ComboBox_ResetContent(control);
ComboBox_AddString(control, GetString(ISOFILE));
ComboBox_SetCurSel(control, 0);
if (canprobe) {
ComboBox_AddString(control, GetString(CDDRIVE));
ComboBox_SetCurSel(control, 1);
control = GetDlgItem(hW, IDC_DRIVE);
std::vector<String> p;
p = cdabstract::probe();
for (std::vector<String>::iterator i = p.begin(); i != p.end(); i++) {
ComboBox_AddString(control, i->to_charp());
}
ComboBox_SetCurSel(control, 0);
fromdrive = true;
ShowWindow(GetDlgItem(hW, IDC_DRIVE), SW_SHOW);
ShowWindow(GetDlgItem(hW, IDC_SOURCE), SW_HIDE);
ShowWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), SW_HIDE);
} else {
EnableWindow(control, false);
}
button = GetDlgItem(hW, IDOK);
GetWindowRect(button, &r);
p.x = r.left;
p.y = r.top;
ScreenToClient(hW, &p);
bwidth = r.right - r.left;
bheight = r.bottom - r.top;
GetWindowRect(hW, &r);
wsize = r.right - r.left;
MoveWindow(button, wsize / 2 - bwidth / 2, p.y, bwidth, bheight, TRUE);
break;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
if (Verify(hW))
EndDialog(hW, 0);
return TRUE;
case IDCANCEL:
EndDialog(hW, 0);
quit = true;
return TRUE;
case IDC_ABOUT:
DialogBox(0, MAKEINTRESOURCE(IDD_ABOUT),
GetActiveWindow(), AboutDlgProc);
return TRUE;
case IDC_SOURCETYPE:
if (HIWORD(wParam) != CBN_SELCHANGE)
return FALSE;
if (ComboBox_GetCurSel(GetDlgItem(hW, IDC_SOURCETYPE))) {
fromdrive = true;
ShowWindow(GetDlgItem(hW, IDC_DRIVE), SW_SHOW);
ShowWindow(GetDlgItem(hW, IDC_SOURCE), SW_HIDE);
ShowWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), SW_HIDE);
} else {
fromdrive = false;
ShowWindow(GetDlgItem(hW, IDC_DRIVE), SW_HIDE);
ShowWindow(GetDlgItem(hW, IDC_SOURCE), SW_SHOW);
ShowWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), SW_SHOW);
}
break;
case IDC_SOURCE_SELECT:
ChooseFile(hW, SOURCE_SELECT);
break;
case IDC_PATCH_SELECT:
ChooseFile(hW, PATCH_SELECT);
break;
case IDC_DEST_SELECT:
ChooseFile(hW, DEST_SELECT);
break;
}
break;
}
return FALSE;
}
bool Verify(HWND hW) {
char szB[260];
GetDlgItemText(hW, IDC_DEST, szB, 259);
if (!szB[0]) {
MessageBox(hW, GetString(NO_DESTINATION), GetString(MSGERROR), MB_OK | MB_ICONERROR);
return false;
}
dest = szB;
GetDlgItemText(hW, IDC_PATCH, szB, 259);
if (!szB[0]) {
MessageBox(hW, GetString(NO_PATCH), GetString(MSGERROR), MB_OK | MB_ICONERROR);
return false;
}
patch = szB;
GetDlgItemText(hW, IDC_SOURCE, szB, 259);
if (!szB[0] && !fromdrive) {
MessageBox(hW, GetString(NO_SOURCE), GetString(MSGERROR), MB_OK | MB_ICONERROR);
return false;
}
if (fromdrive) {
GetDlgItemText(hW, IDC_DRIVE, szB, 259);
source = String("cd:") + szB;
} else {
source = szB;
}
return true;
}
CODE_BEGINS
virtual int startup(void) throw (GeneralException) {
verbosity = M_INFO;
printm(M_BARE, "LuaPatch (C) 2003-2005 Nicolas \"Pixel\" Noble - front-end starting.\n");
int lang;
lang = GetUserDefaultLangID();
langid = PRIMARYLANGID(lang);
canprobe = cdabstract::canprobe();
DialogBox(0, MAKEINTRESOURCE(IDD_FILESELECT),
GetActiveWindow(), FileSelectDlgProc);
if (quit)
exit(0);
Input * fpatch = new Input(patch);
fpatch->seek(0);
new Archive(fpatch);
Output * o;
cdutils * cdutil;
Handle * iso_r;
cdutil = new cdutils(iso_r = cdabstract::open_cd(source));
isobuilder * b = new isobuilder(o = new Output(dest));
Lua * L = new Lua();
L->open_base();
L->open_math();
L->open_string();
L->open_table();
L->open_dir();
LuaInput::pushconstruct(L);
LuaOutput::pushconstruct(L);
LuaBuffer::pushconstruct(L);
CD_PUSHSTATICS(L);
Luapsx::pushstatics(L);
L->push("print");
L->push(myprint);
L->settable(LUA_GLOBALSINDEX);
Luabasecdtool::pushstatics(L);
Luacdutils lcdutil(cdutil);
L->push("cdutil");
lcdutil.push(L);
L->setvar();
Luaisobuilder liso(b);
L->push("iso");
liso.push(L);
L->setvar();
Handle * config_file = 0;
try {
config_file = new Input("patch.ini");
}
catch (IOGeneral e) {
}
if (!config_file) {
printm(M_WARNING, GetString(PARASITE_EVE));
try {
L->load(&Input("main"));
}
catch (IOGeneral e) {
printm(M_ERROR, GetString(VERBOSE_CFG_ERROR));
throw GeneralException(GetString(CFG_ERROR));
}
} else {
ConfigFile cfg(config_file);
Buffer cmd;
L->load(&Input(cfg["patch"]["filename"]));
cmd << cfg["patch"]["command"];
L->load(&cmd);
}
delete config_file;
delete b;
delete o;
delete cdutil;
delete iso_r;
MessageBox(0, GetString(END_MSG), GetString(END_TITLE), MB_ICONINFORMATION | MB_OK);
return 0;
}
CODE_ENDS
#if 0
String message;
char bleh[256];
switch (uMsg) {
case 0x0000: message="WM_NULL"; break;
case 0x0001: message="WM_CREATE"; break;
case 0x0002: message="WM_DESTROY"; break;
case 0x0003: message="WM_MOVE"; break;
case 0x0005: message="WM_SIZE"; break;
case 0x0006: message="WM_ACTIVATE"; break;
case 0x0007: message="WM_SETFOCUS"; break;
case 0x0008: message="WM_KILLFOCUS"; break;
case 0x000A: message="WM_ENABLE"; break;
case 0x000B: message="WM_SETREDRAW"; break;
case 0x000C: message="WM_SETTEXT"; break;
case 0x000D: message="WM_GETTEXT"; break;
case 0x000E: message="WM_GETTEXTLENGTH"; break;
case 0x000F: message="WM_PAINT"; break;
case 0x0010: message="WM_CLOSE"; break;
case 0x0011: message="WM_QUERYENDSESSION"; break;
case 0x0013: message="WM_QUERYOPEN"; break;
case 0x0016: message="WM_ENDSESSION"; break;
case 0x0012: message="WM_QUIT"; break;
case 0x0014: message="WM_ERASEBKGND"; break;
case 0x0015: message="WM_SYSCOLORCHANGE"; break;
case 0x0018: message="WM_SHOWWINDOW"; break;
case 0x001A: message="WM_WININICHANGE"; break;
case 0x001B: message="WM_DEVMODECHANGE"; break;
case 0x001C: message="WM_ACTIVATEAPP"; break;
case 0x001D: message="WM_FONTCHANGE"; break;
case 0x001E: message="WM_TIMECHANGE"; break;
case 0x001F: message="WM_CANCELMODE"; break;
case 0x0020: message="WM_SETCURSOR"; break;
case 0x0021: message="WM_MOUSEACTIVATE"; break;
case 0x0022: message="WM_CHILDACTIVATE"; break;
case 0x0023: message="WM_QUEUESYNC"; break;
case 0x0024: message="WM_GETMINMAXINFO"; break;
case 0x0026: message="WM_PAINTICON"; break;
case 0x0027: message="WM_ICONERASEBKGND"; break;
case 0x0028: message="WM_NEXTDLGCTL"; break;
case 0x002A: message="WM_SPOOLERSTATUS"; break;
case 0x002B: message="WM_DRAWITEM"; break;
case 0x002C: message="WM_MEASUREITEM"; break;
case 0x002D: message="WM_DELETEITEM"; break;
case 0x002E: message="WM_VKEYTOITEM"; break;
case 0x002F: message="WM_CHARTOITEM"; break;
case 0x0030: message="WM_SETFONT"; break;
case 0x0031: message="WM_GETFONT"; break;
case 0x0032: message="WM_SETHOTKEY"; break;
case 0x0033: message="WM_GETHOTKEY"; break;
case 0x0037: message="WM_QUERYDRAGICON"; break;
case 0x0039: message="WM_COMPAREITEM"; break;
case 0x003D: message="WM_GETOBJECT"; break;
case 0x0041: message="WM_COMPACTING"; break;
case 0x0044: message="WM_COMMNOTIFY"; break;
case 0x0046: message="WM_WINDOWPOSCHANGING"; break;
case 0x0047: message="WM_WINDOWPOSCHANGED"; break;
case 0x0048: message="WM_POWER"; break;
case 0x004A: message="WM_COPYDATA"; break;
case 0x004B: message="WM_CANCELJOURNAL"; break;
case 0x004E: message="WM_NOTIFY"; break;
case 0x0050: message="WM_INPUTLANGCHANGEREQUEST"; break;
case 0x0051: message="WM_INPUTLANGCHANGE"; break;
case 0x0052: message="WM_TCARD"; break;
case 0x0053: message="WM_HELP"; break;
case 0x0054: message="WM_USERCHANGED"; break;
case 0x0055: message="WM_NOTIFYFORMAT"; break;
case 0x007B: message="WM_CONTEXTMENU"; break;
case 0x007C: message="WM_STYLECHANGING"; break;
case 0x007D: message="WM_STYLECHANGED"; break;
case 0x007E: message="WM_DISPLAYCHANGE"; break;
case 0x007F: message="WM_GETICON"; break;
case 0x0080: message="WM_SETICON"; break;
case 0x0081: message="WM_NCCREATE"; break;
case 0x0082: message="WM_NCDESTROY"; break;
case 0x0083: message="WM_NCCALCSIZE"; break;
case 0x0084: message="WM_NCHITTEST"; break;
case 0x0085: message="WM_NCPAINT"; break;
case 0x0086: message="WM_NCACTIVATE"; break;
case 0x0087: message="WM_GETDLGCODE"; break;
case 0x0088: message="WM_SYNCPAINT"; break;
case 0x00A0: message="WM_NCMOUSEMOVE"; break;
case 0x00A1: message="WM_NCLBUTTONDOWN"; break;
case 0x00A2: message="WM_NCLBUTTONUP"; break;
case 0x00A3: message="WM_NCLBUTTONDBLCLK"; break;
case 0x00A4: message="WM_NCRBUTTONDOWN"; break;
case 0x00A5: message="WM_NCRBUTTONUP"; break;
case 0x00A6: message="WM_NCRBUTTONDBLCLK"; break;
case 0x00A7: message="WM_NCMBUTTONDOWN"; break;
case 0x00A8: message="WM_NCMBUTTONUP"; break;
case 0x00A9: message="WM_NCMBUTTONDBLCLK"; break;
case 0x00AB: message="WM_NCXBUTTONDOWN"; break;
case 0x00AC: message="WM_NCXBUTTONUP"; break;
case 0x00AD: message="WM_NCXBUTTONDBLCLK"; break;
case 0x00FF: message="WM_INPUT"; break;
case 0x0100: message="WM_KEYFIRST"; break;
case 0x0101: message="WM_KEYUP"; break;
case 0x0102: message="WM_CHAR"; break;
case 0x0103: message="WM_DEADCHAR"; break;
case 0x0104: message="WM_SYSKEYDOWN"; break;
case 0x0105: message="WM_SYSKEYUP"; break;
case 0x0106: message="WM_SYSCHAR"; break;
case 0x0107: message="WM_SYSDEADCHAR"; break;
case 0x0109: message="WM_UNICHAR"; break;
case 0x0108: message="WM_KEYLAST"; break;
case 0x010D: message="WM_IME_STARTCOMPOSITION"; break;
case 0x010E: message="WM_IME_ENDCOMPOSITION"; break;
case 0x010F: message="WM_IME_COMPOSITION"; break;
case 0x0110: message="WM_INITDIALOG"; break;
case 0x0111: message="WM_COMMAND"; break;
case 0x0112: message="WM_SYSCOMMAND"; break;
case 0x0113: message="WM_TIMER"; break;
case 0x0114: message="WM_HSCROLL"; break;
case 0x0115: message="WM_VSCROLL"; break;
case 0x0116: message="WM_INITMENU"; break;
case 0x0117: message="WM_INITMENUPOPUP"; break;
case 0x011F: message="WM_MENUSELECT"; break;
case 0x0120: message="WM_MENUCHAR"; break;
case 0x0121: message="WM_ENTERIDLE"; break;
case 0x0122: message="WM_MENURBUTTONUP"; break;
case 0x0123: message="WM_MENUDRAG"; break;
case 0x0124: message="WM_MENUGETOBJECT"; break;
case 0x0125: message="WM_UNINITMENUPOPUP"; break;
case 0x0126: message="WM_MENUCOMMAND"; break;
case 0x0127: message="WM_CHANGEUISTATE"; break;
case 0x0128: message="WM_UPDATEUISTATE"; break;
case 0x0129: message="WM_QUERYUISTATE"; break;
default: message="Unknown"; break;
}
sprintf(bleh, " (0x%04x)\n", uMsg);
message = "AboutDlgProc: uMsg = " + message + bleh;
Base::printm(M_STATUS, message);
#endif
|