From 6238a6826e09f2c2b7d248a39881a9c6e4b63c51 Mon Sep 17 00:00:00 2001 From: Lemon-King Date: Sun, 15 Oct 2023 16:29:03 -0400 Subject: [PATCH] ZipAssets: Fix how zipped data is accessed to prevent read errors --- .../java/lemon/hxdd/builder/ZipAssets.java | 38 ++++++------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/src/main/java/lemon/hxdd/builder/ZipAssets.java b/src/main/java/lemon/hxdd/builder/ZipAssets.java index 958c29a..d4551f2 100644 --- a/src/main/java/lemon/hxdd/builder/ZipAssets.java +++ b/src/main/java/lemon/hxdd/builder/ZipAssets.java @@ -250,18 +250,13 @@ void ExtractFilesFromFolderAndConvert(String input, String output, String[] limi String fileName = entry.getName(); String cleanedName = fileName.startsWith(input) ? fileName.substring(input.length()) : fileName; - if (limitedFiles != null && limitedFiles.length > 0) { - if (!Arrays.asList(limitedFiles).contains(cleanedName)) { - return; - } - } try { if (fileName.contains(".lmp")) { - String npath = path + "/" + output + "/" + cleanedName.replace("lmp", "png"); + String pathOutput = path + "/" + output + "/" + cleanedName.replace("lmp", "png"); if (dims != null) { - ExportGraphic(npath, this.zis, finalPal, dims); + ExportGraphic(pathOutput, this.zis.readAllBytes(), finalPal, dims); } else { - Export(npath, this.zis, finalPal, dims); + Export(pathOutput, this.zis.readAllBytes(), finalPal, dims); } } else { try { @@ -284,12 +279,12 @@ void ExtractFilesFromFolderAndConvert(String input, String output, String[] limi this.Close(); } - private void Export(String path, InputStream in, Palette pal, int[] dimensions) { + private void Export(String path, byte [] data, Palette pal, int[] dimensions) { try { File fileOutput = new File(path); Picture p = new Picture(); - byte[] bytesGraphic = GetBytesFromInputStream(in); + byte[] bytesGraphic = data; p.fromBytes(bytesGraphic); if (dimensions != null) { p.setDimensions(dimensions[0], dimensions[1]); @@ -304,31 +299,22 @@ private void Export(String path, InputStream in, Palette pal, int[] dimensions) } pngImg.writeBytes(new FileOutputStream(fileOutput, false)); } catch (IOException e) { - e.printStackTrace(); + System.out.println("ZipAssets.Export: Failed to export " + path); } } - private void ExportGraphic(String path, InputStream in, Palette pal, int[] dimensions) { + private void ExportGraphic(String path, byte [] data, Palette pal, int[] dimensions) { try { File target = new File(path); - BufferedImage image = null; + Picture p = new Picture(); + p.setDimensions(dimensions[0], dimensions[1]); + p.fromBytes(data); + BufferedImage image = GraphicUtils.createImage(p, pal); - boolean AsFlat = false; - if (AsFlat) { - // Results in corrupted data: https://github.com/MTrop/DoomStruct/issues/17#issuecomment-1603050005 - Flat f = Flat.read(dimensions[0], dimensions[1], in); - image = GraphicUtils.createImage(f, pal); - } else { - Picture p = new Picture(); - p.setDimensions(dimensions[0], dimensions[1]); - p.readBytes(in); - image = GraphicUtils.createImage(p, pal); - } ImageIO.write(image, "PNG", target); - //System.out.println("Wrote " + path); } catch (IOException e) { - e.printStackTrace(); + System.out.println("ZipAssets.ExportGraphic: Failed to export " + path + "\n" + e); } }