From c385ed04881ee9ea0b8129d03fe556222c378961 Mon Sep 17 00:00:00 2001 From: chibill Date: Thu, 15 Oct 2015 10:38:52 -0500 Subject: Make ConvertMain more generic --- src/cuchaz/enigma/ConvertMain.java | 79 +++++++++++++++----------------------- 1 file changed, 31 insertions(+), 48 deletions(-) (limited to 'src') 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 { throws IOException, MappingParseException { try{ //Get all are args - String inVer = getArg(args, 1, "Old Version", true); - String inSnapshot = getArg(args, 2, "Old Shapshot", true); - String outVer = getArg(args, 3, "New Version", true); - String outSnapshot = getArg(args, 4, "New Snapshot", true); - String side = getArg(args, 5, "Side", true); - if(inSnapshot.equalsIgnoreCase("none")){ - inSnapshot = null; - } - if(outSnapshot.equalsIgnoreCase("none")){ - outSnapshot = null; - } - //Get the home Directory - File home = new File(System.getProperty("user.home")); - //Find the minecraft jars. - JarFile sourceJar = new JarFile(new File(home, getJarPath(inVer, inSnapshot))); - JarFile destJar = new JarFile(new File(home, getJarPath(outVer, outSnapshot))); + String JarOld = getArg(args, 1, "Path to Old Jar", true); + String JarNew = getArg(args, 2, "Path to New Jar", true); + String OldMappings = getArg(args, 3, "Path to old .mappings file", true); + String NewMappings = getArg(args,4,"Path to new .mappings file",true); + String ClassMatches = getArg(args, 5, "Path to Class .matches file", true); + String FieldMatches = getArg(args, 6, "Path to Field .matches file", true); + String MethodMatches = getArg(args, 7, "Path to Method .matches file", true); + //OldJar + JarFile sourceJar = new JarFile(new File(JarOld)); + //NewJar + JarFile destJar = new JarFile(new File(JarNew)); //Get the mapping files - File inMappingsFile = new File("../Enigma Mappings/" + getVersionKey(inVer, inSnapshot, side) + ".mappings"); - File outMappingsFile = new File("../Enigma Mappings/" + getVersionKey(outVer, outSnapshot, side) + ".mappings"); + File inMappingsFile = new File(OldMappings); + File outMappingsFile = new File(NewMappings); Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); //Make the Match Files.. - File classMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".class.matches"); - File fieldMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".field.matches"); - File methodMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".method.matches"); + File classMatchesFile = new File(ClassMatches); + File fieldMatchesFile = new File(FieldMatches); + File methodMatchesFile = new File(MethodMatches); String command = getArg(args, 0, "command", true); if(command.equalsIgnoreCase("computeClassMatches")){ computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); + convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); }else if(command.equalsIgnoreCase("editClassMatches")){ editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); + convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); }else if(command.equalsIgnoreCase("computeFieldMatches")){ computeFieldMatches(fieldMatchesFile, destJar, outMappingsFile, classMatchesFile); + convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile); }else if(command.equalsIgnoreCase("editFieldMatches")){ editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, fieldMatchesFile); + convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile); }else if(command.equalsIgnoreCase("computeMethodMatches")){ computeMethodMatches(methodMatchesFile, destJar, outMappingsFile, classMatchesFile); + convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); }else if(command.equalsIgnoreCase("editMethodMatches")){ editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile); + convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); }else if(command.equalsIgnoreCase("convertMappings")){ convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); } @@ -93,19 +94,21 @@ public class ConvertMain { private static void printHelp() { System.out.println(String.format("%s - %s", Constants.Name, Constants.Version)); System.out.println("Usage:"); - System.out.println("\tjava -cp enigma.jar cuchaz.enigma.ConvertMain "); - System.out.println("\twhere is one of:"); + System.out.println("\tjava -cp enigma.jar cuchaz.enigma.ConvertMain "); + System.out.println("\tWhere is one of:"); System.out.println("\t\tcomputeClassMatches"); System.out.println("\t\teditClassMatches"); System.out.println("\t\tcomputeFieldMatches"); System.out.println("\t\teditFieldMatches"); System.out.println("\t\teditMethodMatches"); System.out.println("\t\tconvertMappings"); - System.out.println("\twhere is the version of Minecraft (1.8 for example)"); - System.out.println("\twhere is the snapshot of Minecraft (14w32a for example) if it is not snapshot use 'none'"); - System.out.println("\twhere is the version of Minecraft (1.9 for example)"); - System.out.println("\twhere is the snapshot of Minecraft (15w32a for example) if it is not snapshot use 'none'"); - System.out.println("\twhere is ether client or server"); + System.out.println("\tWhere is the already mapped jar."); + System.out.println("\tWhere is the unmapped jar."); + System.out.println("\tWhere is the path to the mappings for the old jar."); + System.out.println("\tWhere is the new mappings. (Where you want to save them and there name)"); + System.out.println("\tWhere is the class matches file."); + System.out.println("\tWhere is the field matches file."); + System.out.println("\tWhere is the method matches file."); } //Copy of getArg from CommandMain.... Should make a utils class. @@ -119,26 +122,6 @@ public class ConvertMain { } return args[i]; } - - - private static String getJarPath(String version, String snapshot) { - String os = System.getProperty("os.name"); - String osSpecific = ""; - if(os.toLowerCase().contains("win")){ - osSpecific = "AppData\\Roaming\\"; - } - if (snapshot != null) { - return osSpecific + ".minecraft/versions/" + snapshot + "/" + snapshot + ".jar"; - } - return osSpecific + ".minecraft/versions/" + version + "/" + version + ".jar"; - } - - private static String getVersionKey(String version, String snapshot, String side) { - if (snapshot == null) { - return version + "-" + side; - } - return version + "." + snapshot + "-" + side; - } private static void computeClassMatches(File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) throws IOException { -- cgit v1.2.3