Conditionally set encoding to UTF-8 for ftl.dat, vs windows-1252 for data.dat+resource.dat

This commit is contained in:
Vhati 2017-12-11 13:34:11 -05:00
parent 857fb5d33d
commit 93b9c9b1b0
2 changed files with 26 additions and 11 deletions

View file

@ -176,6 +176,8 @@ public class ModPatchThread extends Thread {
return true; return true;
} }
String ultimateEncoding = null;
packContainer = new PackContainer(); packContainer = new PackContainer();
if ( ftlDatFile.exists() ) { // FTL 1.6.1. if ( ftlDatFile.exists() ) { // FTL 1.6.1.
AbstractPack ftlPack = new PkgPack( ftlDatFile, "r+" ); AbstractPack ftlPack = new PkgPack( ftlDatFile, "r+" );
@ -186,6 +188,8 @@ public class ModPatchThread extends Thread {
packContainer.setPackFor( "img/", ftlPack ); packContainer.setPackFor( "img/", ftlPack );
packContainer.setPackFor( null, ftlPack ); packContainer.setPackFor( null, ftlPack );
// Supposedly "exe_icon.png" has been observed at top-level? // Supposedly "exe_icon.png" has been observed at top-level?
ultimateEncoding = "UTF-8";
} }
else if ( dataDatFile.exists() && resourceDatFile.exists() ) { // FTL 1.01-1.5.13. else if ( dataDatFile.exists() && resourceDatFile.exists() ) { // FTL 1.01-1.5.13.
AbstractPack dataPack = new FTLPack( dataDatFile, "r+" ); AbstractPack dataPack = new FTLPack( dataDatFile, "r+" );
@ -195,6 +199,8 @@ public class ModPatchThread extends Thread {
packContainer.setPackFor( "data/", dataPack ); packContainer.setPackFor( "data/", dataPack );
packContainer.setPackFor( "fonts/", resourcePack ); packContainer.setPackFor( "fonts/", resourcePack );
packContainer.setPackFor( "img/", resourcePack ); packContainer.setPackFor( "img/", resourcePack );
ultimateEncoding = "windows-1252";
} }
else { else {
throw new IOException( String.format( "Could not find either \"%s\" or both \"%s\" and \"%s\"", ftlDatFile.getName(), dataDatFile.getName(), resourceDatFile.getName() ) ); throw new IOException( String.format( "Could not find either \"%s\" or both \"%s\" and \"%s\"", ftlDatFile.getName(), dataDatFile.getName(), resourceDatFile.getName() ) );
@ -277,7 +283,7 @@ public class ModPatchThread extends Thread {
InputStream mainStream = null; InputStream mainStream = null;
try { try {
mainStream = pack.getInputStream( innerPath ); mainStream = pack.getInputStream( innerPath );
InputStream mergedStream = ModUtilities.patchXMLFile( mainStream, zis, "windows-1252", globalPanic, pack.getName()+":"+innerPath, modFile.getName()+":"+parentPath+fileName ); InputStream mergedStream = ModUtilities.patchXMLFile( mainStream, zis, ultimateEncoding, globalPanic, pack.getName()+":"+innerPath, modFile.getName()+":"+parentPath+fileName );
mainStream.close(); mainStream.close();
pack.remove( innerPath ); pack.remove( innerPath );
pack.add( innerPath, mergedStream ); pack.add( innerPath, mergedStream );
@ -304,7 +310,7 @@ public class ModPatchThread extends Thread {
InputStream mainStream = null; InputStream mainStream = null;
try { try {
mainStream = pack.getInputStream( innerPath ); mainStream = pack.getInputStream( innerPath );
InputStream mergedStream = ModUtilities.appendXMLFile( mainStream, zis, "windows-1252", pack.getName()+":"+innerPath, modFile.getName()+":"+parentPath+fileName ); InputStream mergedStream = ModUtilities.appendXMLFile( mainStream, zis, ultimateEncoding, pack.getName()+":"+innerPath, modFile.getName()+":"+parentPath+fileName );
mainStream.close(); mainStream.close();
pack.remove( innerPath ); pack.remove( innerPath );
pack.add( innerPath, mergedStream ); pack.add( innerPath, mergedStream );
@ -330,7 +336,7 @@ public class ModPatchThread extends Thread {
String fixedText = ModUtilities.decodeText( zis, modFile.getName()+":"+parentPath+fileName ).text; String fixedText = ModUtilities.decodeText( zis, modFile.getName()+":"+parentPath+fileName ).text;
fixedText = Pattern.compile("\n").matcher( fixedText ).replaceAll( "\r\n" ); fixedText = Pattern.compile("\n").matcher( fixedText ).replaceAll( "\r\n" );
InputStream fixedStream = ModUtilities.encodeText( fixedText, "windows-1252", modFile.getName()+":"+parentPath+fileName+" (with new EOL)" ); InputStream fixedStream = ModUtilities.encodeText( fixedText, ultimateEncoding, modFile.getName()+":"+parentPath+fileName+" (with new EOL)" );
if ( !moddedItems.contains( innerPath ) ) { if ( !moddedItems.contains( innerPath ) ) {
moddedItems.add( innerPath ); moddedItems.add( innerPath );
@ -345,7 +351,7 @@ public class ModPatchThread extends Thread {
else if ( fileName.endsWith( ".xml" ) ) { else if ( fileName.endsWith( ".xml" ) ) {
innerPath = checkCase( innerPath, knownPaths, knownPathsLower ); innerPath = checkCase( innerPath, knownPaths, knownPathsLower );
InputStream fixedStream = ModUtilities.rebuildXMLFile( zis, "windows-1252", modFile.getName()+":"+parentPath+fileName ); InputStream fixedStream = ModUtilities.rebuildXMLFile( zis, ultimateEncoding, modFile.getName()+":"+parentPath+fileName );
if ( !moddedItems.contains( innerPath ) ) { if ( !moddedItems.contains( innerPath ) ) {
moddedItems.add( innerPath ); moddedItems.add( innerPath );
@ -365,7 +371,7 @@ public class ModPatchThread extends Thread {
String fixedText = ModUtilities.decodeText( zis, modFile.getName()+":"+parentPath+fileName ).text; String fixedText = ModUtilities.decodeText( zis, modFile.getName()+":"+parentPath+fileName ).text;
fixedText = Pattern.compile("\n").matcher( fixedText ).replaceAll( "\r\n" ); fixedText = Pattern.compile("\n").matcher( fixedText ).replaceAll( "\r\n" );
InputStream fixedStream = ModUtilities.encodeText( fixedText, "windows-1252", modFile.getName()+":"+parentPath+fileName+" (with new EOL)" ); InputStream fixedStream = ModUtilities.encodeText( fixedText, ultimateEncoding, modFile.getName()+":"+parentPath+fileName+" (with new EOL)" );
if ( !moddedItems.contains( innerPath ) ) { if ( !moddedItems.contains( innerPath ) ) {
moddedItems.add( innerPath ); moddedItems.add( innerPath );

View file

@ -179,8 +179,11 @@ public class ModUtilities {
* closing. * closing.
* *
* The result will have CR-LF line endings and the desired encoding. * The result will have CR-LF line endings and the desired encoding.
* Note: FTL stubbornly assumes all XML is in windows-1252 encoding, even *
* on Linux. * FTL 1.01-1.5.13 assumes all XML is in windows-1252 encoding, even on
* Linux.
*
* FTL 1.6.1 assumes all XML is in UTF-8 encoding.
* *
* The description arguments identify the streams for log messages. * The description arguments identify the streams for log messages.
* *
@ -244,8 +247,11 @@ public class ModUtilities {
* which doesn't need closing. * which doesn't need closing.
* *
* The result will have CR-LF line endings and the desired encoding. * The result will have CR-LF line endings and the desired encoding.
* Note: FTL stubbornly assumes all XML is in windows-1252 encoding, *
* even on Linux. * FTL 1.01-1.5.13 assumes all XML is in windows-1252 encoding, even on
* Linux.
*
* FTL 1.6.1 assumes all XML is in UTF-8 encoding.
* *
* The description arguments identify the streams for log messages. * The description arguments identify the streams for log messages.
* *
@ -334,8 +340,11 @@ public class ModUtilities {
* which doesn't need closing. * which doesn't need closing.
* *
* The result will have CR-LF line endings and the desired encoding. * The result will have CR-LF line endings and the desired encoding.
* Note: FTL stubbornly assumes all XML is in windows-1252 encoding, *
* even on Linux. * FTL 1.01-1.5.13 assumes all XML is in windows-1252 encoding, even on
* Linux.
*
* FTL 1.6.1 assumes all XML is in UTF-8 encoding.
* *
* The description argument identifies the stream for log messages. * The description argument identifies the stream for log messages.
* *