diff options
| author | 2015-09-19 16:58:16 -0500 | |
|---|---|---|
| committer | 2015-09-19 16:58:16 -0500 | |
| commit | e7d94c619cca81c69539f10efeddf44cbf9d6286 (patch) | |
| tree | 117329653cfd7f072a37a3137052bd6e48528c94 /src | |
| parent | Added tag v0.11 beta for changeset a715b2808bb0 (diff) | |
| download | enigma-e7d94c619cca81c69539f10efeddf44cbf9d6286.tar.gz enigma-e7d94c619cca81c69539f10efeddf44cbf9d6286.tar.xz enigma-e7d94c619cca81c69539f10efeddf44cbf9d6286.zip | |
Added a Command-line interface to ConvertMain
Diffstat (limited to 'src')
| -rw-r--r-- | src/cuchaz/enigma/ConvertMain.java | 121 |
1 files changed, 87 insertions, 34 deletions
diff --git a/src/cuchaz/enigma/ConvertMain.java b/src/cuchaz/enigma/ConvertMain.java index 5ea1bcfa..cf231a25 100644 --- a/src/cuchaz/enigma/ConvertMain.java +++ b/src/cuchaz/enigma/ConvertMain.java | |||
| @@ -40,44 +40,97 @@ public class ConvertMain { | |||
| 40 | 40 | ||
| 41 | public static void main(String[] args) | 41 | public static void main(String[] args) |
| 42 | throws IOException, MappingParseException { | 42 | throws IOException, MappingParseException { |
| 43 | 43 | try{ | |
| 44 | // init files | 44 | //Get all are args |
| 45 | String inVer = "1.8.8"; | 45 | String inVer = getArg(args, 1, "Old Version", true); |
| 46 | String inSnapshot = null; | 46 | String inSnapshot = getArg(args, 2, "Old Shapshot", true); |
| 47 | String outVer = "1.9"; | 47 | String outVer = getArg(args, 3, "New Version", true); |
| 48 | String outSnapshot = "15w31c"; | 48 | String outSnapshot = getArg(args, 4, "New Snapshot", true); |
| 49 | String side = "client"; | 49 | String side = getArg(args, 5, "Side", true); |
| 50 | File home = new File(System.getProperty("user.home")); | 50 | if(inSnapshot.equalsIgnoreCase("none"){ |
| 51 | JarFile sourceJar = new JarFile(new File(home, getJarPath(inVer, inSnapshot))); | 51 | inSnapshot = null; |
| 52 | JarFile destJar = new JarFile(new File(home, getJarPath(outVer, outSnapshot))); | 52 | } |
| 53 | File inMappingsFile = new File("../Enigma Mappings/" + getVersionKey(inVer, inSnapshot, side) + ".mappings"); | 53 | if(outSnapshot.equalsIgnoreCase("none"){ |
| 54 | File outMappingsFile = new File("../Enigma Mappings/" + getVersionKey(outVer, outSnapshot, side) + ".mappings"); | 54 | outSnapshot = null; |
| 55 | Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); | 55 | } |
| 56 | File classMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".class.matches"); | 56 | //Get the home Directory |
| 57 | File fieldMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".field.matches"); | 57 | File home = new File(System.getProperty("user.home")); |
| 58 | File methodMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".method.matches"); | 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 | ||
| 62 | File inMappingsFile = new File("../Enigma Mappings/" + getVersionKey(inVer, inSnapshot, side) + ".mappings"); | ||
| 63 | File outMappingsFile = new File("../Enigma Mappings/" + getVersionKey(outVer, outSnapshot, side) + ".mappings"); | ||
| 64 | Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); | ||
| 65 | //Make the Match Files.. | ||
| 66 | File classMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".class.matches"); | ||
| 67 | File fieldMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".field.matches"); | ||
| 68 | File methodMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".method.matches"); | ||
| 59 | 69 | ||
| 60 | // match classes | 70 | String command = getArg(args, 0, "command", true); |
| 61 | //computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); | 71 | |
| 62 | editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); | 72 | if(command.equalsIgnoreCase("computeClassMatches")){ |
| 63 | //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); | 73 | computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); |
| 64 | 74 | }else if(command.equalsIgnoreCase("editClassMatches")){ | |
| 65 | // match fields | 75 | editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); |
| 66 | //computeFieldMatches(fieldMatchesFile, destJar, outMappingsFile, classMatchesFile); | 76 | }else if(command.equalsIgnoreCase("computeFieldMatches")){ |
| 67 | //editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, fieldMatchesFile); | 77 | computeFieldMatches(fieldMatchesFile, destJar, outMappingsFile, classMatchesFile); |
| 68 | //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile); | 78 | }else if(command.equalsIgnoreCase("editFieldMatches")){ |
| 69 | 79 | editFieldMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, fieldMatchesFile); | |
| 70 | // match methods/constructors | 80 | }else if(command.equalsIgnoreCase("computeMethodMatches")){ |
| 71 | //computeMethodMatches(methodMatchesFile, destJar, outMappingsFile, classMatchesFile); | 81 | computeMethodMatches(methodMatchesFile, destJar, outMappingsFile, classMatchesFile); |
| 72 | //editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile); | 82 | }else if(command.equalsIgnoreCase("editMethodMatches")){ |
| 73 | //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); | 83 | editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile); |
| 84 | }else if(command.equalsIgnoreCase("convertMappings")){ | ||
| 85 | convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); | ||
| 86 | } | ||
| 87 | }catch (IllegalArgumentException ex) { | ||
| 88 | System.out.println(ex.getMessage()); | ||
| 89 | printHelp(); | ||
| 90 | } | ||
| 74 | } | 91 | } |
| 75 | 92 | ||
| 93 | private static void printHelp() { | ||
| 94 | System.out.println(String.format("%s - %s", Constants.Name, Constants.Version)); | ||
| 95 | 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("\twhere <command> is one of:"); | ||
| 98 | System.out.println("\t\tcomputeClassMatches"); | ||
| 99 | System.out.println("\t\teditClassMatches"); | ||
| 100 | System.out.println("\t\tcomputeFieldMatches"); | ||
| 101 | System.out.println("\t\teditFieldMatches"); | ||
| 102 | System.out.println("\t\teditMethodMatches"); | ||
| 103 | 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-snapshpt> is the snapshot of Minecraft (14w32a for example) if it is not snapshot use 'none'"); | ||
| 106 | System.out.println("\twhere <new-version> is the version of Minecraft (1.9 for example)"); | ||
| 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 <side> is ether client or server"); | ||
| 109 | } | ||
| 110 | |||
| 111 | //Copy of getArg from CommandMain.... Should make a utils class. | ||
| 112 | private static String getArg(String[] args, int i, String name, boolean required) { | ||
| 113 | if (i >= args.length) { | ||
| 114 | if (required) { | ||
| 115 | throw new IllegalArgumentException(name + " is required"); | ||
| 116 | } else { | ||
| 117 | return null; | ||
| 118 | } | ||
| 119 | } | ||
| 120 | return args[i]; | ||
| 121 | } | ||
| 122 | |||
| 123 | |||
| 76 | private static String getJarPath(String version, String snapshot) { | 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 | } | ||
| 77 | if (snapshot != null) { | 130 | if (snapshot != null) { |
| 78 | return ".minecraft/versions/" + snapshot + "/" + snapshot + ".jar"; | 131 | return osSpecific + ".minecraft/versions/" + snapshot + "/" + snapshot + ".jar"; |
| 79 | } | 132 | } |
| 80 | return ".minecraft/versions/" + version + "/" + version + ".jar"; | 133 | return osSpecific + ".minecraft/versions/" + version + "/" + version + ".jar"; |
| 81 | } | 134 | } |
| 82 | 135 | ||
| 83 | private static String getVersionKey(String version, String snapshot, String side) { | 136 | private static String getVersionKey(String version, String snapshot, String side) { |
| @@ -338,4 +391,4 @@ public class ConvertMain { | |||
| 338 | } | 391 | } |
| 339 | } | 392 | } |
| 340 | } | 393 | } |
| 341 | } | 394 | } \ No newline at end of file |