diff options
-rw-r--r-- | MSVC/LuaPatch/LuaPatch.vcproj | 12 | ||||
-rw-r--r-- | luapatch-languages.h | 10 | ||||
-rw-r--r-- | luapatch-res.h | 8 | ||||
-rw-r--r-- | luapatch.cpp | 280 | ||||
-rw-r--r-- | luapatch.rc | 55 |
5 files changed, 304 insertions, 61 deletions
diff --git a/MSVC/LuaPatch/LuaPatch.vcproj b/MSVC/LuaPatch/LuaPatch.vcproj index 22fea58..047fc14 100644 --- a/MSVC/LuaPatch/LuaPatch.vcproj +++ b/MSVC/LuaPatch/LuaPatch.vcproj @@ -172,6 +172,10 @@ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
+ RelativePath="..\..\luapatch-languages.h"
+ >
+ </File>
+ <File
RelativePath="..\..\luapatch.cpp"
>
</File>
@@ -185,12 +189,20 @@ Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
+ <File
+ RelativePath="..\..\luapatch-res.h"
+ >
+ </File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
+ <File
+ RelativePath="..\..\cdrom.ico"
+ >
+ </File>
</Filter>
</Files>
<Globals>
diff --git a/luapatch-languages.h b/luapatch-languages.h index 1e85a09..99063f6 100644 --- a/luapatch-languages.h +++ b/luapatch-languages.h @@ -17,9 +17,10 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: luapatch-languages.h,v 1.3 2004-12-21 11:14:16 pixel Exp $ */ +/* $Id: luapatch-languages.h,v 1.4 2004-12-21 22:41:02 pixel Exp $ */ enum strings_e { + ISOFILEPATCH, ISOFILE, CDDRIVE, ISOSOURCE, @@ -29,6 +30,7 @@ enum strings_e { NO_SOURCE, NO_PATCH, MSGERROR, + LOAD_ERROR, PARASITE_EVE, VERBOSE_CFG_ERROR, CFG_ERROR, @@ -44,6 +46,7 @@ struct texts_t { struct texts_t t_english[] = { {-1, IDD_ABOUT, "About..."}, + {-1, IDD_OPTIONS, "Options"}, {IDC_ABOUTTEXT, IDD_ABOUT, "LuaPatch version 0.4.0\n" "Hand made special MFC version\n\n" @@ -52,6 +55,7 @@ struct texts_t t_english[] = { "http://www.nobis-crew.org/luapatch/\n" "http://www.nobis-crew.org/"}, {IDOK, IDD_ABOUT, "OK"}, + {IDOK, IDD_OPTIONS, "OK"}, {IDOK, IDD_FILESELECT, "OK"}, {IDCANCEL, IDD_FILESELECT, "Quit"}, {IDC_ABOUT, IDD_FILESELECT, "About"}, @@ -61,6 +65,7 @@ struct texts_t t_english[] = { {IDC_ST_DEST, IDD_FILESELECT, "Destination file:"}, {IDC_ST_PATCH, IDD_FILESELECT, "Patch file:"}, + {ISOFILEPATCH, 0, "Iso file to patch:"}, {ISOFILE, 0, "Iso file"}, {CDDRIVE, 0, "CD drive"}, {ISODEST, 0, "2352-raw image (*.bin)\0*.BIN\0\0\0"}, @@ -70,6 +75,7 @@ struct texts_t t_english[] = { {NO_DESTINATION, 0, "No destination file."}, {NO_SOURCE, 0, "No source file."}, {NO_PATCH, 0, "No patch file."}, + {LOAD_ERROR, 0, "Error loading patch file."}, {PARASITE_EVE, 0, "Error loading configuration file, switching to old Parasite Eve behavior.\n"}, {VERBOSE_CFG_ERROR, 0, "Something's wrong with that patch: no valid configuration file.\n"}, {CFG_ERROR, 0, "No valid configuration file found."}, @@ -94,6 +100,7 @@ struct texts_t t_french[] = { {IDC_ST_DEST, IDD_FILESELECT, "Fichier de destination:"}, {IDC_ST_PATCH, IDD_FILESELECT, "Fichier de patch:"}, + {ISOFILEPATCH, 0, "Fichier ISO à patcher:"}, {ISOFILE, 0, "Fichier ISO"}, {CDDRIVE, 0, "Lecteur CD"}, {ISODEST, 0, "Image ISO 2352-raw (*.bin)\0*.BIN\0\0\0"}, @@ -103,6 +110,7 @@ struct texts_t t_french[] = { {NO_DESTINATION, 0, "Pas de fichier de destination."}, {NO_SOURCE, 0, "Pas de fichier source."}, {NO_PATCH, 0, "Pas de fichier patch."}, + {LOAD_ERROR, 0, "Erreur au chargement du patch."}, {PARASITE_EVE, 0, "Erreur au chargement du fichier de configuration, compatibilité descendante avec Parasite Eve activée.\n" }, {VERBOSE_CFG_ERROR, 0, "Quelque chose ne va pas avec ce patch: pas de fichier de configuration valide.\n"}, {CFG_ERROR, 0, "Aucun fichier de configuration valide trouvé."}, diff --git a/luapatch-res.h b/luapatch-res.h index 936bbcf..f010ab3 100644 --- a/luapatch-res.h +++ b/luapatch-res.h @@ -6,6 +6,7 @@ #define IDD_ABOUT 102
#define ID_FILE_QUIT 104
#define IDI_ICON 105
+#define IDD_OPTIONS 107
#define IDC_ABOUTTEXT 1001
#define IDC_ABOUT 1003
#define IDC_ST_SOURCETYPE 1004
@@ -23,15 +24,16 @@ #define IDC_SOURCEFILE_SELECT 1017
#define IDC_SOURCE_SELECT 1017
#define IDC_ST_PATCH_TITLE 1018
-#define IDC_CUSTOM1 1019
+#define IDC_TITLE 1020
+#define IDC_ST_TITLE 1020
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 107
+#define _APS_NEXT_RESOURCE_VALUE 108
#define _APS_NEXT_COMMAND_VALUE 40001
-#define _APS_NEXT_CONTROL_VALUE 1020
+#define _APS_NEXT_CONTROL_VALUE 1022
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
diff --git a/luapatch.cpp b/luapatch.cpp index 1491856..add1d63 100644 --- a/luapatch.cpp +++ b/luapatch.cpp @@ -17,7 +17,27 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: luapatch.cpp,v 1.10 2004-12-21 11:14:16 pixel Exp $ */ +/* $Id: luapatch.cpp,v 1.11 2004-12-21 22:41:02 pixel Exp $ */ + +#define PARASITE_EVE_INI \ +"[patch]\n" \ +"title=Parasite Eve - fr - 0.9\n" \ +"options=0\n" \ +"type=rebuild\n" \ +"filename=main\n" \ +"command=\n" + +#define OPEN_PATCH_INI(warn) \ + try { \ + config_file = new Input("patch.ini"); \ + } \ + catch (IOGeneral e) { \ + if (warn) \ + printm(M_WARNING, GetString(PARASITE_EVE)); \ + config_file = new Buffer(true); \ + (*config_file) << PARASITE_EVE_INI; \ + } + #include <windowsx.h> @@ -39,18 +59,6 @@ #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); @@ -100,17 +108,41 @@ int sLua_basecdtool::basecdtool_proceed_statics(Lua * L, int n, int caller) { return r; } -bool Verify(HWND); - bool quit = false; bool canprobe; bool fromdrive = false; +bool rebuild = false; +bool patch_loaded = false; + +int current_option = 0; +String option_variable; + +Input * fpatch = 0; +Handle * config_file = 0; +int options = 0; + +Handle * options_cmds = 0; + +String title; String source, dest, patch; int langid; -void translate(int ownerid, HWND hW) { +CODE_BEGINS +static int myprint(lua_State * _L) { + Lua * L = Lua::find(_L); + String t = L->tostring(); + char * tc = t.strdup(); + + printm(M_STATUS, "%s\n", tc); + + free(tc); + + return 0; +} + +static void translate(int ownerid, HWND hW) { struct trad_t * t; struct texts_t * txt; @@ -130,7 +162,7 @@ void translate(int ownerid, HWND hW) { } } -const char * GetString(int id) { +static const char * GetString(int id) { struct trad_t * t; struct texts_t * txt; int oldlangid = langid; @@ -161,7 +193,45 @@ const char * GetString(int id) { return r; } -void ChooseFile(HWND hW, int iFType) { +static bool LoadPatch(HWND hW) { + char szB[260]; + + GetDlgItemText(hW, IDC_PATCH, szB, 259); + + try { + fpatch = new Input(szB); + fpatch->seek(0); + + new Archive(fpatch); + } + catch (GeneralException e) { + printm(M_ERROR, GetString(LOAD_ERROR) + String(" - ") + e.GetMsg()); + MessageBox(hW, GetString(LOAD_ERROR), GetString(MSGERROR), MB_OK | MB_ICONERROR); + return false; + } + + OPEN_PATCH_INI(true); + + ConfigFile cfg(config_file); + title = cfg["patch"]["title"]; + + if (cfg["patch"]["type"] == "rebuild") { + rebuild = true; + } else if (cfg["patch"]["type"] == "patch") { + rebuild = false; + } else { + MessageBox(hW, GetString(VERBOSE_CFG_ERROR), GetString(MSGERROR), MB_OK | MB_ICONERROR); + return false; + } + + options = cfg["patch"]["options"].to_int(); + + delete config_file; + + return true; +} + +static void ChooseFile(HWND hW, int iFType) { OPENFILENAME ofn; char szB[260]; BOOL b; @@ -231,7 +301,7 @@ void ChooseFile(HWND hW, int iFType) { } } -BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { +static BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT r; POINT p; int bwidth, bheight, wsize; @@ -251,17 +321,92 @@ BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { GetWindowRect(hW, &r); wsize = r.right - r.left; MoveWindow(button, wsize / 2 - bwidth / 2, p.y, bwidth, bheight, TRUE); + return TRUE; + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDOK: + EndDialog(hW, 0); + return TRUE; + } break; + } + return FALSE; +} + +static void set_options_dlg(HWND hW) { + int i, n; + HWND control; + String option_name; + + OPEN_PATCH_INI(false); + + ConfigFile cfg(config_file); + + option_name = cfg["options"][current_option]; + if (cfg[option_name]["type"] != "choices") { + MessageBox(hW, GetString(VERBOSE_CFG_ERROR), GetString(MSGERROR), MB_OK | MB_ICONERROR); + throw GeneralException(GetString(VERBOSE_CFG_ERROR)); + } + n = cfg[option_name]["size"].to_int(); + option_variable = cfg[option_name]["variable"]; + + SetDlgItemText(hW, IDC_ST_TITLE, cfg[option_name]["title"].to_charp()); + + control = GetDlgItem(hW, IDC_OPTIONS); + ComboBox_ResetContent(control); + + for (i = 0; i < n; i++) { + ComboBox_AddString(control, cfg[option_name][i].to_charp()); + } + ComboBox_SetCurSel(control, 0); + + delete config_file; +} + +static BOOL CALLBACK OptionsDlgProc(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_OPTIONS, hW); + + if (options_cmds) + delete options_cmds; + + options_cmds = new Buffer(true); + + 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); + set_options_dlg(hW); + return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { - case IDOK: EndDialog(hW, 0); return TRUE; + case IDOK: + (*options_cmds) << option_variable + "=" + ComboBox_GetCurSel(GetDlgItem(hW, IDC_OPTIONS)) + "\n"; + if ((++current_option) == options) { + EndDialog(hW, 0); + } else { + set_options_dlg(hW); + } + return TRUE; } break; } return FALSE; } -BOOL CALLBACK FileSelectDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { +static BOOL CALLBACK FileSelectDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { RECT r; POINT p; int bwidth, bheight, wsize; @@ -293,8 +438,6 @@ BOOL CALLBACK FileSelectDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam 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); @@ -307,7 +450,7 @@ BOOL CALLBACK FileSelectDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam GetWindowRect(hW, &r); wsize = r.right - r.left; MoveWindow(button, wsize / 2 - bwidth / 2, p.y, bwidth, bheight, TRUE); - break; + return TRUE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: @@ -322,6 +465,10 @@ BOOL CALLBACK FileSelectDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam DialogBox(0, MAKEINTRESOURCE(IDD_ABOUT), GetActiveWindow(), AboutDlgProc); return TRUE; + case IDC_OPTIONS: + DialogBox(0, MAKEINTRESOURCE(IDD_OPTIONS), + GetActiveWindow(), OptionsDlgProc); + return TRUE; case IDC_SOURCETYPE: if (HIWORD(wParam) != CBN_SELCHANGE) return FALSE; @@ -336,23 +483,52 @@ BOOL CALLBACK FileSelectDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam ShowWindow(GetDlgItem(hW, IDC_SOURCE), SW_SHOW); ShowWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), SW_SHOW); } - break; + return TRUE; case IDC_SOURCE_SELECT: ChooseFile(hW, SOURCE_SELECT); - break; + return TRUE; case IDC_PATCH_SELECT: ChooseFile(hW, PATCH_SELECT); - break; + if (LoadPatch(hW)) { + if (canprobe) { + EnableWindow(GetDlgItem(hW, IDC_SOURCETYPE), true); + EnableWindow(GetDlgItem(hW, IDC_ST_SOURCETYPE), true); + } + + if (rebuild) { + EnableWindow(GetDlgItem(hW, IDC_ST_SOURCE), true); + EnableWindow(GetDlgItem(hW, IDC_DRIVE), true); + EnableWindow(GetDlgItem(hW, IDC_SOURCE), true); + EnableWindow(GetDlgItem(hW, IDC_SOURCE_SELECT), true); + } else { + SetDlgItemText(hW, IDC_ST_DEST, GetString(ISOFILEPATCH)); + } + + EnableWindow(GetDlgItem(hW, IDC_ST_DEST), true); + EnableWindow(GetDlgItem(hW, IDC_DEST), true); + EnableWindow(GetDlgItem(hW, IDC_DEST_SELECT), true); + + EnableWindow(GetDlgItem(hW, IDC_PATCH), false); + EnableWindow(GetDlgItem(hW, IDC_PATCH_SELECT), false); + + SetDlgItemText(hW, IDC_ST_PATCH_TITLE, title.to_charp()); + + if (options) + EnableWindow(GetDlgItem(hW, IDC_OPTIONS), true); + } else { + SetDlgItemText(hW, IDC_PATCH, ""); + } + return TRUE; case IDC_DEST_SELECT: ChooseFile(hW, DEST_SELECT); - break; + return TRUE; } break; } return FALSE; } -bool Verify(HWND hW) { +static bool Verify(HWND hW) { char szB[260]; GetDlgItemText(hW, IDC_DEST, szB, 259); @@ -384,7 +560,6 @@ bool Verify(HWND hW) { return true; } -CODE_BEGINS virtual int startup(void) throw (GeneralException) { verbosity = M_INFO; printm(M_BARE, "CD-Tool core (C) 2003-2005 Nicolas \"Pixel\" Noble\nCompiled the " __DATE__ " at " __TIME__ "\n\n"); @@ -402,17 +577,21 @@ virtual int startup(void) throw (GeneralException) { if (quit) exit(0); - Input * fpatch = new Input(patch); - fpatch->seek(0); - - new Archive(fpatch); - Output * o; cdutils * cdutil; Handle * iso_r; + Handle * iso_w; + isobuilder * b; - cdutil = new cdutils(iso_r = cdabstract::open_cd(source)); - isobuilder * b = new isobuilder(o = new Output(dest)); + if (rebuild) { + iso_r = cdabstract::open_cd(source); + b = new isobuilder(o = new Output(dest)); + } else { + iso_r = new Input(source); + iso_w = new Output(source, 0, 0); + } + + cdutil = new cdutils(iso_r, iso_w); Lua * L = new Lua(); L->open_base(); @@ -434,33 +613,26 @@ virtual int startup(void) throw (GeneralException) { 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) { - printm(M_WARNING, GetString(PARASITE_EVE)); - config_file = new Buffer(true); - (*config_file) << -"[patch]\n" -"type=rebuild\n" -"filename=main\n" -"command=\n"; + if (rebuild) { + Luaisobuilder liso(b); + L->push("iso"); + liso.push(L); + L->setvar(); } + OPEN_PATCH_INI(false); + ConfigFile cfg(config_file); Buffer cmd; + if (options_cmds) + L->load(options_cmds); L->load(&Input(cfg["patch"]["filename"])); cmd << cfg["patch"]["command"]; L->load(&cmd); + delete options_cmds; delete config_file; delete b; diff --git a/luapatch.rc b/luapatch.rc index 0987039..2602292 100644 --- a/luapatch.rc +++ b/luapatch.rc @@ -13,6 +13,55 @@ #undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
+// Neutral resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
+#ifdef _WIN32
+LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_OPTIONS DIALOGEX 0, 0, 186, 81
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION |
+ WS_SYSMENU
+CAPTION "Options"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ DEFPUSHBUTTON "OK",IDOK,22,60,50,14,BS_CENTER | BS_FLAT
+ LTEXT "",IDC_ST_TITLE,7,17,172,8
+ COMBOBOX IDC_OPTIONS,7,36,172,80,CBS_DROPDOWN | CBS_SORT |
+ WS_VSCROLL | WS_TABSTOP
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_OPTIONS, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 179
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 74
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+#endif // Neutral resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
@@ -118,7 +167,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_POPUP | CAPTION "LuaPatch"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
- DEFPUSHBUTTON "OK",IDOK,58,173,50,14,BS_FLAT | WS_DISABLED
+ DEFPUSHBUTTON "OK",IDOK,58,173,50,14,BS_FLAT
PUSHBUTTON "Quit",IDCANCEL,131,173,50,14,BS_FLAT
PUSHBUTTON "About",IDC_ABOUT,7,173,50,14,BS_FLAT
LTEXT "Source type:",IDC_ST_SOURCETYPE,7,7,174,11,WS_DISABLED
@@ -133,8 +182,8 @@ BEGIN LTEXT "Patch file:",IDC_ST_PATCH,7,110,174,8
EDITTEXT IDC_PATCH,7,121,156,14,ES_AUTOHSCROLL
PUSHBUTTON "...",IDC_PATCH_SELECT,166,121,15,14
- EDITTEXT IDC_SOURCE,7,49,156,14,ES_AUTOHSCROLL
- PUSHBUTTON "...",IDC_SOURCE_SELECT,166,49,15,14
+ EDITTEXT IDC_SOURCE,7,49,156,14,ES_AUTOHSCROLL | WS_DISABLED
+ PUSHBUTTON "...",IDC_SOURCE_SELECT,166,49,15,14,WS_DISABLED
LTEXT "",IDC_ST_PATCH_TITLE,7,147,174,8
PUSHBUTTON "Options",IDC_OPTIONS,131,158,50,14,BS_FLAT |
WS_DISABLED
|