diff options
| author | 2016-10-26 17:34:06 +0200 | |
|---|---|---|
| committer | 2016-10-26 17:34:06 +0200 | |
| commit | e0f001acce44277a1e4eb0ccf79b801aa25ed216 (patch) | |
| tree | 37577a7ffbc39a3b3a49acec63820fbfce5145f5 | |
| parent | Starting implementing local variables (#33) (diff) | |
| download | enigma-e0f001acce44277a1e4eb0ccf79b801aa25ed216.tar.gz enigma-e0f001acce44277a1e4eb0ccf79b801aa25ed216.tar.xz enigma-e0f001acce44277a1e4eb0ccf79b801aa25ed216.zip | |
Rework saving system to improve saving time (Fix #35)
4 files changed, 100 insertions, 15 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index 36b35f73..923c8ece 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -22,12 +22,14 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 22 | private String m_obfFullName; | 22 | private String m_obfFullName; |
| 23 | private String m_obfSimpleName; | 23 | private String m_obfSimpleName; |
| 24 | private String m_deobfName; | 24 | private String m_deobfName; |
| 25 | private String m_previousDeobfName; | ||
| 25 | private Map<String, ClassMapping> m_innerClassesByObfSimple; | 26 | private Map<String, ClassMapping> m_innerClassesByObfSimple; |
| 26 | private Map<String, ClassMapping> m_innerClassesByDeobf; | 27 | private Map<String, ClassMapping> m_innerClassesByDeobf; |
| 27 | private Map<String, FieldMapping> m_fieldsByObf; | 28 | private Map<String, FieldMapping> m_fieldsByObf; |
| 28 | private Map<String, FieldMapping> m_fieldsByDeobf; | 29 | private Map<String, FieldMapping> m_fieldsByDeobf; |
| 29 | private Map<String, MethodMapping> m_methodsByObf; | 30 | private Map<String, MethodMapping> m_methodsByObf; |
| 30 | private Map<String, MethodMapping> m_methodsByDeobf; | 31 | private Map<String, MethodMapping> m_methodsByDeobf; |
| 32 | private boolean isDirty; | ||
| 31 | 33 | ||
| 32 | public ClassMapping(String obfFullName) { | 34 | public ClassMapping(String obfFullName) { |
| 33 | this(obfFullName, null); | 35 | this(obfFullName, null); |
| @@ -37,6 +39,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 37 | m_obfFullName = obfFullName; | 39 | m_obfFullName = obfFullName; |
| 38 | ClassEntry classEntry = new ClassEntry(obfFullName); | 40 | ClassEntry classEntry = new ClassEntry(obfFullName); |
| 39 | m_obfSimpleName = classEntry.isInnerClass() ? classEntry.getInnermostClassName() : classEntry.getSimpleName(); | 41 | m_obfSimpleName = classEntry.isInnerClass() ? classEntry.getInnermostClassName() : classEntry.getSimpleName(); |
| 42 | m_previousDeobfName = null; | ||
| 40 | m_deobfName = NameValidator.validateClassName(deobfName, false); | 43 | m_deobfName = NameValidator.validateClassName(deobfName, false); |
| 41 | m_innerClassesByObfSimple = Maps.newHashMap(); | 44 | m_innerClassesByObfSimple = Maps.newHashMap(); |
| 42 | m_innerClassesByDeobf = Maps.newHashMap(); | 45 | m_innerClassesByDeobf = Maps.newHashMap(); |
| @@ -44,6 +47,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 44 | m_fieldsByDeobf = Maps.newHashMap(); | 47 | m_fieldsByDeobf = Maps.newHashMap(); |
| 45 | m_methodsByObf = Maps.newHashMap(); | 48 | m_methodsByObf = Maps.newHashMap(); |
| 46 | m_methodsByDeobf = Maps.newHashMap(); | 49 | m_methodsByDeobf = Maps.newHashMap(); |
| 50 | isDirty = true; | ||
| 47 | } | 51 | } |
| 48 | 52 | ||
| 49 | public String getObfFullName() { | 53 | public String getObfFullName() { |
| @@ -54,12 +58,18 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 54 | return m_obfSimpleName; | 58 | return m_obfSimpleName; |
| 55 | } | 59 | } |
| 56 | 60 | ||
| 61 | public String getPreviousDeobfName() { | ||
| 62 | return m_previousDeobfName; | ||
| 63 | } | ||
| 64 | |||
| 57 | public String getDeobfName() { | 65 | public String getDeobfName() { |
| 58 | return m_deobfName; | 66 | return m_deobfName; |
| 59 | } | 67 | } |
| 60 | 68 | ||
| 61 | public void setDeobfName(String val) { | 69 | public void setDeobfName(String val) { |
| 70 | m_previousDeobfName = m_deobfName; | ||
| 62 | m_deobfName = NameValidator.validateClassName(val, false); | 71 | m_deobfName = NameValidator.validateClassName(val, false); |
| 72 | this.isDirty = true; | ||
| 63 | } | 73 | } |
| 64 | 74 | ||
| 65 | //// INNER CLASSES //////// | 75 | //// INNER CLASSES //////// |
| @@ -81,6 +91,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 81 | } | 91 | } |
| 82 | m_innerClassesByDeobf.put(classMapping.getDeobfName(), classMapping); | 92 | m_innerClassesByDeobf.put(classMapping.getDeobfName(), classMapping); |
| 83 | } | 93 | } |
| 94 | this.isDirty = true; | ||
| 84 | } | 95 | } |
| 85 | 96 | ||
| 86 | public void removeInnerClassMapping(ClassMapping classMapping) { | 97 | public void removeInnerClassMapping(ClassMapping classMapping) { |
| @@ -90,6 +101,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 90 | boolean deobfWasRemoved = m_innerClassesByDeobf.remove(classMapping.getDeobfName()) != null; | 101 | boolean deobfWasRemoved = m_innerClassesByDeobf.remove(classMapping.getDeobfName()) != null; |
| 91 | assert (deobfWasRemoved); | 102 | assert (deobfWasRemoved); |
| 92 | } | 103 | } |
| 104 | this.isDirty = true; | ||
| 93 | } | 105 | } |
| 94 | 106 | ||
| 95 | public ClassMapping getOrCreateInnerClass(ClassEntry obfInnerClass) { | 107 | public ClassMapping getOrCreateInnerClass(ClassEntry obfInnerClass) { |
| @@ -98,6 +110,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 98 | classMapping = new ClassMapping(obfInnerClass.getName()); | 110 | classMapping = new ClassMapping(obfInnerClass.getName()); |
| 99 | boolean wasAdded = m_innerClassesByObfSimple.put(classMapping.getObfSimpleName(), classMapping) == null; | 111 | boolean wasAdded = m_innerClassesByObfSimple.put(classMapping.getObfSimpleName(), classMapping) == null; |
| 100 | assert (wasAdded); | 112 | assert (wasAdded); |
| 113 | this.isDirty = true; | ||
| 101 | } | 114 | } |
| 102 | return classMapping; | 115 | return classMapping; |
| 103 | } | 116 | } |
| @@ -141,6 +154,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 141 | boolean wasAdded = m_innerClassesByDeobf.put(deobfName, classMapping) == null; | 154 | boolean wasAdded = m_innerClassesByDeobf.put(deobfName, classMapping) == null; |
| 142 | assert (wasAdded); | 155 | assert (wasAdded); |
| 143 | } | 156 | } |
| 157 | this.isDirty = true; | ||
| 144 | } | 158 | } |
| 145 | 159 | ||
| 146 | public boolean hasInnerClassByObfSimple(String obfSimpleName) { | 160 | public boolean hasInnerClassByObfSimple(String obfSimpleName) { |
| @@ -181,6 +195,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 181 | boolean deobfWasAdded = m_fieldsByDeobf.put(deobfKey, fieldMapping) == null; | 195 | boolean deobfWasAdded = m_fieldsByDeobf.put(deobfKey, fieldMapping) == null; |
| 182 | assert (deobfWasAdded); | 196 | assert (deobfWasAdded); |
| 183 | assert (m_fieldsByObf.size() == m_fieldsByDeobf.size()); | 197 | assert (m_fieldsByObf.size() == m_fieldsByDeobf.size()); |
| 198 | this.isDirty = true; | ||
| 184 | } | 199 | } |
| 185 | 200 | ||
| 186 | public void removeFieldMapping(FieldMapping fieldMapping) { | 201 | public void removeFieldMapping(FieldMapping fieldMapping) { |
| @@ -190,6 +205,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 190 | boolean deobfWasRemoved = m_fieldsByDeobf.remove(getFieldKey(fieldMapping.getDeobfName(), fieldMapping.getObfType())) != null; | 205 | boolean deobfWasRemoved = m_fieldsByDeobf.remove(getFieldKey(fieldMapping.getDeobfName(), fieldMapping.getObfType())) != null; |
| 191 | assert (deobfWasRemoved); | 206 | assert (deobfWasRemoved); |
| 192 | } | 207 | } |
| 208 | this.isDirty = true; | ||
| 193 | } | 209 | } |
| 194 | 210 | ||
| 195 | public FieldMapping getFieldByObf(String obfName, Type obfType) { | 211 | public FieldMapping getFieldByObf(String obfName, Type obfType) { |
| @@ -243,6 +259,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 243 | boolean wasAdded = m_fieldsByDeobf.put(getFieldKey(deobfName, obfType), fieldMapping) == null; | 259 | boolean wasAdded = m_fieldsByDeobf.put(getFieldKey(deobfName, obfType), fieldMapping) == null; |
| 244 | assert (wasAdded); | 260 | assert (wasAdded); |
| 245 | } | 261 | } |
| 262 | this.isDirty = true; | ||
| 246 | } | 263 | } |
| 247 | 264 | ||
| 248 | public void setFieldObfNameAndType(String oldObfName, Type obfType, String newObfName, Type newObfType) { | 265 | public void setFieldObfNameAndType(String oldObfName, Type obfType, String newObfName, Type newObfType) { |
| @@ -253,6 +270,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 253 | fieldMapping.setObfType(newObfType); | 270 | fieldMapping.setObfType(newObfType); |
| 254 | boolean obfWasAdded = m_fieldsByObf.put(getFieldKey(newObfName, newObfType), fieldMapping) == null; | 271 | boolean obfWasAdded = m_fieldsByObf.put(getFieldKey(newObfName, newObfType), fieldMapping) == null; |
| 255 | assert(obfWasAdded); | 272 | assert(obfWasAdded); |
| 273 | this.isDirty = true; | ||
| 256 | } | 274 | } |
| 257 | 275 | ||
| 258 | //// METHODS //////// | 276 | //// METHODS //////// |
| @@ -285,6 +303,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 285 | boolean deobfWasAdded = m_methodsByDeobf.put(deobfKey, methodMapping) == null; | 303 | boolean deobfWasAdded = m_methodsByDeobf.put(deobfKey, methodMapping) == null; |
| 286 | assert (deobfWasAdded); | 304 | assert (deobfWasAdded); |
| 287 | } | 305 | } |
| 306 | this.isDirty = true; | ||
| 288 | assert (m_methodsByObf.size() >= m_methodsByDeobf.size()); | 307 | assert (m_methodsByObf.size() >= m_methodsByDeobf.size()); |
| 289 | } | 308 | } |
| 290 | 309 | ||
| @@ -295,6 +314,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 295 | boolean deobfWasRemoved = m_methodsByDeobf.remove(getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature())) != null; | 314 | boolean deobfWasRemoved = m_methodsByDeobf.remove(getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature())) != null; |
| 296 | assert (deobfWasRemoved); | 315 | assert (deobfWasRemoved); |
| 297 | } | 316 | } |
| 317 | this.isDirty = true; | ||
| 298 | } | 318 | } |
| 299 | 319 | ||
| 300 | public MethodMapping getMethodByObf(String obfName, Signature obfSignature) { | 320 | public MethodMapping getMethodByObf(String obfName, Signature obfSignature) { |
| @@ -328,6 +348,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 328 | boolean wasAdded = m_methodsByDeobf.put(getMethodKey(deobfName, obfSignature), methodMapping) == null; | 348 | boolean wasAdded = m_methodsByDeobf.put(getMethodKey(deobfName, obfSignature), methodMapping) == null; |
| 329 | assert (wasAdded); | 349 | assert (wasAdded); |
| 330 | } | 350 | } |
| 351 | this.isDirty = true; | ||
| 331 | } | 352 | } |
| 332 | 353 | ||
| 333 | public void setMethodObfNameAndSignature(String oldObfName, Signature obfSignature, String newObfName, Signature newObfSignature) { | 354 | public void setMethodObfNameAndSignature(String oldObfName, Signature obfSignature, String newObfName, Signature newObfSignature) { |
| @@ -338,6 +359,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 338 | methodMapping.setObfSignature(newObfSignature); | 359 | methodMapping.setObfSignature(newObfSignature); |
| 339 | boolean obfWasAdded = m_methodsByObf.put(getMethodKey(newObfName, newObfSignature), methodMapping) == null; | 360 | boolean obfWasAdded = m_methodsByObf.put(getMethodKey(newObfName, newObfSignature), methodMapping) == null; |
| 340 | assert(obfWasAdded); | 361 | assert(obfWasAdded); |
| 362 | this.isDirty = true; | ||
| 341 | } | 363 | } |
| 342 | 364 | ||
| 343 | //// ARGUMENTS //////// | 365 | //// ARGUMENTS //////// |
| @@ -349,16 +371,19 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 349 | methodMapping = createMethodMapping(obfMethodName, obfMethodSignature); | 371 | methodMapping = createMethodMapping(obfMethodName, obfMethodSignature); |
| 350 | } | 372 | } |
| 351 | methodMapping.setArgumentName(argumentIndex, argumentName); | 373 | methodMapping.setArgumentName(argumentIndex, argumentName); |
| 374 | this.isDirty = true; | ||
| 352 | } | 375 | } |
| 353 | 376 | ||
| 354 | public void removeArgumentName(String obfMethodName, Signature obfMethodSignature, int argumentIndex) { | 377 | public void removeArgumentName(String obfMethodName, Signature obfMethodSignature, int argumentIndex) { |
| 355 | m_methodsByObf.get(getMethodKey(obfMethodName, obfMethodSignature)).removeArgumentName(argumentIndex); | 378 | m_methodsByObf.get(getMethodKey(obfMethodName, obfMethodSignature)).removeArgumentName(argumentIndex); |
| 379 | this.isDirty = true; | ||
| 356 | } | 380 | } |
| 357 | 381 | ||
| 358 | private MethodMapping createMethodMapping(String obfName, Signature obfSignature) { | 382 | private MethodMapping createMethodMapping(String obfName, Signature obfSignature) { |
| 359 | MethodMapping methodMapping = new MethodMapping(obfName, obfSignature); | 383 | MethodMapping methodMapping = new MethodMapping(obfName, obfSignature); |
| 360 | boolean wasAdded = m_methodsByObf.put(getMethodKey(obfName, obfSignature), methodMapping) == null; | 384 | boolean wasAdded = m_methodsByObf.put(getMethodKey(obfName, obfSignature), methodMapping) == null; |
| 361 | assert (wasAdded); | 385 | assert (wasAdded); |
| 386 | this.isDirty = true; | ||
| 362 | return methodMapping; | 387 | return methodMapping; |
| 363 | } | 388 | } |
| 364 | 389 | ||
| @@ -441,6 +466,7 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 441 | m_obfFullName = newObfClassName; | 466 | m_obfFullName = newObfClassName; |
| 442 | return true; | 467 | return true; |
| 443 | } | 468 | } |
| 469 | this.isDirty = true; | ||
| 444 | return false; | 470 | return false; |
| 445 | } | 471 | } |
| 446 | 472 | ||
| @@ -456,4 +482,14 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 456 | public ClassEntry getObfEntry() { | 482 | public ClassEntry getObfEntry() { |
| 457 | return new ClassEntry(m_obfFullName); | 483 | return new ClassEntry(m_obfFullName); |
| 458 | } | 484 | } |
| 485 | |||
| 486 | public boolean isDirty() | ||
| 487 | { | ||
| 488 | return isDirty; | ||
| 489 | } | ||
| 490 | |||
| 491 | public void resetDirty() | ||
| 492 | { | ||
| 493 | this.isDirty = false; | ||
| 494 | } | ||
| 459 | } | 495 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/Mappings.java b/src/main/java/cuchaz/enigma/mapping/Mappings.java index 7061be79..912a57ab 100644 --- a/src/main/java/cuchaz/enigma/mapping/Mappings.java +++ b/src/main/java/cuchaz/enigma/mapping/Mappings.java | |||
| @@ -30,6 +30,7 @@ public class Mappings { | |||
| 30 | protected Map<String, ClassMapping> classesByObf; | 30 | protected Map<String, ClassMapping> classesByObf; |
| 31 | protected Map<String, ClassMapping> classesByDeobf; | 31 | protected Map<String, ClassMapping> classesByDeobf; |
| 32 | private final FormatType originMapping; | 32 | private final FormatType originMapping; |
| 33 | private Mappings previousState; | ||
| 33 | 34 | ||
| 34 | public Mappings() | 35 | public Mappings() |
| 35 | { | 36 | { |
| @@ -40,6 +41,7 @@ public class Mappings { | |||
| 40 | this.originMapping = originMapping; | 41 | this.originMapping = originMapping; |
| 41 | this.classesByObf = Maps.newHashMap(); | 42 | this.classesByObf = Maps.newHashMap(); |
| 42 | this.classesByDeobf = Maps.newHashMap(); | 43 | this.classesByDeobf = Maps.newHashMap(); |
| 44 | this.previousState = null; | ||
| 43 | } | 45 | } |
| 44 | 46 | ||
| 45 | public Collection<ClassMapping> classes() { | 47 | public Collection<ClassMapping> classes() { |
| @@ -204,9 +206,19 @@ public class Mappings { | |||
| 204 | return originMapping; | 206 | return originMapping; |
| 205 | } | 207 | } |
| 206 | 208 | ||
| 209 | public void savePreviousState() | ||
| 210 | { | ||
| 211 | this.previousState = new Mappings(this.originMapping); | ||
| 212 | this.previousState.classesByDeobf = Maps.newHashMap(this.classesByDeobf); | ||
| 213 | this.previousState.classesByObf = Maps.newHashMap(this.classesByObf); | ||
| 214 | classesByDeobf.values().forEach(ClassMapping::resetDirty); | ||
| 215 | classesByObf.values().forEach(ClassMapping::resetDirty); | ||
| 216 | } | ||
| 217 | |||
| 207 | public void saveEnigmaMappings(File file, boolean isDirectoryFormat) throws IOException | 218 | public void saveEnigmaMappings(File file, boolean isDirectoryFormat) throws IOException |
| 208 | { | 219 | { |
| 209 | new MappingsEnigmaWriter().write(file, this, isDirectoryFormat); | 220 | new MappingsEnigmaWriter().write(file, this, isDirectoryFormat); |
| 221 | this.savePreviousState(); | ||
| 210 | } | 222 | } |
| 211 | 223 | ||
| 212 | public void saveSRGMappings(File file) throws IOException | 224 | public void saveSRGMappings(File file) throws IOException |
| @@ -214,6 +226,10 @@ public class Mappings { | |||
| 214 | new MappingsSRGWriter().write(file, this); | 226 | new MappingsSRGWriter().write(file, this); |
| 215 | } | 227 | } |
| 216 | 228 | ||
| 229 | public Mappings getPreviousState() { | ||
| 230 | return previousState; | ||
| 231 | } | ||
| 232 | |||
| 217 | public enum FormatType | 233 | public enum FormatType |
| 218 | { | 234 | { |
| 219 | ENIGMA_FILE, ENIGMA_DIRECTORY, SRG_FILE | 235 | ENIGMA_FILE, ENIGMA_DIRECTORY, SRG_FILE |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java index 74c5340c..93276a63 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java | |||
| @@ -37,6 +37,7 @@ public class MappingsEnigmaReader | |||
| 37 | else if (file.isDirectory()) | 37 | else if (file.isDirectory()) |
| 38 | readDirectory(mappings, file.getAbsoluteFile()); | 38 | readDirectory(mappings, file.getAbsoluteFile()); |
| 39 | } | 39 | } |
| 40 | mappings.savePreviousState(); | ||
| 40 | } | 41 | } |
| 41 | else | 42 | else |
| 42 | throw new IOException("Cannot access directory" + directory.getAbsolutePath()); | 43 | throw new IOException("Cannot access directory" + directory.getAbsolutePath()); |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java index ba0720a0..e1763d0a 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaWriter.java | |||
| @@ -30,24 +30,14 @@ 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 | |||
| 43 | public void writeAsDirectory(File target, Mappings mappings) throws IOException { | 33 | 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); | ||
| 46 | if (!target.exists() && !target.mkdirs()) | 34 | if (!target.exists() && !target.mkdirs()) |
| 47 | throw new IOException("Cannot create mapping directory!"); | 35 | throw new IOException("Cannot create mapping directory!"); |
| 48 | |||
| 49 | 36 | ||
| 50 | for (ClassMapping classMapping : sorted(mappings.classes())) { | 37 | for (ClassMapping classMapping : sorted(mappings.classes())) { |
| 38 | if (!classMapping.isDirty()) | ||
| 39 | continue; | ||
| 40 | this.deletePreviousClassMapping(target, classMapping); | ||
| 51 | File obFile = new File(target, classMapping.getObfFullName() + ".mapping"); | 41 | File obFile = new File(target, classMapping.getObfFullName() + ".mapping"); |
| 52 | File result; | 42 | File result; |
| 53 | if (classMapping.getDeobfName() == null) | 43 | if (classMapping.getDeobfName() == null) |
| @@ -68,8 +58,50 @@ public class MappingsEnigmaWriter { | |||
| 68 | outputWriter.close(); | 58 | outputWriter.close(); |
| 69 | } | 59 | } |
| 70 | 60 | ||
| 61 | // Remove dropped mappings | ||
| 62 | List<ClassMapping> droppedClassMappings = new ArrayList<>(mappings.getPreviousState().classes()); | ||
| 63 | List<ClassMapping> classMappings = new ArrayList<>(mappings.classes()); | ||
| 64 | droppedClassMappings.removeAll(classMappings); | ||
| 65 | for (ClassMapping classMapping : droppedClassMappings) | ||
| 66 | { | ||
| 67 | File obFile = new File(target, classMapping.getObfFullName() + ".mapping"); | ||
| 68 | File result; | ||
| 69 | if (classMapping.getDeobfName() == null) | ||
| 70 | result = obFile; | ||
| 71 | else | ||
| 72 | { | ||
| 73 | // Make sure that old version of the file doesn't exist | ||
| 74 | if (obFile.exists()) | ||
| 75 | obFile.delete(); | ||
| 76 | result = new File(target, classMapping.getDeobfName() + ".mapping"); | ||
| 77 | } | ||
| 78 | if (result.exists()) | ||
| 79 | result.delete(); | ||
| 80 | } | ||
| 71 | } | 81 | } |
| 72 | 82 | ||
| 83 | private void deletePreviousClassMapping(File target, ClassMapping classMapping) { | ||
| 84 | File prevFile = null; | ||
| 85 | // Deob rename | ||
| 86 | if (classMapping.getDeobfName() != null && classMapping.getPreviousDeobfName() != null && !classMapping.getPreviousDeobfName().equals(classMapping.getDeobfName())) | ||
| 87 | { | ||
| 88 | prevFile = new File(target, classMapping.getPreviousDeobfName() + ".mapping"); | ||
| 89 | } | ||
| 90 | // Deob to ob rename | ||
| 91 | else if (classMapping.getDeobfName() == null && classMapping.getPreviousDeobfName() != null) | ||
| 92 | { | ||
| 93 | prevFile = new File(target, classMapping.getPreviousDeobfName() + ".mapping"); | ||
| 94 | } | ||
| 95 | // Ob to Deob rename | ||
| 96 | else if (classMapping.getDeobfName() != null && classMapping.getPreviousDeobfName() == null) | ||
| 97 | { | ||
| 98 | prevFile = new File(target, classMapping.getObfFullName() + ".mapping"); | ||
| 99 | } | ||
| 100 | |||
| 101 | if (prevFile != null && prevFile.exists()) | ||
| 102 | prevFile.delete(); | ||
| 103 | } | ||
| 104 | |||
| 73 | public void write(PrintWriter out, Mappings mappings) throws IOException { | 105 | public void write(PrintWriter out, Mappings mappings) throws IOException { |
| 74 | for (ClassMapping classMapping : sorted(mappings.classes())) { | 106 | for (ClassMapping classMapping : sorted(mappings.classes())) { |
| 75 | write(out, classMapping, 0); | 107 | write(out, classMapping, 0); |