Skip to content

Commit

Permalink
Fixed: NoSuchFileException got thrown when export folder should be de…
Browse files Browse the repository at this point in the history
…leted but did not exist
  • Loading branch information
LMH01 committed Jun 30, 2022
1 parent a4a48e3 commit 256026b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit 256026b

Please sign in to comment.