diff options
| author | 2016-08-12 19:23:54 +0200 | |
|---|---|---|
| committer | 2016-08-12 19:23:54 +0200 | |
| commit | c4970cc4addedd4565cf8c3ed9ea92b6a4487e0c (patch) | |
| tree | a6f00a59cd0d5bc41014768506d9c4d3aad48de8 /src/main/java/cuchaz/enigma/mapping/MappingsReader.java | |
| parent | Allow exporting mappings as SRG or Enigma (diff) | |
| download | enigma-fork-c4970cc4addedd4565cf8c3ed9ea92b6a4487e0c.tar.gz enigma-fork-c4970cc4addedd4565cf8c3ed9ea92b6a4487e0c.tar.xz enigma-fork-c4970cc4addedd4565cf8c3ed9ea92b6a4487e0c.zip | |
Implement Enigma directory format (#1)
Others changes:
~ Rework File menu
~ Force UTF-8 for all I/O operations
~ Enigma now detect the original file format and use the correct one when you save a mapping
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsReader.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsReader.java | 121 |
1 files changed, 0 insertions, 121 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsReader.java deleted file mode 100644 index b2b6d09..0000000 --- a/src/main/java/cuchaz/enigma/mapping/MappingsReader.java +++ /dev/null | |||
| @@ -1,121 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.mapping; | ||
| 12 | |||
| 13 | import com.google.common.io.Files; | ||
| 14 | import com.google.gson.Gson; | ||
| 15 | import com.google.gson.GsonBuilder; | ||
| 16 | |||
| 17 | import java.io.BufferedReader; | ||
| 18 | import java.io.File; | ||
| 19 | import java.io.FileReader; | ||
| 20 | import java.io.IOException; | ||
| 21 | |||
| 22 | import cuchaz.enigma.json.JsonClass; | ||
| 23 | import cuchaz.enigma.throwables.MappingConflict; | ||
| 24 | |||
| 25 | public class MappingsReader { | ||
| 26 | |||
| 27 | public Mappings read(File in) throws IOException { | ||
| 28 | Mappings mappings = new Mappings(); | ||
| 29 | readDirectory(mappings, in); | ||
| 30 | return mappings; | ||
| 31 | } | ||
| 32 | |||
| 33 | public void readDirectory(Mappings mappings, File in) throws IOException { | ||
| 34 | File[] fList = in.listFiles(); | ||
| 35 | if (fList != null) { | ||
| 36 | for (File file : fList) { | ||
| 37 | if (file.isFile() && Files.getFileExtension(file.getName()).equalsIgnoreCase("json")) { | ||
| 38 | readFile(mappings, new BufferedReader(new FileReader(file))); | ||
| 39 | } else if (file.isDirectory()) { | ||
| 40 | readDirectory(mappings, file.getAbsoluteFile()); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | public void readFile(Mappings mappings, BufferedReader in) throws IOException { | ||
| 47 | StringBuilder buf = new StringBuilder(); | ||
| 48 | String line; | ||
| 49 | while ((line = in.readLine()) != null) { | ||
| 50 | buf.append(line); | ||
| 51 | } | ||
| 52 | |||
| 53 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); | ||
| 54 | JsonClass jsonClass = gson.fromJson(buf.toString(), JsonClass.class); | ||
| 55 | try { | ||
| 56 | load(null, jsonClass, mappings); | ||
| 57 | } catch (MappingConflict e) { | ||
| 58 | e.printStackTrace(); | ||
| 59 | } | ||
| 60 | in.close(); | ||
| 61 | } | ||
| 62 | |||
| 63 | public void load(ClassMapping parent, JsonClass jsonClass, Mappings mappings) throws MappingConflict { | ||
| 64 | ClassMapping classMapping = readClass(jsonClass.getObf(), jsonClass.getName()); | ||
| 65 | if (parent != null) { | ||
| 66 | parent.addInnerClassMapping(classMapping); | ||
| 67 | } else { | ||
| 68 | mappings.addClassMapping(classMapping); | ||
| 69 | } | ||
| 70 | jsonClass.getField().forEach(jsonField -> classMapping.addFieldMapping(readField(jsonField.getObf(), jsonField.getName(), jsonField.getType()))); | ||
| 71 | |||
| 72 | jsonClass.getConstructors().forEach(jsonConstructor -> { | ||
| 73 | MethodMapping methodMapping = readMethod(jsonConstructor.isStatics() ? "<clinit>" : "<init>", null, jsonConstructor.getSignature()); | ||
| 74 | jsonConstructor.getArgs().forEach(jsonArgument -> { | ||
| 75 | try { | ||
| 76 | methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName())); | ||
| 77 | } catch (MappingConflict e) { | ||
| 78 | e.printStackTrace(); | ||
| 79 | } | ||
| 80 | }); | ||
| 81 | classMapping.addMethodMapping(methodMapping); | ||
| 82 | }); | ||
| 83 | |||
| 84 | jsonClass.getMethod().forEach(jsonMethod -> { | ||
| 85 | MethodMapping methodMapping = readMethod(jsonMethod.getObf(), jsonMethod.getName(), jsonMethod.getSignature()); | ||
| 86 | jsonMethod.getArgs().forEach(jsonArgument -> { | ||
| 87 | try { | ||
| 88 | methodMapping.addArgumentMapping(readArgument(jsonArgument.getIndex(), jsonArgument.getName())); | ||
| 89 | } catch (MappingConflict e) { | ||
| 90 | e.printStackTrace(); | ||
| 91 | } | ||
| 92 | }); | ||
| 93 | classMapping.addMethodMapping(methodMapping); | ||
| 94 | }); | ||
| 95 | |||
| 96 | jsonClass.getInnerClass().forEach(jsonInnerClasses -> { | ||
| 97 | try { | ||
| 98 | load(classMapping, jsonInnerClasses, mappings); | ||
| 99 | } catch (MappingConflict e) { | ||
| 100 | e.printStackTrace(); | ||
| 101 | } | ||
| 102 | }); | ||
| 103 | } | ||
| 104 | |||
| 105 | private ArgumentMapping readArgument(int index, String name) { | ||
| 106 | return new ArgumentMapping(index, name); | ||
| 107 | } | ||
| 108 | |||
| 109 | private ClassMapping readClass(String obf, String deobf) { | ||
| 110 | return new ClassMapping("none/" + obf, deobf); | ||
| 111 | } | ||
| 112 | |||
| 113 | /* TEMP */ | ||
| 114 | protected FieldMapping readField(String obf, String deobf, String sig) { | ||
| 115 | return new FieldMapping(obf, new Type(sig), deobf); | ||
| 116 | } | ||
| 117 | |||
| 118 | private MethodMapping readMethod(String obf, String deobf, String sig) { | ||
| 119 | return new MethodMapping(obf, new Signature(sig), deobf); | ||
| 120 | } | ||
| 121 | } | ||