diff options
| author | 2018-07-05 09:08:45 +0200 | |
|---|---|---|
| committer | 2018-07-05 09:08:45 +0200 | |
| commit | 5b813c2ae4bbf5c7e1733b45d0d52db85060e0dd (patch) | |
| tree | 906ec9cb9e4cc8846f396c2a6a7874df40293c92 /src | |
| parent | Merge pull request #5 from thiakil/param-annotation-fix (diff) | |
| download | enigma-5b813c2ae4bbf5c7e1733b45d0d52db85060e0dd.tar.gz enigma-5b813c2ae4bbf5c7e1733b45d0d52db85060e0dd.tar.xz enigma-5b813c2ae4bbf5c7e1733b45d0d52db85060e0dd.zip | |
Use previous save state to delete old mapping files
Diffstat (limited to 'src')
3 files changed, 54 insertions, 54 deletions
diff --git a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java index 4e60e87d..0141b45e 100644 --- a/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java +++ b/src/main/java/cuchaz/enigma/bytecode/translators/TranslationMethodVisitor.java | |||
| @@ -178,6 +178,9 @@ public class TranslationMethodVisitor extends MethodVisitor { | |||
| 178 | String typeName = desc.getTypeEntry().getSimpleName().replace("$", ""); | 178 | String typeName = desc.getTypeEntry().getSimpleName().replace("$", ""); |
| 179 | typeName = typeName.substring(0, 1).toUpperCase(Locale.ROOT) + typeName.substring(1); | 179 | typeName = typeName.substring(0, 1).toUpperCase(Locale.ROOT) + typeName.substring(1); |
| 180 | nameBuilder.append(typeName); | 180 | nameBuilder.append(typeName); |
| 181 | } else { | ||
| 182 | System.err.println("Encountered invalid argument type descriptor " + desc.toString()); | ||
| 183 | nameBuilder.append("Unk"); | ||
| 181 | } | 184 | } |
| 182 | if (!argument || methodEntry.getDesc().getArgumentDescs().size() > 1) { | 185 | if (!argument || methodEntry.getDesc().getArgumentDescs().size() > 1) { |
| 183 | nameBuilder.append(nameIndex); | 186 | nameBuilder.append(nameIndex); |
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index 1e6c3a19..be9e7416 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -517,6 +517,14 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 517 | return deobfFullName != null ? new ClassEntry(deobfFullName) : null; | 517 | return deobfFullName != null ? new ClassEntry(deobfFullName) : null; |
| 518 | } | 518 | } |
| 519 | 519 | ||
| 520 | public boolean isObfuscated() { | ||
| 521 | return this.deobfName == null || this.deobfName.equals(this.obfFullName); | ||
| 522 | } | ||
| 523 | |||
| 524 | public String getSaveName() { | ||
| 525 | return this.isObfuscated() ? this.obfFullName : this.deobfName; | ||
| 526 | } | ||
| 527 | |||
| 520 | public boolean isDirty() { | 528 | public boolean isDirty() { |
| 521 | return isDirty; | 529 | return isDirty; |
| 522 | } | 530 | } |
| @@ -564,4 +572,14 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 564 | this.deobfFullName = deobName; | 572 | this.deobfFullName = deobName; |
| 565 | return this; | 573 | return this; |
| 566 | } | 574 | } |
| 575 | |||
| 576 | @Override | ||
| 577 | public int hashCode() { | ||
| 578 | return this.obfFullName.hashCode(); | ||
| 579 | } | ||
| 580 | |||
| 581 | @Override | ||
| 582 | public boolean equals(Object obj) { | ||
| 583 | return obj instanceof ClassMapping && ((ClassMapping) obj).obfFullName.equals(this.obfFullName); | ||
| 584 | } | ||
| 567 | } | 585 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java index 4e29a465..231893d5 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java | |||
| @@ -14,9 +14,7 @@ package cuchaz.enigma.mapping; | |||
| 14 | import com.google.common.base.Charsets; | 14 | import com.google.common.base.Charsets; |
| 15 | 15 | ||
| 16 | import java.io.*; | 16 | import java.io.*; |
| 17 | import java.util.ArrayList; | 17 | import java.util.*; |
| 18 | import java.util.Collections; | ||
| 19 | import java.util.List; | ||
| 20 | 18 | ||
| 21 | public class MappingsEnigmaWriter { | 19 | public class MappingsEnigmaWriter { |
| 22 | 20 | ||
| @@ -33,70 +31,51 @@ public class MappingsEnigmaWriter { | |||
| 33 | if (!target.exists() && !target.mkdirs()) | 31 | if (!target.exists() && !target.mkdirs()) |
| 34 | throw new IOException("Cannot create mapping directory!"); | 32 | throw new IOException("Cannot create mapping directory!"); |
| 35 | 33 | ||
| 34 | Mappings previousState = mappings.getPreviousState(); | ||
| 36 | for (ClassMapping classMapping : sorted(mappings.classes())) { | 35 | for (ClassMapping classMapping : sorted(mappings.classes())) { |
| 37 | if (!classMapping.isDirty()) | 36 | if (!classMapping.isDirty()) { |
| 38 | continue; | 37 | continue; |
| 39 | this.deletePreviousClassMapping(target, classMapping); | ||
| 40 | File obFile = new File(target, classMapping.getObfFullName() + ".mapping"); | ||
| 41 | File result; | ||
| 42 | if (classMapping.getDeobfName() == null) | ||
| 43 | result = obFile; | ||
| 44 | else { | ||
| 45 | // Make sure that old version of the file doesn't exist | ||
| 46 | if (obFile.exists()) | ||
| 47 | obFile.delete(); | ||
| 48 | result = new File(target, classMapping.getDeobfName() + ".mapping"); | ||
| 49 | } | 38 | } |
| 50 | 39 | ||
| 51 | if (!result.getParentFile().exists()) | 40 | if (previousState != null) { |
| 52 | result.getParentFile().mkdirs(); | 41 | ClassMapping previousClass = previousState.classesByObf.get(classMapping.getObfFullName()); |
| 42 | if (previousClass != null) { | ||
| 43 | File previousFile = new File(target, previousClass.getSaveName() + ".mapping"); | ||
| 44 | if (previousFile.exists() && !previousFile.delete()) { | ||
| 45 | System.err.println("Failed to delete old class mapping " + previousFile.getName()); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | File result = new File(target, classMapping.getSaveName() + ".mapping"); | ||
| 51 | |||
| 52 | File packageFile = result.getParentFile(); | ||
| 53 | if (!packageFile.exists()) { | ||
| 54 | packageFile.mkdirs(); | ||
| 55 | } | ||
| 53 | result.createNewFile(); | 56 | result.createNewFile(); |
| 54 | PrintWriter outputWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(result), Charsets.UTF_8)); | 57 | |
| 55 | write(outputWriter, classMapping, 0); | 58 | try (PrintWriter outputWriter = new PrintWriter(new BufferedWriter(new FileWriter(result)))) { |
| 56 | outputWriter.close(); | 59 | write(outputWriter, classMapping, 0); |
| 60 | } | ||
| 57 | } | 61 | } |
| 58 | 62 | ||
| 59 | // Remove dropped mappings | 63 | // Remove dropped mappings |
| 60 | if (mappings.getPreviousState() != null) { | 64 | if (previousState != null) { |
| 61 | List<ClassMapping> droppedClassMappings = new ArrayList<>(mappings.getPreviousState().classes()); | 65 | Set<ClassMapping> droppedClassMappings = new HashSet<>(previousState.classes()); |
| 62 | List<ClassMapping> classMappings = new ArrayList<>(mappings.classes()); | 66 | droppedClassMappings.removeAll(mappings.classes()); |
| 63 | droppedClassMappings.removeAll(classMappings); | 67 | for (ClassMapping droppedMapping : droppedClassMappings) { |
| 64 | for (ClassMapping classMapping : droppedClassMappings) { | 68 | File result = new File(target, droppedMapping.getSaveName() + ".mapping"); |
| 65 | File obFile = new File(target, classMapping.getObfFullName() + ".mapping"); | 69 | if (!result.exists()) { |
| 66 | File result; | 70 | continue; |
| 67 | if (classMapping.getDeobfName() == null) | 71 | } |
| 68 | result = obFile; | 72 | if (!result.delete()) { |
| 69 | else { | 73 | System.err.println("Failed to delete dropped class mapping " + result.getName()); |
| 70 | // Make sure that old version of the file doesn't exist | ||
| 71 | if (obFile.exists()) | ||
| 72 | obFile.delete(); | ||
| 73 | result = new File(target, classMapping.getDeobfName() + ".mapping"); | ||
| 74 | } | 74 | } |
| 75 | if (result.exists()) | ||
| 76 | result.delete(); | ||
| 77 | } | 75 | } |
| 78 | } | 76 | } |
| 79 | } | 77 | } |
| 80 | 78 | ||
| 81 | private void deletePreviousClassMapping(File target, ClassMapping classMapping) { | ||
| 82 | File prevFile = null; | ||
| 83 | // Deob rename | ||
| 84 | if (classMapping.getDeobfName() != null && classMapping.getPreviousDeobfName() != null && !classMapping.getPreviousDeobfName().equals(classMapping.getDeobfName())) { | ||
| 85 | prevFile = new File(target, classMapping.getPreviousDeobfName() + ".mapping"); | ||
| 86 | } | ||
| 87 | // Deob to ob rename | ||
| 88 | else if (classMapping.getDeobfName() == null && classMapping.getPreviousDeobfName() != null) { | ||
| 89 | prevFile = new File(target, classMapping.getPreviousDeobfName() + ".mapping"); | ||
| 90 | } | ||
| 91 | // Ob to Deob rename | ||
| 92 | else if (classMapping.getDeobfName() != null && classMapping.getPreviousDeobfName() == null) { | ||
| 93 | prevFile = new File(target, classMapping.getObfFullName() + ".mapping"); | ||
| 94 | } | ||
| 95 | |||
| 96 | if (prevFile != null && prevFile.exists()) | ||
| 97 | prevFile.delete(); | ||
| 98 | } | ||
| 99 | |||
| 100 | public void write(PrintWriter out, Mappings mappings) throws IOException { | 79 | public void write(PrintWriter out, Mappings mappings) throws IOException { |
| 101 | for (ClassMapping classMapping : sorted(mappings.classes())) { | 80 | for (ClassMapping classMapping : sorted(mappings.classes())) { |
| 102 | write(out, classMapping, 0); | 81 | write(out, classMapping, 0); |