From 256026bfeb5519564188ed6bff8e25cf8b353c35 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 30 Jun 2022 22:10:11 +0200 Subject: [PATCH] Fixed: NoSuchFileException got thrown when export folder should be deleted but did not exist --- changelog.md | 1 + .../mgt2mt/data_stream/DataStreamHelper.java | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) 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; + } } }