From 845d9f253d7505befde5e83fb3e25969e1c6b4ac Mon Sep 17 00:00:00 2001 From: Konloch Date: Sun, 11 Jul 2021 01:50:12 -0700 Subject: [PATCH] Preserve File Order --- .../importing/impl/DirectoryResourceImporter.java | 5 +++-- .../importing/impl/XAPKResourceImporter.java | 3 ++- .../club/bytecodeviewer/util/JarUtils.java | 15 ++++++--------- .../bytecodeviewer/util/ResourceContainer.java | 7 ++++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java index c5185a12..a9ae148f 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/DirectoryResourceImporter.java @@ -14,6 +14,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Objects; /** @@ -26,8 +27,8 @@ public class DirectoryResourceImporter implements Importer public void open(File file) throws Exception { ResourceContainer container = new ResourceContainer(file); - HashMap allDirectoryFiles = new HashMap<>(); - HashMap allDirectoryClasses = new HashMap<>(); + LinkedHashMap allDirectoryFiles = new LinkedHashMap<>(); + LinkedHashMap allDirectoryClasses = new LinkedHashMap<>(); boolean finished = false; ArrayList totalFiles = new ArrayList<>(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java index 5d65b8a6..dee38aeb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/resources/importing/impl/XAPKResourceImporter.java @@ -12,6 +12,7 @@ import the.bytecode.club.bytecodeviewer.util.MiscUtils; import java.io.*; import java.util.Enumeration; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -30,7 +31,7 @@ public class XAPKResourceImporter implements Importer public void open(File file) throws Exception { ResourceContainer container = new ResourceContainer(file); - HashMap allDirectoryFiles = new HashMap<>(); + LinkedHashMap allDirectoryFiles = new LinkedHashMap<>(); Configuration.silenceExceptionGUI++; //turn exceptions off try (ZipFile zipFile = new ZipFile(file)) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java index a306effe..03e4fc17 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java @@ -5,10 +5,7 @@ import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; +import java.util.*; import java.util.Map.Entry; import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; @@ -67,7 +64,7 @@ public class JarUtils public static void importArchiveA(final File jarFile) throws IOException { ResourceContainer container = new ResourceContainer(jarFile); - HashMap files = new HashMap<>(); + LinkedHashMap files = new LinkedHashMap<>(); ZipInputStream jis = new ZipInputStream(new FileInputStream(jarFile)); ZipEntry entry; @@ -121,7 +118,7 @@ public class JarUtils // should also rebuild the archive byte offsets ResourceContainer container = new ResourceContainer(jarFile); - HashMap files = new HashMap<>(); + LinkedHashMap files = new LinkedHashMap<>(); try (ZipFile zipFile = new ZipFile(jarFile)) { Enumeration entries = zipFile.getEntries(); @@ -196,11 +193,11 @@ public class JarUtils * @param zipFile the input zip file * @throws IOException */ - public static HashMap loadResources(final File zipFile) throws IOException { + public static LinkedHashMap loadResources(final File zipFile) throws IOException { if (!zipFile.exists()) return null; //just ignore - - HashMap files = new HashMap<>(); + + LinkedHashMap files = new LinkedHashMap<>(); ZipInputStream jis = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry entry; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/util/ResourceContainer.java b/src/main/java/the/bytecode/club/bytecodeviewer/util/ResourceContainer.java index ff1137b2..05019c83 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/util/ResourceContainer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/util/ResourceContainer.java @@ -3,6 +3,7 @@ package the.bytecode.club.bytecodeviewer.util; import java.io.File; import java.util.ArrayList; import java.util.HashMap; +import java.util.LinkedHashMap; import org.apache.commons.io.FilenameUtils; import org.objectweb.asm.tree.ClassNode; @@ -38,9 +39,9 @@ public class ResourceContainer public String name; public File APKToolContents = null; - public HashMap resourceFiles = new HashMap<>(); - public HashMap resourceClassBytes = new HashMap<>(); - public HashMap resourceClasses = new HashMap<>(); + public LinkedHashMap resourceFiles = new LinkedHashMap<>(); + public LinkedHashMap resourceClassBytes = new LinkedHashMap<>(); + public LinkedHashMap resourceClasses = new LinkedHashMap<>(); public ResourceContainer(File f) {