39 lines
1.5 KiB
Java
39 lines
1.5 KiB
Java
package io.gitlab.jfronny.resclone.processors;
|
|
|
|
import io.gitlab.jfronny.resclone.Resclone;
|
|
import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor;
|
|
import net.minecraft.server.MinecraftServer;
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.nio.file.*;
|
|
|
|
public class PruneVanillaProcessor implements PackProcessor {
|
|
@Override
|
|
public void process(FileSystem p) throws Exception {
|
|
ClassLoader cl = MinecraftServer.class.getClassLoader();
|
|
try {
|
|
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);
|
|
}
|
|
}
|
|
} catch (Throwable e) {
|
|
Resclone.LOGGER.error("Could not prune unchanged assets", e);
|
|
}
|
|
return false;
|
|
}));
|
|
}
|
|
} catch (IOException e) {
|
|
throw new Exception("Could not prune vanilla files", e);
|
|
}
|
|
}
|
|
}
|