diff options
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java index a3b0616e..ba0720a0 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java | |||
| @@ -30,10 +30,23 @@ public class MappingsEnigmaWriter { | |||
| 30 | writeAsDirectory(out, mappings); | 30 | writeAsDirectory(out, mappings); |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | private void deleteDir(File file) { | ||
| 34 | File[] contents = file.listFiles(); | ||
| 35 | if (contents != null) { | ||
| 36 | for (File f : contents) { | ||
| 37 | deleteDir(f); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | file.delete(); | ||
| 41 | } | ||
| 42 | |||
| 33 | public void writeAsDirectory(File target, Mappings mappings) throws IOException { | 43 | public void writeAsDirectory(File target, Mappings mappings) throws IOException { |
| 44 | //TODO: Know what have changes during write to not rewrite all the things | ||
| 45 | deleteDir(target); | ||
| 34 | if (!target.exists() && !target.mkdirs()) | 46 | if (!target.exists() && !target.mkdirs()) |
| 35 | throw new IOException("Cannot create mapping directory!"); | 47 | throw new IOException("Cannot create mapping directory!"); |
| 36 | 48 | ||
| 49 | |||
| 37 | for (ClassMapping classMapping : sorted(mappings.classes())) { | 50 | for (ClassMapping classMapping : sorted(mappings.classes())) { |
| 38 | File obFile = new File(target, classMapping.getObfFullName() + ".mapping"); | 51 | File obFile = new File(target, classMapping.getObfFullName() + ".mapping"); |
| 39 | File result; | 52 | File result; |
| @@ -55,21 +68,6 @@ public class MappingsEnigmaWriter { | |||
| 55 | outputWriter.close(); | 68 | outputWriter.close(); |
| 56 | } | 69 | } |
| 57 | 70 | ||
| 58 | // Remove empty directories | ||
| 59 | File[] fileList = target.listFiles(); | ||
| 60 | if (fileList != null) | ||
| 61 | { | ||
| 62 | for (File file : fileList) | ||
| 63 | { | ||
| 64 | if (file.isDirectory()) | ||
| 65 | { | ||
| 66 | File[] childFiles = file.listFiles(); | ||
| 67 | if (childFiles != null && childFiles.length == 0) | ||
| 68 | file.delete(); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | } | 71 | } |
| 74 | 72 | ||
| 75 | public void write(PrintWriter out, Mappings mappings) throws IOException { | 73 | public void write(PrintWriter out, Mappings mappings) throws IOException { |