Resclone/src/main/java/io/gitlab/jfronny/resclone/processors/PruneVanillaProcessor.java

39 lines
1.5 KiB
Java
Raw Normal View History

2020-12-29 16:14:53 +01:00
package io.gitlab.jfronny.resclone.processors;
2023-02-26 14:00:38 +01:00
import io.gitlab.jfronny.resclone.Resclone;
2021-05-07 17:39:13 +02:00
import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor;
2022-07-28 15:36:25 +02:00
import net.minecraft.server.MinecraftServer;
2020-12-29 16:14:53 +01:00
import org.apache.commons.io.IOUtils;
import java.io.IOException;
import java.io.InputStream;
2023-02-26 14:00:38 +01:00
import java.nio.file.*;
2020-12-29 16:14:53 +01:00
public class PruneVanillaProcessor implements PackProcessor {
2020-12-29 16:14:53 +01:00
@Override
2021-04-03 02:40:38 +02:00
public void process(FileSystem p) throws Exception {
2022-07-28 15:36:25 +02:00
ClassLoader cl = MinecraftServer.class.getClassLoader();
2020-12-29 16:14:53 +01:00
try {
2021-02-19 12:39:22 +01:00
if (Files.isDirectory(p.getPath("/assets/minecraft"))) {
Files.walkFileTree(p.getPath("/assets/minecraft"), new PathPruneVisitor((s) -> {
if (Files.isDirectory(s))
return false;
try {
InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString());
if (vn != null) {
try (InputStream pk = Files.newInputStream(s, StandardOpenOption.READ)) {
return IOUtils.contentEquals(vn, pk);
}
2021-02-19 12:39:22 +01:00
}
2021-04-03 02:40:38 +02:00
} catch (Throwable e) {
Resclone.LOGGER.error("Could not prune unchanged assets", e);
2020-12-29 16:14:53 +01:00
}
2021-02-19 12:39:22 +01:00
return false;
}));
}
2020-12-29 16:14:53 +01:00
} catch (IOException e) {
2021-04-03 02:40:38 +02:00
throw new Exception("Could not prune vanilla files", e);
2020-12-29 16:14:53 +01:00
}
}
}