diff --git a/changelog.md b/changelog.md index 1b4274a5..fd08d0fc 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ ### Bug fixes - Deleting backups from the uninstallation menu would sometimes fail +- Deleting export folder would throw exception when it did not exist ## [v4.2.1](https://github.com/LMH01/MGT2_Mod_Tool/releases/tag/v4.2.1) (Latest Version) diff --git a/src/main/java/com/github/lmh01/mgt2mt/data_stream/DataStreamHelper.java b/src/main/java/com/github/lmh01/mgt2mt/data_stream/DataStreamHelper.java index ccd94238..7c32057a 100644 --- a/src/main/java/com/github/lmh01/mgt2mt/data_stream/DataStreamHelper.java +++ b/src/main/java/com/github/lmh01/mgt2mt/data_stream/DataStreamHelper.java @@ -355,6 +355,9 @@ public static void deleteDirectory(Path directoryToBeDeleted, boolean useProgres } ProgressBarHelper.increaseMaxValue((int) getFileCount(directoryToBeDeleted)); } + if (!Files.exists(directoryToBeDeleted)) { + return; + } Files.walkFileTree(directoryToBeDeleted, new SimpleFileVisitor() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { @@ -384,9 +387,13 @@ public FileVisitResult postVisitDirectory(Path dir, IOException exc) * @throws IOException Thrown if the directory can not be read */ public static long getFileCount(Path dir) throws IOException { - return Files.walk(dir) - .parallel() - .filter(p -> !p.toFile().isDirectory()) - .count(); + if (Files.exists(dir)) { + return Files.walk(dir) + .parallel() + .filter(p -> !p.toFile().isDirectory()) + .count(); + } else { + return 0; + } } }