diff options
| author | 2015-10-15 10:38:52 -0500 | |
|---|---|---|
| committer | 2015-10-15 10:38:52 -0500 | |
| commit | c385ed04881ee9ea0b8129d03fe556222c378961 (patch) | |
| tree | d696725b3cf9470a2df93d9c9bb792d4eb708b6e /src | |
| parent | Added description to all the tasks in build.py (diff) | |
| download | enigma-c385ed04881ee9ea0b8129d03fe556222c378961.tar.gz enigma-c385ed04881ee9ea0b8129d03fe556222c378961.tar.xz enigma-c385ed04881ee9ea0b8129d03fe556222c378961.zip | |
Make ConvertMain more generic
Diffstat (limited to 'src')
| -rw-r--r-- | src/cuchaz/enigma/ConvertMain.java | 79 |
1 files changed, 31 insertions, 48 deletions
diff --git a/src/cuchaz/enigma/ConvertMain.java b/src/cuchaz/enigma/ConvertMain.java index 9a370115..48a15881 100644 --- a/src/cuchaz/enigma/ConvertMain.java +++ b/src/cuchaz/enigma/ConvertMain.java | |||
| @@ -42,45 +42,46 @@ public class ConvertMain { | |||
| 42 | throws IOException, MappingParseException { | 42 | throws IOException, MappingParseException { |
| 43 | try{ | 43 | try{ |
| 44 | //Get all are args | 44 | //Get all are args |
| 45 | String inVer = getArg(args, 1, "Old Version", true); | 45 | String JarOld = getArg(args, 1, "Path to Old Jar", true); |
| 46 | String inSnapshot = getArg(args, 2, "Old Shapshot", true); | 46 | String JarNew = getArg(args, 2, "Path to New Jar", true); |
| 47 | String outVer = getArg(args, 3, "New Version", true); | 47 | String OldMappings = getArg(args, 3, "Path to old .mappings file", true); |
| 48 | String outSnapshot = getArg(args, 4, "New Snapshot", true); | 48 | String NewMappings = getArg(args,4,"Path to new .mappings file",true); |
| 49 | String side = getArg(args, 5, "Side", true); | 49 | String ClassMatches = getArg(args, 5, "Path to Class .matches file", true); |
| 50 | if(inSnapshot.equalsIgnoreCase("none")){ | 50 | String FieldMatches = getArg(args, 6, "Path to Field .matches file", true); |
| 51 | inSnapshot = null; | 51 | String MethodMatches = getArg(args, 7, "Path to Method .matches file", true); |
| 52 | } | 52 | //OldJar |
| 53 | if(outSnapshot.equalsIgnoreCase("none")){ | 53 | JarFile sourceJar = new JarFile(new File(JarOld)); |
| 54 | outSnapshot = null; | 54 | //NewJar |
| 55 | } | 55 | JarFile destJar = new JarFile(new File(JarNew)); |
| 56 | //Get the home Directory | ||
| 57 | File home = new File(System.getProperty("user.home")); | ||
| 58 | //Find the minecraft jars. | ||
| 59 | JarFile sourceJar = new JarFile(new File(home, getJarPath(inVer, inSnapshot))); | ||
| 60 | JarFile destJar = new JarFile(new File(home, getJarPath(outVer, outSnapshot))); | ||
| 61 | //Get the mapping files | 56 | //Get the mapping files |
| 62 | File inMappingsFile = new File("../Enigma Mappings/" + getVersionKey(inVer, inSnapshot, side) + ".mappings"); | 57 | File inMappingsFile = new File(OldMappings); |
| 63 | File outMappingsFile = new File("../Enigma Mappings/" + getVersionKey(outVer, outSnapshot, side) + ".mappings"); | 58 | File outMappingsFile = new File(NewMappings); |
| 64 | Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); | 59 | Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); |
| 65 | //Make the Match Files.. | 60 | //Make the Match Files.. |
| 66 | File classMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".class.matches"); | 61 | File classMatchesFile = new File(ClassMatches); |
| 67 | File fieldMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".field.matches"); | 62 | File fieldMatchesFile = new File(FieldMatches); |
| 68 | File methodMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".method.matches"); | 63 | File methodMatchesFile = new File(MethodMatches); |
| 69 | 64 | ||
| 70 | String command = getArg(args, 0, "command", true); | 65 | String command = getArg(args, 0, "command", true); |
| 71 | 66 | ||
| 72 | if(command.equalsIgnoreCase("computeClassMatches")){ | 67 | if(command.equalsIgnoreCase("computeClassMatches")){ |
| 73 | computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); | 68 | computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); |
| 69 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); | ||
| 74 | }else if(command.equalsIgnoreCase("editClassMatches")){ | 70 | }else if(command.equalsIgnoreCase("editClassMatches")){ |
| 75 | editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); | 71 | editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); |
| 72 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); | ||
| 76 | }else if(command.equalsIgnoreCase("computeFieldMatches")){ | 73 | }else if(command.equalsIgnoreCase("computeFieldMatches")){ |
| 77 | computeFieldMatches(fieldMatchesFile, destJar, outMappingsFile, classMatchesFile); | 74 | computeFieldMatches(fieldMatchesFile, destJar, outMappingsFile, classMatchesFile); |
| 75 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile); | ||
| 78 | }else if(command.equalsIgnoreCase("editFieldMatches")){ | 76 | }else if(command.equalsIgnoreCase("editFieldMatches")){ |
| 79 | editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, fieldMatchesFile); | 77 | editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, fieldMatchesFile); |
| 78 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile); | ||
| 80 | }else if(command.equalsIgnoreCase("computeMethodMatches")){ | 79 | }else if(command.equalsIgnoreCase("computeMethodMatches")){ |
| 81 | computeMethodMatches(methodMatchesFile, destJar, outMappingsFile, classMatchesFile); | 80 | computeMethodMatches(methodMatchesFile, destJar, outMappingsFile, classMatchesFile); |
| 81 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); | ||
| 82 | }else if(command.equalsIgnoreCase("editMethodMatches")){ | 82 | }else if(command.equalsIgnoreCase("editMethodMatches")){ |
| 83 | editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile); | 83 | editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile); |
| 84 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); | ||
| 84 | }else if(command.equalsIgnoreCase("convertMappings")){ | 85 | }else if(command.equalsIgnoreCase("convertMappings")){ |
| 85 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); | 86 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); |
| 86 | } | 87 | } |
| @@ -93,19 +94,21 @@ public class ConvertMain { | |||
| 93 | private static void printHelp() { | 94 | private static void printHelp() { |
| 94 | System.out.println(String.format("%s - %s", Constants.Name, Constants.Version)); | 95 | System.out.println(String.format("%s - %s", Constants.Name, Constants.Version)); |
| 95 | System.out.println("Usage:"); | 96 | System.out.println("Usage:"); |
| 96 | System.out.println("\tjava -cp enigma.jar cuchaz.enigma.ConvertMain <command> <old-version> <old-snapshot> <new-version> <new-snapshot> <side>"); | 97 | System.out.println("\tjava -cp enigma.jar cuchaz.enigma.ConvertMain <command> <old-jar> <new-jar> <old-mappings> <new-mappings> <class-matches> <field-matches> <method-matches>"); |
| 97 | System.out.println("\twhere <command> is one of:"); | 98 | System.out.println("\tWhere <command> is one of:"); |
| 98 | System.out.println("\t\tcomputeClassMatches"); | 99 | System.out.println("\t\tcomputeClassMatches"); |
| 99 | System.out.println("\t\teditClassMatches"); | 100 | System.out.println("\t\teditClassMatches"); |
| 100 | System.out.println("\t\tcomputeFieldMatches"); | 101 | System.out.println("\t\tcomputeFieldMatches"); |
| 101 | System.out.println("\t\teditFieldMatches"); | 102 | System.out.println("\t\teditFieldMatches"); |
| 102 | System.out.println("\t\teditMethodMatches"); | 103 | System.out.println("\t\teditMethodMatches"); |
| 103 | System.out.println("\t\tconvertMappings"); | 104 | System.out.println("\t\tconvertMappings"); |
| 104 | System.out.println("\twhere <old-version> is the version of Minecraft (1.8 for example)"); | 105 | System.out.println("\tWhere <old-jar> is the already mapped jar."); |
| 105 | System.out.println("\twhere <old-snapshpt> is the snapshot of Minecraft (14w32a for example) if it is not snapshot use 'none'"); | 106 | System.out.println("\tWhere <new-jar> is the unmapped jar."); |
| 106 | System.out.println("\twhere <new-version> is the version of Minecraft (1.9 for example)"); | 107 | System.out.println("\tWhere <old-mappings> is the path to the mappings for the old jar."); |
| 107 | System.out.println("\twhere <new-snapshpt> is the snapshot of Minecraft (15w32a for example) if it is not snapshot use 'none'"); | 108 | System.out.println("\tWhere <new-mappings> is the new mappings. (Where you want to save them and there name)"); |
| 108 | System.out.println("\twhere <side> is ether client or server"); | 109 | System.out.println("\tWhere <class-matches> is the class matches file."); |
| 110 | System.out.println("\tWhere <field-matches> is the field matches file."); | ||
| 111 | System.out.println("\tWhere <method-matches> is the method matches file."); | ||
| 109 | } | 112 | } |
| 110 | 113 | ||
| 111 | //Copy of getArg from CommandMain.... Should make a utils class. | 114 | //Copy of getArg from CommandMain.... Should make a utils class. |
| @@ -119,26 +122,6 @@ public class ConvertMain { | |||
| 119 | } | 122 | } |
| 120 | return args[i]; | 123 | return args[i]; |
| 121 | } | 124 | } |
| 122 | |||
| 123 | |||
| 124 | private static String getJarPath(String version, String snapshot) { | ||
| 125 | String os = System.getProperty("os.name"); | ||
| 126 | String osSpecific = ""; | ||
| 127 | if(os.toLowerCase().contains("win")){ | ||
| 128 | osSpecific = "AppData\\Roaming\\"; | ||
| 129 | } | ||
| 130 | if (snapshot != null) { | ||
| 131 | return osSpecific + ".minecraft/versions/" + snapshot + "/" + snapshot + ".jar"; | ||
| 132 | } | ||
| 133 | return osSpecific + ".minecraft/versions/" + version + "/" + version + ".jar"; | ||
| 134 | } | ||
| 135 | |||
| 136 | private static String getVersionKey(String version, String snapshot, String side) { | ||
| 137 | if (snapshot == null) { | ||
| 138 | return version + "-" + side; | ||
| 139 | } | ||
| 140 | return version + "." + snapshot + "-" + side; | ||
| 141 | } | ||
| 142 | 125 | ||
| 143 | private static void computeClassMatches(File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) | 126 | private static void computeClassMatches(File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) |
| 144 | throws IOException { | 127 | throws IOException { |