Introduce some try-with-resource blocks in an attempt to fix windows
This commit is contained in:
parent
a0207bb153
commit
5af47bf460
|
@ -6,8 +6,7 @@ import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
|
||||||
public class RemoveDirVisitor extends SimpleFileVisitor<Path> {
|
public class RemoveDirVisitor extends SimpleFileVisitor<Path> {
|
||||||
@Override
|
@Override
|
||||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||||
{
|
|
||||||
Files.delete(file);
|
Files.delete(file);
|
||||||
return FileVisitResult.CONTINUE;
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,9 @@ public class PruneVanillaProcessor extends PackProcessor {
|
||||||
try {
|
try {
|
||||||
InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString());
|
InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString());
|
||||||
if (vn != null) {
|
if (vn != null) {
|
||||||
InputStream pk = Files.newInputStream(s, StandardOpenOption.READ);
|
try (InputStream pk = Files.newInputStream(s, StandardOpenOption.READ)) {
|
||||||
return IOUtils.contentEquals(vn, pk);
|
return IOUtils.contentEquals(vn, pk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
|
|
|
@ -4,8 +4,10 @@ import io.gitlab.jfronny.resclone.data.RescloneException;
|
||||||
import io.gitlab.jfronny.resclone.io.PathPruneVisitor;
|
import io.gitlab.jfronny.resclone.io.PathPruneVisitor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.FileSystem;
|
import java.nio.file.FileSystem;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
public class RemoveEmptyProcessor extends PackProcessor {
|
public class RemoveEmptyProcessor extends PackProcessor {
|
||||||
@Override
|
@Override
|
||||||
|
@ -14,8 +16,8 @@ public class RemoveEmptyProcessor extends PackProcessor {
|
||||||
try {
|
try {
|
||||||
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
|
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
|
||||||
if (Files.isDirectory(s)) {
|
if (Files.isDirectory(s)) {
|
||||||
try {
|
try (DirectoryStream<Path> paths = Files.newDirectoryStream(s)) {
|
||||||
return !Files.newDirectoryStream(s).iterator().hasNext();
|
return !paths.iterator().hasNext();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,7 @@ import io.gitlab.jfronny.resclone.io.MoveDirVisitor;
|
||||||
import io.gitlab.jfronny.resclone.data.RescloneException;
|
import io.gitlab.jfronny.resclone.data.RescloneException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.FileSystem;
|
import java.nio.file.*;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
|
|
||||||
public class RootPathProcessor extends PackProcessor {
|
public class RootPathProcessor extends PackProcessor {
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,9 +12,11 @@ public class RootPathProcessor extends PackProcessor {
|
||||||
if (!Files.exists(p.getPath("/pack.mcmeta"))) {
|
if (!Files.exists(p.getPath("/pack.mcmeta"))) {
|
||||||
try {
|
try {
|
||||||
Path root = p.getPath("/");
|
Path root = p.getPath("/");
|
||||||
for (Path path : Files.newDirectoryStream(root)) {
|
try (DirectoryStream<Path> paths = Files.newDirectoryStream(root)) {
|
||||||
if (Files.isDirectory(path) && Files.exists(path.resolve("pack.mcmeta"))) {
|
for (Path path : paths) {
|
||||||
Files.walkFileTree(path, new MoveDirVisitor(path, root, StandardCopyOption.REPLACE_EXISTING));
|
if (Files.isDirectory(path) && Files.exists(path.resolve("pack.mcmeta"))) {
|
||||||
|
Files.walkFileTree(path, new MoveDirVisitor(path, root, StandardCopyOption.REPLACE_EXISTING));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Reference in New Issue