add optional parameter to skip META-INF
All checks were successful
Publish to snapshot maven / build (push) Successful in 49s

This commit is contained in:
moehreag 2024-05-16 13:54:18 +02:00
parent af4af1ba29
commit 80d2ef41e0

View file

@ -18,7 +18,7 @@ import org.objectweb.asm.commons.ClassRemapper;
public class MojMapPatcher { public class MojMapPatcher {
public static void run(String minecraftVersion, Path inputJar, Path outputJar) throws IOException, InterruptedException { public static void run(String minecraftVersion, Path inputJar, Path outputJar, boolean skipMetaInf) throws IOException, InterruptedException {
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse(); MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse();
Mapper mapper = new Mapper(data); Mapper mapper = new Mapper(data);
@ -36,7 +36,11 @@ public class MojMapPatcher {
Files.walkFileTree(inFs.getPath("/"), new SimpleFileVisitor<>() { Files.walkFileTree(inFs.getPath("/"), new SimpleFileVisitor<>() {
@Override @Override
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException { public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) {
if (skipMetaInf && path.startsWith("/META-INF")){
return FileVisitResult.SKIP_SUBTREE;
}
tasks.add(() -> { tasks.add(() -> {
try { try {
if (path.getFileName().toString().endsWith(".class")) { if (path.getFileName().toString().endsWith(".class")) {
@ -74,16 +78,17 @@ public class MojMapPatcher {
public static void main(String[] args) throws IOException, InterruptedException { public static void main(String[] args) throws IOException, InterruptedException {
// temporary // temporary
if (args.length != 3) { if (args.length < 3 || args.length > 4) {
System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar]"); System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar] <--remove-meta-inf>");
return; return;
} }
String minecraftVersion = args[0]; String minecraftVersion = args[0];
String minecraftJar = args[1]; String minecraftJar = args[1];
String outJar = args[2]; String outJar = args[2];
boolean removeMetaInf = args.length > 3 && "--remove-meta-inf".equals(args[3]);
run(minecraftVersion, Paths.get(minecraftJar), Paths.get(outJar)); run(minecraftVersion, Paths.get(minecraftJar), Paths.get(outJar), removeMetaInf);
} }
} }