diff options
Diffstat (limited to 'luapatch.cpp')
-rw-r--r-- | luapatch.cpp | 1198 |
1 files changed, 599 insertions, 599 deletions
diff --git a/luapatch.cpp b/luapatch.cpp index 8e5c8ee..7665b9e 100644 --- a/luapatch.cpp +++ b/luapatch.cpp @@ -1,599 +1,599 @@ -#include <windowsx.h>
-
-#include <Input.h>
-#include <Output.h>
-#include <BLua.h>
-#include <LuaHandle.h>
-#include <Main.h>
-
-#include "cdabstract.h"
-#include "cdutils.h"
-#include "isobuilder.h"
-#include "luacd.h"
-#include "luapsx.h"
-
-#include "luapatch-res.h"
-
-static int myprint(lua_State * _L) {
- Lua * L = Lua::find(_L);
- String t = L->tostring();
-
- Base::printm(M_BARE, t + "\n");
-
- return 0;
-}
-
-bool Verify(HWND);
-
-enum strings_e {
- ISOFILE,
- CDDRIVE,
- ISOSOURCE,
- ISODEST,
- PATCH,
- NO_DESTINATION,
- NO_SOURCE,
- NO_PATCH,
- MSGERROR,
-};
-
-bool quit = false;
-bool canprobe;
-bool fromdrive = false;
-
-String source, dest, patch;
-
-struct texts_t {
- int id;
- int owner;
- char * str;
-};
-
-struct texts_t t_english[] = {
- {ISOFILE, 0, "Iso file"},
- {CDDRIVE, 0, "CD drive"},
- {ISODEST, 0, "2352-raw image (*.bin)\0*.BIN\0\0\0"},
- {ISOSOURCE, 0, "2352-raw image (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"},
- {PATCH, 0, "PAQ Archive (*.paq)\0*.PAQ\0\0\0"},
- {MSGERROR, 0, "Error"},
- {NO_DESTINATION, 0, "No destination file."},
- {NO_SOURCE, 0, "No source file."},
- {NO_PATCH, 0, "No patch file."},
- {-1, 0}
-};
-
-struct texts_t t_french[] = {
- {IDC_ABOUTTEXT, IDD_ABOUT,
-"LuaPatch version 0.3.0\n"
-"Version artisanale spéciale MFC \"Eve\"\n\n"
-"Un système de patch de CD\n\n"
-"Copyrignt © 2003-2004 Nicolas \"Pixel\" Noble / NOBIS\n\n"
-"http://www.nobis-crew.org/luapatch/\n"
-"http://www.nobis-crew.org/"},
- {IDCANCEL, IDD_FILESELECT, "Quitter"},
- {IDC_ABOUT, IDD_FILESELECT, "A propos"},
- {IDC_ST_SOURCETYPE, IDD_FILESELECT, "Type de source:"},
- {IDC_ST_DEST, IDD_FILESELECT, "Fichier de destination:"},
- {IDC_ST_PATCH, IDD_FILESELECT, "Fichier de patch:"},
- {ISOFILE, 0, "Fichier ISO"},
- {CDDRIVE, 0, "Lecteur CD"},
- {ISODEST, 0, "Image ISO 2352-raw (*.bin)\0*.BIN\0\0\0"},
- {ISOSOURCE, 0, "Image ISO 2352-raw (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"},
- {PATCH, 0, "Archive PAQ (*.paq)\0*.PAQ\0\0\0"},
- {MSGERROR, 0, "Erreur"},
- {NO_DESTINATION, 0, "Pas de fichier de destination."},
- {NO_SOURCE, 0, "Pas de fichier source."},
- {NO_PATCH, 0, "Pas de fichier patch."},
- {-1, 0}
-};
-
-struct texts_t t_german[] = {
- {IDC_ABOUTTEXT, IDD_ABOUT,
-"LuaPatch version 0.3.0\n"
-"Adaptierte MFC Version \"Eve\"\n\n"
-"CD Patch System\n\n"
-"Copyright © 2003-2004 Nicolas \"Pixel\" Noble / NOBIS\n\n"
-"http://www.nobis-crew.org/luapatch/\n"
-"http://www.nobis-crew.org/"},
- {IDCANCEL, IDD_FILESELECT, "Beenden"},
- {IDC_ABOUT, IDD_FILESELECT, "Info"},
- {IDC_ST_SOURCETYPE, IDD_FILESELECT, "Quelletyp:"},
- {IDC_ST_SOURCE, IDD_FILESELECT, "Quelle:"},
- {IDC_ST_DEST, IDD_FILESELECT, "Ziel Datei:"},
- {IDC_ST_PATCH, IDD_FILESELECT, "Patch Datei:"},
- {ISOFILE, 0, "Iso Image"},
- {CDDRIVE, 0, "CD Laufwerk"},
- {ISODEST, 0, "ISO Image 2352-raw (*.bin)\0*.BIN\0\0\0"},
- {ISOSOURCE, 0, "ISO Image 2352-raw (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"},
- {PATCH, 0, "Archiv PAQ (*.paq)\0*.PAQ\0\0\0"},
- {MSGERROR, 0, "Fehler"},
- {NO_DESTINATION, 0, "Keine Zeildatei."},
- {NO_SOURCE, 0, "Keine Quelldatei."},
- {NO_PATCH, 0, "Keine Patchdatei."},
- {-1, 0}
-};
-
-struct trad_t {
- int langid;
- struct texts_t * trad;
-};
-
-struct trad_t trads[] = {
- {LANG_NEUTRAL, t_english},
- {LANG_FRENCH, t_french},
- {LANG_GERMAN, t_german},
- {-1, 0}
-};
-
-int langid;
-
-enum {
- DEST_SELECT,
- SOURCE_SELECT,
- PATCH_SELECT,
-};
-
-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)
- 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) 2004 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();
- 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);
-
- Luacdutils lcdutil(cdutil);
- L->push("cdutil");
- lcdutil.push(L);
- L->setvar();
- Luaisobuilder liso(b);
- L->push("iso");
- liso.push(L);
- L->setvar();
- L->load(&Input("main"));
-
- delete b;
- delete o;
- delete cdutil;
- delete iso_r;
-
- 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
+#include <windowsx.h> + +#include <Input.h> +#include <Output.h> +#include <BLua.h> +#include <LuaHandle.h> +#include <Main.h> + +#include "cdabstract.h" +#include "cdutils.h" +#include "isobuilder.h" +#include "luacd.h" +#include "luapsx.h" + +#include "luapatch-res.h" + +static int myprint(lua_State * _L) { + Lua * L = Lua::find(_L); + String t = L->tostring(); + + Base::printm(M_BARE, t + "\n"); + + return 0; +} + +bool Verify(HWND); + +enum strings_e { + ISOFILE, + CDDRIVE, + ISOSOURCE, + ISODEST, + PATCH, + NO_DESTINATION, + NO_SOURCE, + NO_PATCH, + MSGERROR, +}; + +bool quit = false; +bool canprobe; +bool fromdrive = false; + +String source, dest, patch; + +struct texts_t { + int id; + int owner; + char * str; +}; + +struct texts_t t_english[] = { + {ISOFILE, 0, "Iso file"}, + {CDDRIVE, 0, "CD drive"}, + {ISODEST, 0, "2352-raw image (*.bin)\0*.BIN\0\0\0"}, + {ISOSOURCE, 0, "2352-raw image (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"}, + {PATCH, 0, "PAQ Archive (*.paq)\0*.PAQ\0\0\0"}, + {MSGERROR, 0, "Error"}, + {NO_DESTINATION, 0, "No destination file."}, + {NO_SOURCE, 0, "No source file."}, + {NO_PATCH, 0, "No patch file."}, + {-1, 0} +}; + +struct texts_t t_french[] = { + {IDC_ABOUTTEXT, IDD_ABOUT, +"LuaPatch version 0.3.0\n" +"Version artisanale spéciale MFC \"Eve\"\n\n" +"Un système de patch de CD\n\n" +"Copyrignt © 2003-2004 Nicolas \"Pixel\" Noble / NOBIS\n\n" +"http://www.nobis-crew.org/luapatch/\n" +"http://www.nobis-crew.org/"}, + {IDCANCEL, IDD_FILESELECT, "Quitter"}, + {IDC_ABOUT, IDD_FILESELECT, "A propos"}, + {IDC_ST_SOURCETYPE, IDD_FILESELECT, "Type de source:"}, + {IDC_ST_DEST, IDD_FILESELECT, "Fichier de destination:"}, + {IDC_ST_PATCH, IDD_FILESELECT, "Fichier de patch:"}, + {ISOFILE, 0, "Fichier ISO"}, + {CDDRIVE, 0, "Lecteur CD"}, + {ISODEST, 0, "Image ISO 2352-raw (*.bin)\0*.BIN\0\0\0"}, + {ISOSOURCE, 0, "Image ISO 2352-raw (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"}, + {PATCH, 0, "Archive PAQ (*.paq)\0*.PAQ\0\0\0"}, + {MSGERROR, 0, "Erreur"}, + {NO_DESTINATION, 0, "Pas de fichier de destination."}, + {NO_SOURCE, 0, "Pas de fichier source."}, + {NO_PATCH, 0, "Pas de fichier patch."}, + {-1, 0} +}; + +struct texts_t t_german[] = { + {IDC_ABOUTTEXT, IDD_ABOUT, +"LuaPatch version 0.3.0\n" +"Adaptierte MFC Version \"Eve\"\n\n" +"CD Patch System\n\n" +"Copyright © 2003-2004 Nicolas \"Pixel\" Noble / NOBIS\n\n" +"http://www.nobis-crew.org/luapatch/\n" +"http://www.nobis-crew.org/"}, + {IDCANCEL, IDD_FILESELECT, "Beenden"}, + {IDC_ABOUT, IDD_FILESELECT, "Info"}, + {IDC_ST_SOURCETYPE, IDD_FILESELECT, "Quelletyp:"}, + {IDC_ST_SOURCE, IDD_FILESELECT, "Quelle:"}, + {IDC_ST_DEST, IDD_FILESELECT, "Ziel Datei:"}, + {IDC_ST_PATCH, IDD_FILESELECT, "Patch Datei:"}, + {ISOFILE, 0, "Iso Image"}, + {CDDRIVE, 0, "CD Laufwerk"}, + {ISODEST, 0, "ISO Image 2352-raw (*.bin)\0*.BIN\0\0\0"}, + {ISOSOURCE, 0, "ISO Image 2352-raw (*.bin, *.iso, *.img)\0*.BIN;*.ISO;*.IMG\0\0\0"}, + {PATCH, 0, "Archiv PAQ (*.paq)\0*.PAQ\0\0\0"}, + {MSGERROR, 0, "Fehler"}, + {NO_DESTINATION, 0, "Keine Zeildatei."}, + {NO_SOURCE, 0, "Keine Quelldatei."}, + {NO_PATCH, 0, "Keine Patchdatei."}, + {-1, 0} +}; + +struct trad_t { + int langid; + struct texts_t * trad; +}; + +struct trad_t trads[] = { + {LANG_NEUTRAL, t_english}, + {LANG_FRENCH, t_french}, + {LANG_GERMAN, t_german}, + {-1, 0} +}; + +int langid; + +enum { + DEST_SELECT, + SOURCE_SELECT, + PATCH_SELECT, +}; + +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) + 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) 2004 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(); + 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); + + Luacdutils lcdutil(cdutil); + L->push("cdutil"); + lcdutil.push(L); + L->setvar(); + Luaisobuilder liso(b); + L->push("iso"); + liso.push(L); + L->setvar(); + L->load(&Input("main")); + + delete b; + delete o; + delete cdutil; + delete iso_r; + + 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 |