|
4 | 4 | import me.coley.recaf.plugin.PluginsManager;
|
5 | 5 | import me.coley.recaf.plugin.api.ExportInterceptorPlugin;
|
6 | 6 | import me.coley.recaf.util.IOUtil;
|
| 7 | +import me.coley.recaf.util.Log; |
7 | 8 | import me.coley.recaf.workspace.ClassResource;
|
8 | 9 | import me.coley.recaf.workspace.DirectoryResource;
|
9 | 10 | import me.coley.recaf.workspace.JavaResource;
|
|
16 | 17 | import java.io.File;
|
17 | 18 | import java.io.IOException;
|
18 | 19 | import java.io.OutputStream;
|
| 20 | +import java.lang.reflect.Field; |
19 | 21 | import java.nio.file.Files;
|
20 | 22 | import java.nio.file.Path;
|
21 | 23 | import java.nio.file.Paths;
|
@@ -141,6 +143,13 @@ public static void writeArchive(boolean compress, File output, Map<String, byte[
|
141 | 143 | OutputStream os = new BufferedOutputStream(Files.newOutputStream(output.toPath()), 1048576);
|
142 | 144 | try (ZipOutputStream jos = ("zip".equals(extension)) ? new ZipOutputStream(os) :
|
143 | 145 | /* Let's assume it's a jar */ new JarOutputStream(os)) {
|
| 146 | + try { |
| 147 | + Field field = ZipOutputStream.class.getDeclaredField("names"); |
| 148 | + field.setAccessible(true); |
| 149 | + field.set(jos, new DiscardingSet()); |
| 150 | + } catch (NoSuchFieldException | IllegalAccessException ex) { |
| 151 | + Log.error(ex, "Could not replace ZIP names"); |
| 152 | + } |
144 | 153 | PluginsManager pluginsManager = PluginsManager.getInstance();
|
145 | 154 | Set<String> dirsVisited = new HashSet<>();
|
146 | 155 | // Contents is iterated in sorted order (because 'archiveContent' is TreeMap).
|
@@ -197,4 +206,20 @@ private void put(Map<String, byte[]> content, JavaResource res) {
|
197 | 206 | content.put(name, e.getValue());
|
198 | 207 | }
|
199 | 208 | }
|
| 209 | + |
| 210 | + /** |
| 211 | + * A set that discards it's elements upon adding. |
| 212 | + * |
| 213 | + * This class is used to prevent "Duplcicate zip entry: " |
| 214 | + * error |
| 215 | + * |
| 216 | + * @author xDark |
| 217 | + */ |
| 218 | + private static final class DiscardingSet extends HashSet<String> { |
| 219 | + |
| 220 | + @Override |
| 221 | + public boolean add(String s) { |
| 222 | + return true; |
| 223 | + } |
| 224 | + } |
200 | 225 | }
|
0 commit comments