From 31fe4ac0c2859808339202eb8d1c172667d27f02 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Tue, 8 Apr 2014 12:39:17 +0200 Subject: [PATCH] Add Base.absoluteFile method This method takes filenames as specified on the commandline and turns them into the right File object, taking into account the current directory passed through --curdir by the wrapper script. --- app/src/processing/app/Base.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 5a948a24a..d4b567fce 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -291,6 +291,18 @@ public class Base { } } + // Returns a File object for the given pathname. If the pathname + // is not absolute, it is interpreted relative to the current + // directory when starting the IDE (which is not the same as the + // current working directory!). + static public File absoluteFile(String path) { + File file = new File(path); + if (!file.isAbsolute()) { + file = new File(currentDirectory, path); + } + return file; + } + protected static enum ACTION { GUI, VERIFY, UPLOAD, NOOP, GET_PREF }; public Base(String[] args) throws Exception { @@ -457,12 +469,11 @@ public class Base { } } - if (!new File(path).isAbsolute()) { - path = new File(currentDirectory, path).getAbsolutePath(); - } + // Correctly resolve relative paths + File file = absoluteFile(path); boolean showEditor = (action == ACTION.GUI); - if (handleOpen(new File(path), nextEditorLocation(), showEditor) == null) { + if (handleOpen(file, nextEditorLocation(), showEditor) == null) { String mess = I18n.format(_("Failed to open sketch: \"{0}\""), path); // Open failure is fatal in upload/verify mode if (action == ACTION.VERIFY || action == ACTION.UPLOAD)