2020-12-29 16:14:53 +01:00
|
|
|
package io.gitlab.jfronny.resclone.processors;
|
|
|
|
|
2021-05-07 17:39:13 +02:00
|
|
|
import io.gitlab.jfronny.resclone.util.io.MoveDirVisitor;
|
2020-12-29 16:14:53 +01:00
|
|
|
|
|
|
|
import java.io.IOException;
|
2021-03-04 14:59:41 +01:00
|
|
|
import java.nio.file.*;
|
2020-12-29 16:14:53 +01:00
|
|
|
|
2021-05-11 17:51:34 +02:00
|
|
|
public class RootPathProcessor 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 {
|
2020-12-29 16:14:53 +01:00
|
|
|
if (!Files.exists(p.getPath("/pack.mcmeta"))) {
|
|
|
|
try {
|
|
|
|
Path root = p.getPath("/");
|
2021-03-04 14:59:41 +01:00
|
|
|
try (DirectoryStream<Path> paths = Files.newDirectoryStream(root)) {
|
|
|
|
for (Path path : paths) {
|
|
|
|
if (Files.isDirectory(path) && Files.exists(path.resolve("pack.mcmeta"))) {
|
|
|
|
Files.walkFileTree(path, new MoveDirVisitor(path, root, StandardCopyOption.REPLACE_EXISTING));
|
|
|
|
}
|
2020-12-29 16:14:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
2021-04-03 02:40:38 +02:00
|
|
|
throw new Exception("Could not fix root path", e);
|
2020-12-29 16:14:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-06-05 17:40:50 +02:00
|
|
|
}
|