package cuchaz.enigma.command; import java.lang.reflect.Field; import java.nio.file.Path; import java.util.List; import java.util.Locale; import cuchaz.enigma.EnigmaProject; import cuchaz.enigma.EnigmaProject.DecompileErrorStrategy; import cuchaz.enigma.ProgressListener; import cuchaz.enigma.source.DecompilerService; import cuchaz.enigma.source.Decompilers; public class DecompileCommand extends Command { public DecompileCommand() { super("decompile"); } @Override public String getUsage() { return " [] [ ...]"; } @Override public boolean isValidArgument(int length) { return length == 3 || length == 4; } @Override public void run(String... args) throws Exception { String decompilerName = getArg(args, 0, "decompiler", true); Path fileJarIn = getReadableFile(getArg(args, 1, "in jar", true)).toPath(); Path fileJarOut = getWritableFolder(getArg(args, 2, "out folder", true)).toPath(); Path fileMappings = getReadablePath(getArg(args, 3, "mappings file", false)); List libraries = getReadablePaths(args, 4); DecompilerService decompilerService; try { Field decompilerField = Decompilers.class.getField(decompilerName.toUpperCase(Locale.ROOT)); decompilerService = (DecompilerService) decompilerField.get(null); } catch (NoSuchFieldException e) { System.err.println("Decompiler not found."); return; } EnigmaProject project = openProject(fileJarIn, fileMappings, libraries); ProgressListener progress = new ConsoleProgressListener(); EnigmaProject.JarExport jar = project.exportRemappedJar(progress); EnigmaProject.SourceExport source = jar.decompile(project, progress, decompilerService, DecompileErrorStrategy.TRACE_AS_SOURCE); source.write(fileJarOut, progress); } }