From ae2cb23cbfc2097870c5141dca225771718f2457 Mon Sep 17 00:00:00 2001 From: Vhati Date: Tue, 21 Oct 2014 21:28:50 -0400 Subject: [PATCH] Added *.xml.rawclobber suffix to preserve whitespace --- skel_common/readme_changelog.txt | 2 +- skel_common/readme_modders.txt | 10 +++++++-- .../vhati/modmanager/core/ModPatchThread.java | 22 +++++++++++++++++++ .../vhati/modmanager/core/ModUtilities.java | 11 ++++++++-- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/skel_common/readme_changelog.txt b/skel_common/readme_changelog.txt index 7c9bbab..2a20e13 100644 --- a/skel_common/readme_changelog.txt +++ b/skel_common/readme_changelog.txt @@ -15,7 +15,7 @@ Changelog - Added a Validate warning for junk files named '.dropbox' - Added a check during patching to skip junk files - Added an error popup when the jar is double-clicked -- Added *.xml.rawappend suffix to preserve whitespace in 'misc.xml' +- Added rawappend/rawclobber suffixes to preserve whitespace in 'misc.xml' - Minor optimizations to reduce memory usage - Added uncaught exception handling for background threads diff --git a/skel_common/readme_modders.txt b/skel_common/readme_modders.txt index 835430e..41569d0 100644 --- a/skel_common/readme_modders.txt +++ b/skel_common/readme_modders.txt @@ -197,7 +197,7 @@ Advanced XML edit in the wake of earlier ones. -Raw Appending +Raw XML FTL is quirky. Occasionally you may need to include non-standard XML in a mod without elaborate parsing. For instance, "misc.xml" defines phrases @@ -210,7 +210,13 @@ Raw Appending (mis)understand the tags of either file. You can still override existing tags by adding your own with the same - name attribute. + name attribute, since FTL honors the last it sees. + + Similarly a file named "misc.xml.rawclobber" will entirely replace the + original "misc.xml". + + Any other mods patched afterward must either avoid that file or also treat + it as raw themselves. Hence this should be used as a last resort. Commandline diff --git a/src/main/java/net/vhati/modmanager/core/ModPatchThread.java b/src/main/java/net/vhati/modmanager/core/ModPatchThread.java index 7039eaa..91aead8 100644 --- a/src/main/java/net/vhati/modmanager/core/ModPatchThread.java +++ b/src/main/java/net/vhati/modmanager/core/ModPatchThread.java @@ -281,6 +281,28 @@ public class ModPatchThread extends Thread { } } } + else if ( fileName.endsWith( ".xml.rawclobber" ) || fileName.endsWith( ".rawclobber.xml" ) ) { + innerPath = checkCase( innerPath, knownPaths, knownPathsLower ); + + log.warn( String.format( "Copying xml as raw text: %s", innerPath ) ); + + // Normalize line endings to CR-LF. + // decodeText() reads anything and returns an LF string. + String fixedText = ModUtilities.decodeText( zis, modFile.getName()+":"+parentPath+fileName ).text; + fixedText = Pattern.compile("\n").matcher( fixedText ).replaceAll( "\r\n" ); + + InputStream fixedStream = ModUtilities.encodeText( fixedText, "windows-1252", modFile.getName()+":"+parentPath+fileName+" (with new EOL)" ); + + if ( !moddedItems.contains(innerPath) ) { + moddedItems.add( innerPath ); + } else { + log.warn( String.format( "Clobbering earlier mods: %s", innerPath ) ); + } + + if ( ftlP.contains( innerPath ) ) + ftlP.remove( innerPath ); + ftlP.add( innerPath, fixedStream ); + } else if ( fileName.endsWith( ".xml" ) ) { innerPath = checkCase( innerPath, knownPaths, knownPathsLower ); diff --git a/src/main/java/net/vhati/modmanager/core/ModUtilities.java b/src/main/java/net/vhati/modmanager/core/ModUtilities.java index 65e12c0..db97ff2 100644 --- a/src/main/java/net/vhati/modmanager/core/ModUtilities.java +++ b/src/main/java/net/vhati/modmanager/core/ModUtilities.java @@ -457,11 +457,18 @@ public class ModUtilities { modValid = false; } } - else if ( innerPath.matches( "^.*(?:[.]xml[.]append|[.]append[.]xml|[.]xml[.]rawappend|[.]rawappend[.]xml|[.]xml|[.]txt)$" ) ) { + else if ( innerPath.matches( "^.*(?:[.]xml[.]append|[.]append[.]xml)$" ) || + innerPath.matches( "^.*(?:[.]xml[.]rawappend|[.]rawappend[.]xml)$" ) || + innerPath.matches( "^.*(?:[.]xml[.]rawclobber|[.]rawclobber[.]xml)$" ) || + innerPath.matches( "^.*(?:[.]xml|[.]txt)$" ) ) { + boolean isTxt = innerPath.matches( "^.*(?:[.]txt)$" ); boolean isXML = innerPath.matches( "^.*(?:[.]xml[.]append|[.]append[.]xml|[.]xml)$" ); boolean isXMLAppend = innerPath.matches( "^.*(?:[.]xml[.]append|[.]append[.]xml)$" ); - if ( innerPath.matches( "^.*(?:[.]xml[.]rawappend|[.]rawappend[.]xml)$" ) ) { + + if ( innerPath.matches( "^.*(?:[.]xml[.]rawappend|[.]rawappend[.]xml)$" ) || + innerPath.matches( "^.*(?:[.]xml[.]rawclobber|[.]rawclobber[.]xml)$" ) ) { + isXML = false; // Raw xml is exempt from normal processing. }