Do not use Apache ZipFile as it fails to read some ZIPs created under special conditions (java.util.ZipFile works)
This commit is contained in:
@@ -4,7 +4,6 @@ import eu.crushedpixel.replaymod.ReplayMod;
|
|||||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||||
import eu.crushedpixel.replaymod.utils.ReplayFile;
|
import eu.crushedpixel.replaymod.utils.ReplayFile;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
|
||||||
@@ -13,6 +12,7 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
@EqualsAndHashCode
|
@EqualsAndHashCode
|
||||||
public class AssetRepository {
|
public class AssetRepository {
|
||||||
@@ -65,9 +65,9 @@ public class AssetRepository {
|
|||||||
try {
|
try {
|
||||||
ReplayFile replayFile = new ReplayFile(ReplayHandler.getReplayFile());
|
ReplayFile replayFile = new ReplayFile(ReplayHandler.getReplayFile());
|
||||||
|
|
||||||
Enumeration<ZipArchiveEntry> entries = replayFile.getEntries();
|
Enumeration<? extends ZipEntry> entries = replayFile.entries();
|
||||||
while(entries.hasMoreElements()) {
|
while(entries.hasMoreElements()) {
|
||||||
ZipArchiveEntry entry = entries.nextElement();
|
ZipEntry entry = entries.nextElement();
|
||||||
if(entry.getName().startsWith(ReplayFile.ENTRY_ASSET_FOLDER)) {
|
if(entry.getName().startsWith(ReplayFile.ENTRY_ASSET_FOLDER)) {
|
||||||
ReplayMod.replayFileAppender.registerModifiedFile(null, entry.getName(), ReplayHandler.getReplayFile());
|
ReplayMod.replayFileAppender.registerModifiedFile(null, entry.getName(), ReplayHandler.getReplayFile());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,14 +12,14 @@ import eu.crushedpixel.replaymod.holders.KeyframeSet;
|
|||||||
import eu.crushedpixel.replaymod.holders.Marker;
|
import eu.crushedpixel.replaymod.holders.Marker;
|
||||||
import eu.crushedpixel.replaymod.holders.PlayerVisibility;
|
import eu.crushedpixel.replaymod.holders.PlayerVisibility;
|
||||||
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
||||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
|
||||||
import org.apache.commons.compress.archivers.zip.ZipFile;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
public class ReplayFile extends ZipFile {
|
public class ReplayFile extends ZipFile {
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZipArchiveEntry recordingEntry() {
|
public ZipEntry recordingEntry() {
|
||||||
return getEntry(ENTRY_RECORDING);
|
return getEntry(ENTRY_RECORDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZipArchiveEntry metadataEntry() {
|
public ZipEntry metadataEntry() {
|
||||||
return getEntry(ENTRY_METADATA);
|
return getEntry(ENTRY_METADATA);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,8 +84,8 @@ public class ReplayFile extends ZipFile {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZipArchiveEntry pathsEntry() {
|
public ZipEntry pathsEntry() {
|
||||||
ZipArchiveEntry newEntry = getEntry(ENTRY_PATHS);
|
ZipEntry newEntry = getEntry(ENTRY_PATHS);
|
||||||
return newEntry != null ? newEntry : getEntry(ENTRY_PATHS_OLD);
|
return newEntry != null ? newEntry : getEntry(ENTRY_PATHS_OLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
@Override
|
@Override
|
||||||
public KeyframeSet[] get() {
|
public KeyframeSet[] get() {
|
||||||
try {
|
try {
|
||||||
ZipArchiveEntry entry = pathsEntry();
|
ZipEntry entry = pathsEntry();
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -111,8 +111,8 @@ public class ReplayFile extends ZipFile {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZipArchiveEntry visibilityEntry() {
|
public ZipEntry visibilityEntry() {
|
||||||
ZipArchiveEntry newEntry = getEntry(ENTRY_VISIBILITY);
|
ZipEntry newEntry = getEntry(ENTRY_VISIBILITY);
|
||||||
return newEntry != null ? newEntry : getEntry(ENTRY_VISIBILITY_OLD);
|
return newEntry != null ? newEntry : getEntry(ENTRY_VISIBILITY_OLD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
@Override
|
@Override
|
||||||
public PlayerVisibility get() {
|
public PlayerVisibility get() {
|
||||||
try {
|
try {
|
||||||
ZipArchiveEntry entry = visibilityEntry();
|
ZipEntry entry = visibilityEntry();
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -134,7 +134,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZipArchiveEntry markersEntry() {
|
public ZipEntry markersEntry() {
|
||||||
return getEntry(ENTRY_MARKERS);
|
return getEntry(ENTRY_MARKERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
@Override
|
@Override
|
||||||
public List<Keyframe<Marker>> get() {
|
public List<Keyframe<Marker>> get() {
|
||||||
try {
|
try {
|
||||||
ZipArchiveEntry entry = markersEntry();
|
ZipEntry entry = markersEntry();
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -159,7 +159,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZipArchiveEntry thumbEntry() {
|
public ZipEntry thumbEntry() {
|
||||||
return getEntry(ENTRY_THUMB);
|
return getEntry(ENTRY_THUMB);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
@Override
|
@Override
|
||||||
public BufferedImage get() {
|
public BufferedImage get() {
|
||||||
try {
|
try {
|
||||||
ZipArchiveEntry entry = thumbEntry();
|
ZipEntry entry = thumbEntry();
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -185,7 +185,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZipArchiveEntry resourcePackIndexEntry() {
|
public ZipEntry resourcePackIndexEntry() {
|
||||||
return getEntry(ENTRY_RESOURCE_PACK_INDEX);
|
return getEntry(ENTRY_RESOURCE_PACK_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public Map<Integer, String> get() {
|
public Map<Integer, String> get() {
|
||||||
try {
|
try {
|
||||||
ZipArchiveEntry entry = resourcePackIndexEntry();
|
ZipEntry entry = resourcePackIndexEntry();
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZipArchiveEntry resourcePackEntry(String hash) {
|
public ZipEntry resourcePackEntry(String hash) {
|
||||||
return getEntry(String.format(ENTRY_RESOURCE_PACK, hash));
|
return getEntry(String.format(ENTRY_RESOURCE_PACK, hash));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ public class ReplayFile extends ZipFile {
|
|||||||
@Override
|
@Override
|
||||||
public InputStream get() {
|
public InputStream get() {
|
||||||
try {
|
try {
|
||||||
ZipArchiveEntry entry = resourcePackEntry(hash);
|
ZipEntry entry = resourcePackEntry(hash);
|
||||||
if (entry == null) {
|
if (entry == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -240,12 +240,12 @@ public class ReplayFile extends ZipFile {
|
|||||||
public AssetRepository get() {
|
public AssetRepository get() {
|
||||||
AssetRepository assetRepository = new AssetRepository();
|
AssetRepository assetRepository = new AssetRepository();
|
||||||
|
|
||||||
Enumeration<ZipArchiveEntry> entries = getEntries();
|
Enumeration<? extends ZipEntry> entries = entries();
|
||||||
|
|
||||||
while(entries.hasMoreElements()) {
|
while(entries.hasMoreElements()) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ZipArchiveEntry entry = entries.nextElement();
|
ZipEntry entry = entries.nextElement();
|
||||||
|
|
||||||
String entryName = entry.getName();
|
String entryName = entry.getName();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user