diff --git a/src/main/java/cn/maxpixel/mcdecompiler/MinecraftDecompiler.java b/src/main/java/cn/maxpixel/mcdecompiler/MinecraftDecompiler.java index c470922..c71bf5c 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/MinecraftDecompiler.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/MinecraftDecompiler.java @@ -113,15 +113,13 @@ public void deobfuscate() { public void decompile(Info.DecompilerType decompilerType) { if(Files.notExists(options.outputJar())) deobfuscate(); LOGGER.info("Decompiling using \"{}\"", decompilerType); - decompile0(Decompilers.get(decompilerType), options.outputJar().toAbsolutePath().normalize(), - options.outputDecompDir().toAbsolutePath().normalize()); + decompile0(Decompilers.get(decompilerType), options.outputJar(), options.outputDecompDir()); } public void decompileCustomized(String customizedDecompilerName) { if(Files.notExists(options.outputJar())) deobfuscate(); LOGGER.info("Decompiling using customized decompiler \"{}\"", customizedDecompilerName); - decompile0(Decompilers.getCustom(customizedDecompilerName), options.outputJar().toAbsolutePath().normalize(), - options.outputDecompDir().toAbsolutePath().normalize()); + decompile0(Decompilers.getCustom(customizedDecompilerName), options.outputJar(), options.outputDecompDir()); } private void decompile0(IDecompiler decompiler, Path inputJar, Path outputDir) { @@ -170,8 +168,8 @@ public static class OptionBuilder { public OptionBuilder(String version, Info.SideType type) { this.version = Objects.requireNonNull(version, "version cannot be null!"); this.type = Objects.requireNonNull(type, "type cannot be null!"); - this.outputJar = Path.of("output", version + "_" + type + "_deobfuscated.jar"); - this.outputDecompDir = Path.of("output", version + "_" + type + "_decompiled"); + this.outputJar = Path.of("output", version + "_" + type + "_deobfuscated.jar").toAbsolutePath().normalize(); + this.outputDecompDir = Path.of("output", version + "_" + type + "_decompiled").toAbsolutePath().normalize(); } public OptionBuilder(Path inputJar) { @@ -181,8 +179,8 @@ public OptionBuilder(Path inputJar) { public OptionBuilder(Path inputJar, boolean reverse) { this.inputJar = inputJar; this.reverse = reverse; - this.outputJar = Path.of("output", "deobfuscated.jar"); - this.outputDecompDir = Path.of("output", "decompiled"); + this.outputJar = Path.of("output", "deobfuscated.jar").toAbsolutePath().normalize(); + this.outputDecompDir = Path.of("output", "decompiled").toAbsolutePath().normalize(); } public OptionBuilder libsUsing(String version) { @@ -214,12 +212,12 @@ public OptionBuilder withMapping(BufferedReader inputMappings) { } public OptionBuilder output(Path outputJar) { - this.outputJar = Objects.requireNonNull(outputJar, "outputJar cannot be null"); + this.outputJar = Objects.requireNonNull(outputJar, "outputJar cannot be null").toAbsolutePath().normalize(); return this; } public OptionBuilder outputDecomp(Path outputDecompDir) { - this.outputDecompDir = Objects.requireNonNull(outputDecompDir, "outputDecompDir cannot be null"); + this.outputDecompDir = Objects.requireNonNull(outputDecompDir, "outputDecompDir cannot be null").toAbsolutePath().normalize(); return this; } @@ -239,6 +237,8 @@ public OptionBuilder regenerateVariableNames() { } public Options build() { + if(this.outputJar.getParent().equals(this.outputDecompDir)) + throw new IllegalArgumentException("The parent directory of outputJar cannot be the same as outputDecomp"); return new Options() { @Override public String version() { diff --git a/src/main/java/cn/maxpixel/mcdecompiler/MinecraftDecompilerCommandLine.java b/src/main/java/cn/maxpixel/mcdecompiler/MinecraftDecompilerCommandLine.java index 484d6a2..11d4ce7 100644 --- a/src/main/java/cn/maxpixel/mcdecompiler/MinecraftDecompilerCommandLine.java +++ b/src/main/java/cn/maxpixel/mcdecompiler/MinecraftDecompilerCommandLine.java @@ -21,6 +21,7 @@ import cn.maxpixel.mcdecompiler.util.Utils; import joptsimple.*; import joptsimple.util.PathConverter; +import joptsimple.util.PathProperties; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -58,14 +59,14 @@ public static void main(String[] args) throws Throwable { ArgumentAcceptingOptionSpec targetNamespaceO = parser.accepts("targetNamespace", "The target namespace to remap " + "to if you are using namespaced mappings(Tiny, Tsrgv2)").availableUnless(sideTypeO).withRequiredArg(); ArgumentAcceptingOptionSpec inputO = parser.acceptsAll(asList("i", "input"), "The input file. With this option, you must " + - "specify --mappingPath option and musn't specify --version or --side option.").availableUnless(sideTypeO).requiredUnless(sideTypeO) - .withRequiredArg().withValuesConvertedBy(new PathConverter()); + "specify --mappingPath option and can't specify --version or --side option.").availableUnless(sideTypeO).requiredUnless(sideTypeO) + .withRequiredArg().withValuesConvertedBy(new PathConverter(PathProperties.FILE_EXISTING)); ArgumentAcceptingOptionSpec mappingPathO = parser.acceptsAll(asList("m", "map", "mappingPath"), "Mapping file use to " + "deobfuscate.").requiredUnless(sideTypeO).withRequiredArg(); - ArgumentAcceptingOptionSpec outputO = parser.acceptsAll(asList("o", "output"), "The remapped file. Includes suffix.") - .withRequiredArg().withValuesConvertedBy(new PathConverter()); - ArgumentAcceptingOptionSpec outputDecompO = parser.accepts("outputDecomp", "The output decompile directory") + ArgumentAcceptingOptionSpec outputO = parser.acceptsAll(asList("o", "output"), "The remapped file. Including the suffix.") .withRequiredArg().withValuesConvertedBy(new PathConverter()); + ArgumentAcceptingOptionSpec outputDecompO = parser.accepts("outputDecomp", "The decompiled output directory. Will " + + "be deleted before decompiling if it is exist").withRequiredArg().withValuesConvertedBy(new PathConverter()); ArgumentAcceptingOptionSpec decompileO = parser.acceptsAll(asList("d", "decompile"), "Decompile the " + "deobfuscated jar. Values are \"FERNFLOWER\", \"OFFICIAL_FERNFLOWER\", \"FORGEFLOWER\", \"CFR\" and \"USER_DEFINED\". Do NOT pass " + "any arg to this option when \"customDecompilerName\" option is specified.").withOptionalArg().ofType(Info.DecompilerType.class)