diff options
Diffstat (limited to 'luapatch.cpp')
-rw-r--r-- | luapatch.cpp | 185 |
1 files changed, 86 insertions, 99 deletions
diff --git a/luapatch.cpp b/luapatch.cpp index 7665b9e..369b55a 100644 --- a/luapatch.cpp +++ b/luapatch.cpp @@ -2,9 +2,11 @@ #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" @@ -14,124 +16,78 @@ #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); - Base::printm(M_BARE, t + "\n"); + free(tc); return 0; } -bool Verify(HWND); - -enum strings_e { - ISOFILE, - CDDRIVE, - ISOSOURCE, - ISODEST, - PATCH, - NO_DESTINATION, - NO_SOURCE, - NO_PATCH, - MSGERROR, +class Luabasecdtool : public LuaObject { + public: + static void pushstatics(Lua *) throw (GeneralException); }; -bool quit = false; -bool canprobe; -bool fromdrive = false; - -String source, dest, patch; +typedef void basecdtool; -struct texts_t { - int id; - int owner; - char * str; +enum basecdtool_t { + BASECDTOOL_LOAD = 0, }; -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 lua_functypes_t basecdtool_functions[] = { + { BASECDTOOL_LOAD, "load", 0, 1, { LUA_STRING | LUA_OBJECT } }, + { -1, 0, 0, 0, 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} +class sLua_basecdtool : public Base { + public: + DECLARE_FUNCTION(basecdtool, BASECDTOOL_LOAD); + private: + static int basecdtool_proceed_statics(Lua * L, int n, int caller); }; -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} -}; +void Luabasecdtool::pushstatics(Lua * L) throw (GeneralException ) { + CHECK_FUNCTIONS(basecdtool); + + PUSH_FUNCTION(basecdtool, BASECDTOOL_LOAD); +} -struct trad_t { - int langid; - struct texts_t * trad; -}; +int sLua_basecdtool::basecdtool_proceed_statics(Lua * L, int n, int caller) { + int r = 0; -struct trad_t trads[] = { - {LANG_NEUTRAL, t_english}, - {LANG_FRENCH, t_french}, - {LANG_GERMAN, t_german}, - {-1, 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); + } + } + } -int langid; + return r; +} -enum { - DEST_SELECT, - SOURCE_SELECT, - PATCH_SELECT, -}; +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; @@ -405,7 +361,7 @@ bool Verify(HWND hW) { CODE_BEGINS virtual int startup(void) throw (GeneralException) { verbosity = M_INFO; - printm(M_BARE, "LuaPatch (C) 2004 Nicolas \"Pixel\" Noble - front-end starting.\n"); + printm(M_BARE, "LuaPatch (C) 2003-2005 Nicolas \"Pixel\" Noble - front-end starting.\n"); int lang; lang = GetUserDefaultLangID(); @@ -436,6 +392,7 @@ virtual int startup(void) throw (GeneralException) { L->open_math(); L->open_string(); L->open_table(); + L->open_dir(); LuaInput::pushconstruct(L); LuaOutput::pushconstruct(L); LuaBuffer::pushconstruct(L); @@ -444,6 +401,7 @@ virtual int startup(void) throw (GeneralException) { L->push("print"); L->push(myprint); L->settable(LUA_GLOBALSINDEX); + Luabasecdtool::pushstatics(L); Luacdutils lcdutil(cdutil); L->push("cdutil"); @@ -453,13 +411,42 @@ virtual int startup(void) throw (GeneralException) { L->push("iso"); liso.push(L); L->setvar(); - L->load(&Input("main")); + + 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 |