Added tolerance/warning for non-standard zips containing backslash paths

This commit is contained in:
Vhati 2013-08-24 19:57:42 -04:00
parent 248cc5d6aa
commit 33064ebff2
4 changed files with 28 additions and 7 deletions

View file

@ -190,9 +190,12 @@ public class ModPatchThread extends Thread {
while ( (item = zis.getNextEntry()) != null ) {
if ( item.isDirectory() ) continue;
Matcher m = pathPtn.matcher( item.getName() );
String innerPath = item.getName();
innerPath = innerPath.replace( '\\', '/' ); // Non-standard zips.
Matcher m = pathPtn.matcher( innerPath );
if ( !m.matches() ) {
log.warn( String.format( "Unexpected innerPath: %s", item.getName() ) );
log.warn( String.format( "Unexpected innerPath: %s", innerPath ) );
zis.closeEntry();
continue;
}
@ -203,13 +206,13 @@ public class ModPatchThread extends Thread {
AbstractPack ftlP = topFolderMap.get( topFolder );
if ( ftlP == null ) {
log.warn( String.format( "Unexpected innerPath: %s", item.getName() ) );
log.warn( String.format( "Unexpected innerPath: %s", innerPath ) );
zis.closeEntry();
continue;
}
if ( fileName.endsWith( ".xml.append" ) || fileName.endsWith( ".append.xml" ) ) {
String innerPath = parentPath + fileName.replaceAll( "[.](?:xml[.]append|append[.]xml)$", ".xml" );
innerPath = parentPath + fileName.replaceAll( "[.](?:xml[.]append|append[.]xml)$", ".xml" );
innerPath = checkCase( innerPath, knownPaths, knownPathsLower );
if ( !ftlP.contains( innerPath ) ) {
@ -234,7 +237,7 @@ public class ModPatchThread extends Thread {
}
}
else if ( fileName.endsWith( ".xml" ) || fileName.endsWith( ".txt" ) ) {
String innerPath = checkCase( item.getName(), knownPaths, knownPathsLower );
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 );
@ -249,7 +252,7 @@ public class ModPatchThread extends Thread {
ftlP.add( innerPath, fixedStream );
}
else {
String innerPath = checkCase( item.getName(), knownPaths, knownPathsLower );
innerPath = checkCase( innerPath, knownPaths, knownPathsLower );
if ( !moddedItems.contains(innerPath) )
moddedItems.add( innerPath );

View file

@ -223,6 +223,15 @@ public class ModUtilities {
String innerPath = item.getName();
pendingMsgs.clear();
if ( innerPath.indexOf( "\\" ) != -1 ) {
pendingMsgs.add( new ReportMessage(
ReportMessage.ERROR,
String.format( "Backslashes in path. (Non-standard zip archive)" )
) );
modValid = false;
innerPath = innerPath.replace( '\\', '/' );
}
if ( !asciiEncoder.canEncode( innerPath ) ) {
pendingMsgs.add( new ReportMessage(
ReportMessage.ERROR,
@ -379,9 +388,10 @@ public class ModUtilities {
}
if ( !pendingMsgs.isEmpty() ) {
// Prepend the original path.
messages.add( new ReportMessage(
ReportMessage.SUBSECTION,
innerPath
item.getName()
) );
messages.addAll( pendingMsgs );
}