From 2bf3860cbc11cc786f5dbd1d86577e1801c79aaf Mon Sep 17 00:00:00 2001 From: Vhati Date: Sun, 15 Sep 2013 01:31:48 -0400 Subject: [PATCH] Added '--global-panic' commandline arg --- skel_common/readme_changelog.txt | 2 ++ skel_common/readme_modders.txt | 19 +++++++++++++++++++ .../vhati/modmanager/cli/SlipstreamCLI.java | 9 +++++++-- .../vhati/modmanager/core/ModPatchThread.java | 6 ++++-- .../vhati/modmanager/core/ModUtilities.java | 3 ++- .../net/vhati/modmanager/core/XMLPatcher.java | 17 +++++++++++++---- .../net/vhati/modmanager/ui/ManagerFrame.java | 2 +- .../vhati/modmanager/ui/ModXMLSandbox.java | 1 + 8 files changed, 49 insertions(+), 10 deletions(-) diff --git a/skel_common/readme_changelog.txt b/skel_common/readme_changelog.txt index aaf1173..76cc96f 100644 --- a/skel_common/readme_changelog.txt +++ b/skel_common/readme_changelog.txt @@ -5,6 +5,8 @@ Changelog - Fixed advanced find tags' panic arg (was "true" all the time) - Fixed advanced selector tag not narrowing results when it had a value - Fixed perpetually green "Update" button +- Added --global-panic commandline arg to show mod devs typoed find tags +- Added commandline tips in readme_modders.txt 1.2: - Added a commandline interface diff --git a/skel_common/readme_modders.txt b/skel_common/readme_modders.txt index 923a596..eb3b9bf 100644 --- a/skel_common/readme_modders.txt +++ b/skel_common/readme_modders.txt @@ -191,6 +191,25 @@ Advanced XML edit in the wake of earlier ones. +Commandline + + Running Slipstream from a prompt can speed up development... + + --patch Abc.ftl Def "Ghi 1.0.ftl" + + Patches named mod files. Dirs can also be named, so you won't have to + re-zip for every test. + + --global-panic + + While patching, reveals typoed tags. Any find that yields no + matches will cause an error, as if it had panic='true'. + + --runftl + + Runs the game. If used with "--patch", runs afterward if successful. + + Pitfalls FTL Bug (fixed in 1.03.3): If a ship is modded to have level 5 shields, diff --git a/src/main/java/net/vhati/modmanager/cli/SlipstreamCLI.java b/src/main/java/net/vhati/modmanager/cli/SlipstreamCLI.java index 6876941..85c9b30 100644 --- a/src/main/java/net/vhati/modmanager/cli/SlipstreamCLI.java +++ b/src/main/java/net/vhati/modmanager/cli/SlipstreamCLI.java @@ -56,11 +56,14 @@ public class SlipstreamCLI { .hasArg() .withArgName("DIR") .create() ); + options.addOption( OptionBuilder.withLongOpt( "global-panic" ) + .withDescription( "patch as if advanced find tags had panic='true'" ) + .create() ); options.addOption( OptionBuilder.withLongOpt( "list-mods" ) .withDescription( "list available mod names" ) .create() ); options.addOption( OptionBuilder.withLongOpt( "runftl" ) - .withDescription( "run the game" ) + .withDescription( "run the game (standalone or with 'patch')" ) .create() ); options.addOption( OptionBuilder.withLongOpt( "patch" ) .withDescription( "revert to vanilla and add named mods (if any)" ) @@ -259,8 +262,10 @@ public class SlipstreamCLI { resDat.datFile = new File( datsDir, "resource.dat" ); resDat.bakFile = new File( backupDir, "resource.dat.bak" ); + boolean globalPanic = cmdline.hasOption( "global-panic" ); + SilentPatchObserver patchObserver = new SilentPatchObserver(); - ModPatchThread patchThread = new ModPatchThread( modFiles, dataDat, resDat, patchObserver ); + ModPatchThread patchThread = new ModPatchThread( modFiles, dataDat, resDat, globalPanic, patchObserver ); deleteHook.addWatchedThread( patchThread ); patchThread.start(); diff --git a/src/main/java/net/vhati/modmanager/core/ModPatchThread.java b/src/main/java/net/vhati/modmanager/core/ModPatchThread.java index fe407e4..8f1fcfb 100644 --- a/src/main/java/net/vhati/modmanager/core/ModPatchThread.java +++ b/src/main/java/net/vhati/modmanager/core/ModPatchThread.java @@ -37,6 +37,7 @@ public class ModPatchThread extends Thread { private List modFiles = new ArrayList(); private BackedUpDat dataDat = null; private BackedUpDat resDat = null; + private boolean globalPanic = false; private ModPatchObserver observer = null; private final int progMax = 100; @@ -46,10 +47,11 @@ public class ModPatchThread extends Thread { private final int progRepackMax = 5; private int progMilestone = 0; - public ModPatchThread( List modFiles, BackedUpDat dataDat, BackedUpDat resDat, ModPatchObserver observer ) { + public ModPatchThread( List modFiles, BackedUpDat dataDat, BackedUpDat resDat, boolean globalPanic, ModPatchObserver observer ) { this.modFiles.addAll( modFiles ); this.dataDat = dataDat; this.resDat = resDat; + this.globalPanic = globalPanic; this.observer = observer; } @@ -223,7 +225,7 @@ public class ModPatchThread extends Thread { InputStream mainStream = null; try { mainStream = ftlP.getInputStream(innerPath); - InputStream mergedStream = ModUtilities.patchXMLFile( mainStream, zis, "windows-1252", ftlP.getName()+":"+innerPath, modFile.getName()+":"+parentPath+fileName ); + InputStream mergedStream = ModUtilities.patchXMLFile( mainStream, zis, "windows-1252", globalPanic, ftlP.getName()+":"+innerPath, modFile.getName()+":"+parentPath+fileName ); mainStream.close(); ftlP.remove( innerPath ); ftlP.add( innerPath, mergedStream ); diff --git a/src/main/java/net/vhati/modmanager/core/ModUtilities.java b/src/main/java/net/vhati/modmanager/core/ModUtilities.java index 3c5acfe..b8500b4 100644 --- a/src/main/java/net/vhati/modmanager/core/ModUtilities.java +++ b/src/main/java/net/vhati/modmanager/core/ModUtilities.java @@ -207,7 +207,7 @@ public class ModUtilities { * @see net.vhati.modmanager.core.XMLPatcher * @see net.vhati.modmanager.core.SloppyXMLOutputProcessor */ - public static InputStream patchXMLFile( InputStream mainStream, InputStream appendStream, String encoding, String mainDescription, String appendDescription ) throws IOException, JDOMException { + public static InputStream patchXMLFile( InputStream mainStream, InputStream appendStream, String encoding, boolean globalPanic, String mainDescription, String appendDescription ) throws IOException, JDOMException { Pattern xmlDeclPtn = Pattern.compile( "<[?]xml [^>]*?[?]>\n*" ); String mainText = decodeText( mainStream, mainDescription ).text; @@ -221,6 +221,7 @@ public class ModUtilities { Document appendDoc = parseStrictOrSloppyXML( appendText, appendDescription+" (wrapped)" ); XMLPatcher patcher = new XMLPatcher(); + patcher.setGlobalPanic( globalPanic ); Document mergedDoc = patcher.patch( mainDoc, appendDoc ); StringWriter writer = new StringWriter(); diff --git a/src/main/java/net/vhati/modmanager/core/XMLPatcher.java b/src/main/java/net/vhati/modmanager/core/XMLPatcher.java index 22a6422..d330c6d 100644 --- a/src/main/java/net/vhati/modmanager/core/XMLPatcher.java +++ b/src/main/java/net/vhati/modmanager/core/XMLPatcher.java @@ -36,6 +36,7 @@ import org.jdom2.input.SAXBuilder; */ public class XMLPatcher { + protected boolean globalPanic = false; protected Namespace modNS; protected Namespace modAppendNS; protected Namespace modOverwriteNS; @@ -47,6 +48,10 @@ public class XMLPatcher { modOverwriteNS = Namespace.getNamespace( "mod-overwrite", "mod-overwrite" ); } + public void setGlobalPanic( boolean b ) { + globalPanic = b; + } + public Document patch( Document mainDoc, Document appendDoc ) { Document resultDoc = mainDoc.clone(); @@ -100,7 +105,8 @@ public class XMLPatcher { int searchStart = getAttributeIntValue( node, "start", 0 ); int searchLimit = getAttributeIntValue( node, "limit", 1 ); boolean panic = getAttributeBooleanValue( node, "panic", false ); - + if ( globalPanic ) panic = true; + if ( searchName == null || searchName.length() == 0 ) throw new IllegalArgumentException( String.format( "<%s> requires a name attribute (%s).", node.getName(), getPathToRoot(node) ) ); if ( searchType != null && searchType.length() == 0 ) @@ -136,7 +142,8 @@ public class XMLPatcher { int searchStart = getAttributeIntValue( node, "start", 0 ); int searchLimit = getAttributeIntValue( node, "limit", -1 ); boolean panic = getAttributeBooleanValue( node, "panic", false ); - + if ( globalPanic ) panic = true; + if ( searchType != null && searchType.length() == 0 ) throw new IllegalArgumentException( String.format( "<%s> type attribute, when present, can't be empty (%s).", node.getName(), getPathToRoot(node) ) ); if ( searchStart < 0 ) @@ -188,7 +195,8 @@ public class XMLPatcher { int searchStart = getAttributeIntValue( node, "start", 0 ); int searchLimit = getAttributeIntValue( node, "limit", -1 ); boolean panic = getAttributeBooleanValue( node, "panic", false ); - + if ( globalPanic ) panic = true; + if ( searchType != null && searchType.length() == 0 ) throw new IllegalArgumentException( String.format( "<%s> type attribute, when present, can't be empty (%s).", node.getName(), getPathToRoot(node) ) ); if ( searchChildType != null && searchChildType.length() == 0 ) @@ -237,7 +245,8 @@ public class XMLPatcher { int searchStart = getAttributeIntValue( node, "start", 0 ); int searchLimit = getAttributeIntValue( node, "limit", -1 ); boolean panic = getAttributeBooleanValue( node, "panic", false ); - + if ( globalPanic ) panic = true; + if ( searchStart < 0 ) throw new IllegalArgumentException( String.format( "<%s> 'start' attribute is not >= 0 (%s).", node.getName(), getPathToRoot(node) ) ); if ( searchLimit < -1 ) diff --git a/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java b/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java index 36568ad..298c169 100644 --- a/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java +++ b/src/main/java/net/vhati/modmanager/ui/ManagerFrame.java @@ -818,7 +818,7 @@ public class ManagerFrame extends JFrame implements ActionListener, HashObserver log.info( "" ); log.info( "Patching..." ); log.info( "" ); - ModPatchThread patchThread = new ModPatchThread( modFiles, dataDat, resDat, patchDlg ); + ModPatchThread patchThread = new ModPatchThread( modFiles, dataDat, resDat, false, patchDlg ); patchThread.start(); patchDlg.setVisible( true ); diff --git a/src/main/java/net/vhati/modmanager/ui/ModXMLSandbox.java b/src/main/java/net/vhati/modmanager/ui/ModXMLSandbox.java index ea93000..6e1bc37 100644 --- a/src/main/java/net/vhati/modmanager/ui/ModXMLSandbox.java +++ b/src/main/java/net/vhati/modmanager/ui/ModXMLSandbox.java @@ -373,6 +373,7 @@ public class ModXMLSandbox extends JFrame implements ActionListener { Document appendDoc = ModUtilities.parseStrictOrSloppyXML( appendText, "Sandbox Append XML" ); XMLPatcher patcher = new XMLPatcher(); + patcher.setGlobalPanic( false ); Document resultDoc = patcher.patch( mainDoc, appendDoc ); StringWriter writer = new StringWriter();