From 020aa5e10b59fc3c2e7a3aa5501137782f2ab5c5 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 11 Nov 2016 19:07:00 +0800 Subject: [PATCH] Resolve relative files against $HOME --- .../format/ExpressionFormatFunctions.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/source/net/filebot/format/ExpressionFormatFunctions.java b/source/net/filebot/format/ExpressionFormatFunctions.java index b3fd0c1a..701613e1 100644 --- a/source/net/filebot/format/ExpressionFormatFunctions.java +++ b/source/net/filebot/format/ExpressionFormatFunctions.java @@ -1,6 +1,8 @@ package net.filebot.format; +import static java.util.Collections.*; import static java.util.stream.Collectors.*; +import static net.filebot.Settings.*; import static net.filebot.util.RegularExpressions.*; import java.io.File; @@ -14,6 +16,8 @@ import java.util.stream.Stream; import groovy.lang.Closure; import groovy.util.XmlSlurper; +import net.filebot.ApplicationFolder; +import net.filebot.mac.MacAppUtilities; import net.filebot.util.FileUtilities; /** @@ -76,11 +80,25 @@ public class ExpressionFormatFunctions { } public static List readLines(String path) throws IOException { - return FileUtilities.readLines(new File(path)); + return FileUtilities.readLines(getFile(path)); } public static Object readXml(String path) throws Exception { - return new XmlSlurper().parse(new File(path)); + return new XmlSlurper().parse(getFile(path)); + } + + public static File getFile(String path) { + File f = new File(path); + + if (!f.isAbsolute()) { + f = ApplicationFolder.UserHome.resolve(path); + } + + if (isMacSandbox()) { + MacAppUtilities.askUnlockFolders(null, singleton(f)); + } + + return f; } }