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.
This commit is contained in:
Matthijs Kooijman 2014-04-08 12:39:17 +02:00 committed by Cristian Maglie
parent 0798e1cf6f
commit 31fe4ac0c2
1 changed files with 15 additions and 4 deletions

View File

@ -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)