Patching now converts all text to windows-1252, because FTL expects that apparently
This commit is contained in:
parent
3d109f1b20
commit
97c54d26e3
2 changed files with 15 additions and 25 deletions
|
@ -223,7 +223,7 @@ public class ModPatchThread extends Thread {
|
|||
InputStream mainStream = null;
|
||||
try {
|
||||
mainStream = ftlP.getInputStream(innerPath);
|
||||
InputStream mergedStream = ModUtilities.patchXMLFile( mainStream, zis, ftlP.getName()+":"+innerPath, modFile.getName()+":"+parentPath+fileName );
|
||||
InputStream mergedStream = ModUtilities.patchXMLFile( mainStream, zis, "windows-1252", ftlP.getName()+":"+innerPath, modFile.getName()+":"+parentPath+fileName );
|
||||
mainStream.close();
|
||||
ftlP.remove( innerPath );
|
||||
ftlP.add( innerPath, mergedStream );
|
||||
|
@ -241,7 +241,14 @@ public class ModPatchThread extends Thread {
|
|||
innerPath = checkCase( innerPath, knownPaths, knownPathsLower );
|
||||
|
||||
// Normalize line endings for other text files to CR-LF.
|
||||
InputStream fixedStream = ModUtilities.setLineEndings( zis, "\r\n", modFile.getName()+":"+parentPath+fileName );
|
||||
// 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" );
|
||||
|
||||
if ( fileName.endsWith( ".xml" ) )
|
||||
fixedText = fixedText.replaceAll( "<[?]xml [^>]*?[?]>\n*", "<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n" );
|
||||
|
||||
InputStream fixedStream = ModUtilities.encodeText( fixedText, "windows-1252", modFile.getName()+":"+parentPath+fileName+" (with new EOL)" );
|
||||
|
||||
if ( !moddedItems.contains(innerPath) )
|
||||
moddedItems.add( innerPath );
|
||||
|
|
|
@ -198,14 +198,16 @@ public class ModUtilities {
|
|||
* The returned stream is a ByteArrayInputStream
|
||||
* which doesn't need closing.
|
||||
*
|
||||
* The result will be UTF-8 with CR-LF line endings.
|
||||
* The result will have CR-LF line endings and the desired encoding.
|
||||
* FTL stubbornly assumes all XML is in windows-1252 encoding, even
|
||||
* on Linux.
|
||||
*
|
||||
* The description arguments identify the streams for log messages.
|
||||
*
|
||||
* @see net.vhati.modmanager.core.XMLPatcher
|
||||
* @see net.vhati.modmanager.core.SloppyXMLOutputProcessor
|
||||
*/
|
||||
public static InputStream patchXMLFile( InputStream mainStream, InputStream appendStream, String mainDescription, String appendDescription ) throws IOException, JDOMException {
|
||||
public static InputStream patchXMLFile( InputStream mainStream, InputStream appendStream, String encoding, String mainDescription, String appendDescription ) throws IOException, JDOMException {
|
||||
Pattern xmlDeclPtn = Pattern.compile( "<[?]xml [^>]*?[?]>\n*" );
|
||||
|
||||
String mainText = decodeText( mainStream, mainDescription ).text;
|
||||
|
@ -222,10 +224,10 @@ public class ModUtilities {
|
|||
Document mergedDoc = patcher.patch( mainDoc, appendDoc );
|
||||
|
||||
StringWriter writer = new StringWriter();
|
||||
SloppyXMLOutputProcessor.sloppyPrint( mergedDoc, writer, null );
|
||||
SloppyXMLOutputProcessor.sloppyPrint( mergedDoc, writer, encoding );
|
||||
String mergedString = writer.toString();
|
||||
|
||||
InputStream result = encodeText( mergedString, "UTF-8", mainDescription+"+"+appendDescription );
|
||||
InputStream result = encodeText( mergedString, encoding, mainDescription+"+"+appendDescription );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -263,25 +265,6 @@ public class ModUtilities {
|
|||
return doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls decodeText() on a stream, replaces line endings, and re-encodes.
|
||||
*
|
||||
* The returned stream is a ByteArrayInputStream
|
||||
* which doesn't need closing.
|
||||
*
|
||||
* The result will be UTF-8 with the desired line endings.
|
||||
*
|
||||
* The description argument identifies the stream for log messages.
|
||||
*/
|
||||
public static InputStream setLineEndings( InputStream srcStream, String eol, String srcDescription ) throws IOException {
|
||||
// decodeText() returns a LF string.
|
||||
String srcText = decodeText( srcStream, srcDescription ).text;
|
||||
String fixedText = Pattern.compile("\n").matcher( srcText ).replaceAll( Matcher.quoteReplacement(eol) );
|
||||
|
||||
InputStream result = encodeText( fixedText, "UTF-8", srcDescription+" (with new EOL)" );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks a mod file for common problems.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue