Moved some code from Base to BaseNoGui into new getSketchbookPath() method.

This commit is contained in:
Claudio Indellicati 2014-08-26 11:27:08 +02:00 committed by Cristian Maglie
parent 443f7a7150
commit 10af59f6fa
2 changed files with 28 additions and 22 deletions

View File

@ -220,27 +220,7 @@ public class Base {
if (OSUtils.isMacOS()) if (OSUtils.isMacOS())
ThinkDifferent.init(this); ThinkDifferent.init(this);
// Get the sketchbook path, and make sure it's set properly String sketchbookPath = BaseNoGui.getSketchbookPath();
String sketchbookPath = Preferences.get("sketchbook.path");
// If a value is at least set, first check to see if the folder exists.
// If it doesn't, warn the user that the sketchbook folder is being reset.
if (sketchbookPath != null) {
File sketchbookFolder;
if (BaseNoGui.getPortableFolder() != null)
sketchbookFolder = new File(BaseNoGui.getPortableFolder(), sketchbookPath);
else
sketchbookFolder = absoluteFile(sketchbookPath);
if (!sketchbookFolder.exists()) {
showWarning(_("Sketchbook folder disappeared"),
_("The sketchbook folder no longer exists.\n" +
"Arduino will switch to the default sketchbook\n" +
"location, and create a new sketchbook folder if\n" +
"necessary. Arduino will then stop talking about\n" +
"himself in the third person."), null);
sketchbookPath = null;
}
}
// If no path is set, get the default sketchbook folder for this platform // If no path is set, get the default sketchbook folder for this platform
if (sketchbookPath == null) { if (sketchbookPath == null) {

View File

@ -254,6 +254,32 @@ public class BaseNoGui {
return libdir; return libdir;
} }
static public String getSketchbookPath() {
// Get the sketchbook path, and make sure it's set properly
String sketchbookPath = Preferences.get("sketchbook.path");
// If a value is at least set, first check to see if the folder exists.
// If it doesn't, warn the user that the sketchbook folder is being reset.
if (sketchbookPath != null) {
File sketchbookFolder;
if (BaseNoGui.getPortableFolder() != null)
sketchbookFolder = new File(BaseNoGui.getPortableFolder(), sketchbookPath);
else
sketchbookFolder = absoluteFile(sketchbookPath);
if (!sketchbookFolder.exists()) {
showWarning(_("Sketchbook folder disappeared"),
_("The sketchbook folder no longer exists.\n" +
"Arduino will switch to the default sketchbook\n" +
"location, and create a new sketchbook folder if\n" +
"necessary. Arduino will then stop talking about\n" +
"himself in the third person."), null);
sketchbookPath = null;
}
}
return sketchbookPath;
}
public static TargetBoard getTargetBoard() { public static TargetBoard getTargetBoard() {
String boardId = PreferencesData.get("board"); String boardId = PreferencesData.get("board");
return getTargetPlatform().getBoard(boardId); return getTargetPlatform().getBoard(boardId);
@ -552,7 +578,7 @@ public class BaseNoGui {
if (targetBoard.getMenuLabel(key, value) == null) if (targetBoard.getMenuLabel(key, value) == null)
showError(null, I18n.format(_("{0}: Invalid option for \"{1}\" option for board \"{2}\""), value, key, targetBoard.getId()), 3); showError(null, I18n.format(_("{0}: Invalid option for \"{1}\" option for board \"{2}\""), value, key, targetBoard.getId()), 3);
Preferences.set("custom_" + key, targetBoard.getId() + "_" + value); PreferencesData.set("custom_" + key, targetBoard.getId() + "_" + value);
} }
} }
} }