From bf0cbe41f6821ccfefd18eb223f27285bb59f057 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 11 Mar 2016 11:26:59 +0000 Subject: [PATCH] Unify application folder logic --- source/net/filebot/Settings.java | 5 +---- source/net/filebot/util/FileUtilities.java | 14 +++++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/source/net/filebot/Settings.java b/source/net/filebot/Settings.java index 158fac98..5cc3dc69 100644 --- a/source/net/filebot/Settings.java +++ b/source/net/filebot/Settings.java @@ -269,10 +269,7 @@ public final class Settings { public File getCanonicalFile() { File path = get(); try { - if (!path.isDirectory()) { - createFolders(path); - } - return path.getCanonicalFile(); + return createFolders(path.getCanonicalFile()); } catch (Exception e) { debug.log(Level.SEVERE, String.format("Failed to create application folder: %s => %s", this, path), e); return path; diff --git a/source/net/filebot/util/FileUtilities.java b/source/net/filebot/util/FileUtilities.java index 989b6e44..c08cb70c 100644 --- a/source/net/filebot/util/FileUtilities.java +++ b/source/net/filebot/util/FileUtilities.java @@ -45,6 +45,8 @@ import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.io.FileUtils; + import com.ibm.icu.text.CharsetDetector; import com.ibm.icu.text.CharsetMatch; @@ -56,7 +58,7 @@ public final class FileUtilities { if (source.isDirectory()) { // move folder - org.apache.commons.io.FileUtils.moveDirectory(source, destination); + FileUtils.moveDirectory(source, destination); return destination; } @@ -80,7 +82,7 @@ public final class FileUtilities { if (source.isDirectory()) { // copy folder - org.apache.commons.io.FileUtils.copyDirectory(source, destination); + FileUtils.copyDirectory(source, destination); return destination; } @@ -156,13 +158,11 @@ public final class FileUtilities { public static boolean delete(File file) { // delete files or files - return org.apache.commons.io.FileUtils.deleteQuietly(file); + return FileUtils.deleteQuietly(file); } - public static void createFolders(File folder) throws IOException { - if (!folder.isDirectory()) { - Files.createDirectories(folder.toPath()); - } + public static File createFolders(File folder) throws IOException { + return Files.createDirectories(folder.toPath()).toFile(); } public static void createFileIfNotExists(File file) throws IOException {