diff options
Diffstat (limited to 'luapatch.cpp')
-rw-r--r-- | luapatch.cpp | 280 |
1 files changed, 226 insertions, 54 deletions
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; |