diff options
| author | 2018-07-05 12:33:05 +0200 | |
|---|---|---|
| committer | 2018-07-05 12:33:05 +0200 | |
| commit | 7d88f12b8a39aa6d6489109a03b32a4b7a995d9a (patch) | |
| tree | 8c9a5e57a29fa22cd79bf29bf79a9fac733d0b9f /src | |
| parent | Use previous save state to delete old mapping files (diff) | |
| download | enigma-7d88f12b8a39aa6d6489109a03b32a4b7a995d9a.tar.gz enigma-7d88f12b8a39aa6d6489109a03b32a4b7a995d9a.tar.xz enigma-7d88f12b8a39aa6d6489109a03b32a4b7a995d9a.zip | |
Fix old mappings not properly being removed
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/Mappings.java | 4 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java | 23 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/Mappings.java b/src/main/java/cuchaz/enigma/mapping/Mappings.java index 79d9f104..307b1bd4 100644 --- a/src/main/java/cuchaz/enigma/mapping/Mappings.java +++ b/src/main/java/cuchaz/enigma/mapping/Mappings.java | |||
| @@ -47,6 +47,10 @@ public class Mappings { | |||
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | public void addClassMapping(ClassMapping classMapping) throws MappingConflict { | 49 | public void addClassMapping(ClassMapping classMapping) throws MappingConflict { |
| 50 | if (classMapping.isObfuscated()) { | ||
| 51 | return; | ||
| 52 | } | ||
| 53 | |||
| 50 | if (this.classesByObf.containsKey(classMapping.getObfFullName())) { | 54 | if (this.classesByObf.containsKey(classMapping.getObfFullName())) { |
| 51 | throw new MappingConflict("class", classMapping.getObfFullName(), this.classesByObf.get(classMapping.getObfFullName()).getObfFullName()); | 55 | throw new MappingConflict("class", classMapping.getObfFullName(), this.classesByObf.get(classMapping.getObfFullName()).getObfFullName()); |
| 52 | } | 56 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java index 231893d5..1e1c4ddc 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java | |||
| @@ -39,11 +39,14 @@ public class MappingsEnigmaWriter { | |||
| 39 | 39 | ||
| 40 | if (previousState != null) { | 40 | if (previousState != null) { |
| 41 | ClassMapping previousClass = previousState.classesByObf.get(classMapping.getObfFullName()); | 41 | ClassMapping previousClass = previousState.classesByObf.get(classMapping.getObfFullName()); |
| 42 | File previousFile; | ||
| 42 | if (previousClass != null) { | 43 | if (previousClass != null) { |
| 43 | File previousFile = new File(target, previousClass.getSaveName() + ".mapping"); | 44 | previousFile = new File(target, previousClass.getSaveName() + ".mapping"); |
| 44 | if (previousFile.exists() && !previousFile.delete()) { | 45 | } else { |
| 45 | System.err.println("Failed to delete old class mapping " + previousFile.getName()); | 46 | previousFile = new File(target, classMapping.getObfFullName() + ".mapping"); |
| 46 | } | 47 | } |
| 48 | if (previousFile.exists() && !previousFile.delete()) { | ||
| 49 | System.err.println("Failed to delete old class mapping " + previousFile.getName()); | ||
| 47 | } | 50 | } |
| 48 | } | 51 | } |
| 49 | 52 | ||
| @@ -85,10 +88,10 @@ public class MappingsEnigmaWriter { | |||
| 85 | private void write(PrintWriter out, ClassMapping classMapping, int depth) throws IOException { | 88 | private void write(PrintWriter out, ClassMapping classMapping, int depth) throws IOException { |
| 86 | if (classMapping.getDeobfName() == null) { | 89 | if (classMapping.getDeobfName() == null) { |
| 87 | out.format("%sCLASS %s%s\n", getIndent(depth), classMapping.getObfFullName(), | 90 | out.format("%sCLASS %s%s\n", getIndent(depth), classMapping.getObfFullName(), |
| 88 | classMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : classMapping.getModifier().getFormattedName()); | 91 | classMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : classMapping.getModifier().getFormattedName()); |
| 89 | } else { | 92 | } else { |
| 90 | out.format("%sCLASS %s %s%s\n", getIndent(depth), classMapping.getObfFullName(), classMapping.getDeobfName(), | 93 | out.format("%sCLASS %s %s%s\n", getIndent(depth), classMapping.getObfFullName(), classMapping.getDeobfName(), |
| 91 | classMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : classMapping.getModifier().getFormattedName()); | 94 | classMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : classMapping.getModifier().getFormattedName()); |
| 92 | } | 95 | } |
| 93 | 96 | ||
| 94 | for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { | 97 | for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { |
| @@ -107,19 +110,19 @@ public class MappingsEnigmaWriter { | |||
| 107 | private void write(PrintWriter out, FieldMapping fieldMapping, int depth) { | 110 | private void write(PrintWriter out, FieldMapping fieldMapping, int depth) { |
| 108 | if (fieldMapping.getDeobfName() == null) | 111 | if (fieldMapping.getDeobfName() == null) |
| 109 | out.format("%sFIELD %s %s%s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getObfDesc().toString(), | 112 | out.format("%sFIELD %s %s%s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getObfDesc().toString(), |
| 110 | fieldMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : fieldMapping.getModifier().getFormattedName()); | 113 | fieldMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : fieldMapping.getModifier().getFormattedName()); |
| 111 | else | 114 | else |
| 112 | out.format("%sFIELD %s %s %s%s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getDeobfName(), fieldMapping.getObfDesc().toString(), | 115 | out.format("%sFIELD %s %s %s%s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getDeobfName(), fieldMapping.getObfDesc().toString(), |
| 113 | fieldMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : fieldMapping.getModifier().getFormattedName()); | 116 | fieldMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : fieldMapping.getModifier().getFormattedName()); |
| 114 | } | 117 | } |
| 115 | 118 | ||
| 116 | private void write(PrintWriter out, MethodMapping methodMapping, int depth) throws IOException { | 119 | private void write(PrintWriter out, MethodMapping methodMapping, int depth) throws IOException { |
| 117 | if (methodMapping.isObfuscated()) { | 120 | if (methodMapping.isObfuscated()) { |
| 118 | out.format("%sMETHOD %s %s%s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getObfDesc(), | 121 | out.format("%sMETHOD %s %s%s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getObfDesc(), |
| 119 | methodMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : methodMapping.getModifier().getFormattedName()); | 122 | methodMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : methodMapping.getModifier().getFormattedName()); |
| 120 | } else { | 123 | } else { |
| 121 | out.format("%sMETHOD %s %s %s%s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getDeobfName(), methodMapping.getObfDesc(), | 124 | out.format("%sMETHOD %s %s %s%s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getDeobfName(), methodMapping.getObfDesc(), |
| 122 | methodMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : methodMapping.getModifier().getFormattedName()); | 125 | methodMapping.getModifier() == Mappings.EntryModifier.UNCHANGED ? "" : methodMapping.getModifier().getFormattedName()); |
| 123 | } | 126 | } |
| 124 | 127 | ||
| 125 | for (LocalVariableMapping localVariableMapping : sorted(methodMapping.arguments())) { | 128 | for (LocalVariableMapping localVariableMapping : sorted(methodMapping.arguments())) { |