mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-18 12:54:25 +01:00
Removed dependency from Base in PreferencesData.
This commit is contained in:
parent
fa0d37dad6
commit
d6bd77ec2b
@ -36,6 +36,7 @@ import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.helpers.FileUtils;
|
||||
import processing.app.helpers.GUINotifier;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.filefilters.OnlyDirs;
|
||||
@ -104,6 +105,8 @@ public class Base {
|
||||
|
||||
static public void main(String args[]) throws Exception {
|
||||
BaseNoGui.initLogger();
|
||||
|
||||
BaseNoGui.notifier = new GUINotifier();
|
||||
|
||||
initPlatform();
|
||||
|
||||
@ -1850,33 +1853,7 @@ public class Base {
|
||||
|
||||
|
||||
static public File getSettingsFolder() {
|
||||
if (BaseNoGui.getPortableFolder() != null)
|
||||
return BaseNoGui.getPortableFolder();
|
||||
|
||||
File settingsFolder = null;
|
||||
|
||||
String preferencesPath = Preferences.get("settings.path");
|
||||
if (preferencesPath != null) {
|
||||
settingsFolder = absoluteFile(preferencesPath);
|
||||
|
||||
} else {
|
||||
try {
|
||||
settingsFolder = getPlatform().getSettingsFolder();
|
||||
} catch (Exception e) {
|
||||
showError(_("Problem getting data folder"),
|
||||
_("Error getting the Arduino data folder."), e);
|
||||
}
|
||||
}
|
||||
|
||||
// create the folder if it doesn't exist already
|
||||
if (!settingsFolder.exists()) {
|
||||
if (!settingsFolder.mkdirs()) {
|
||||
showError(_("Settings issues"),
|
||||
_("Arduino cannot run because it could not\n" +
|
||||
"create a folder to store your settings."), null);
|
||||
}
|
||||
}
|
||||
return settingsFolder;
|
||||
return BaseNoGui.getSettingsFolder();
|
||||
}
|
||||
|
||||
|
||||
@ -1888,7 +1865,7 @@ public class Base {
|
||||
* @return filename wrapped as a File object inside the settings folder
|
||||
*/
|
||||
static public File getSettingsFile(String filename) {
|
||||
return new File(getSettingsFolder(), filename);
|
||||
return BaseNoGui.getSettingsFile(filename);
|
||||
}
|
||||
|
||||
|
||||
@ -2323,17 +2300,7 @@ public class Base {
|
||||
* for errors that allow P5 to continue running.
|
||||
*/
|
||||
static public void showError(String title, String message, Throwable e, int exit_code) {
|
||||
if (title == null) title = _("Error");
|
||||
|
||||
if (commandLine) {
|
||||
System.err.println(title + ": " + message);
|
||||
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(new Frame(), message, title,
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
if (e != null) e.printStackTrace();
|
||||
System.exit(exit_code);
|
||||
BaseNoGui.showError(title, message, e, exit_code);
|
||||
}
|
||||
|
||||
|
||||
@ -2535,7 +2502,7 @@ public class Base {
|
||||
* Return an InputStream for a file inside the Processing lib folder.
|
||||
*/
|
||||
static public InputStream getLibStream(String filename) throws IOException {
|
||||
return new FileInputStream(new File(getContentFile("lib"), filename));
|
||||
return BaseNoGui.getLibStream(filename);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,7 +3,9 @@ package processing.app;
|
||||
import static processing.app.I18n._;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
@ -19,8 +21,10 @@ import processing.app.debug.TargetBoard;
|
||||
import processing.app.debug.TargetPackage;
|
||||
import processing.app.debug.TargetPlatform;
|
||||
import processing.app.debug.TargetPlatformException;
|
||||
import processing.app.helpers.BasicNotifier;
|
||||
import processing.app.helpers.OSUtils;
|
||||
import processing.app.helpers.PreferencesMap;
|
||||
import processing.app.helpers.UserNotifier;
|
||||
import processing.app.helpers.filefilters.OnlyDirs;
|
||||
import processing.app.helpers.filefilters.OnlyFilesWithExtension;
|
||||
import processing.app.legacy.PApplet;
|
||||
@ -45,6 +49,8 @@ public class BaseNoGui {
|
||||
// maps library name to their library folder
|
||||
static private LibraryList libraries;
|
||||
|
||||
static UserNotifier notifier = new BasicNotifier();
|
||||
|
||||
static public Map<String, TargetPackage> packages;
|
||||
|
||||
static Platform platform;
|
||||
@ -126,6 +132,13 @@ public class BaseNoGui {
|
||||
return libraries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an InputStream for a file inside the Processing lib folder.
|
||||
*/
|
||||
static public InputStream getLibStream(String filename) throws IOException {
|
||||
return new FileInputStream(new File(getContentFile("lib"), filename));
|
||||
}
|
||||
|
||||
static public Platform getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
@ -134,6 +147,47 @@ public class BaseNoGui {
|
||||
return portableFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method to get a File object for the specified filename inside
|
||||
* the settings folder.
|
||||
* For now, only used by Preferences to get the preferences.txt file.
|
||||
* @param filename A file inside the settings folder.
|
||||
* @return filename wrapped as a File object inside the settings folder
|
||||
*/
|
||||
static public File getSettingsFile(String filename) {
|
||||
return new File(getSettingsFolder(), filename);
|
||||
}
|
||||
|
||||
static public File getSettingsFolder() {
|
||||
if (BaseNoGui.getPortableFolder() != null)
|
||||
return BaseNoGui.getPortableFolder();
|
||||
|
||||
File settingsFolder = null;
|
||||
|
||||
String preferencesPath = Preferences.get("settings.path");
|
||||
if (preferencesPath != null) {
|
||||
settingsFolder = absoluteFile(preferencesPath);
|
||||
|
||||
} else {
|
||||
try {
|
||||
settingsFolder = getPlatform().getSettingsFolder();
|
||||
} catch (Exception e) {
|
||||
showError(_("Problem getting data folder"),
|
||||
_("Error getting the Arduino data folder."), e);
|
||||
}
|
||||
}
|
||||
|
||||
// create the folder if it doesn't exist already
|
||||
if (!settingsFolder.exists()) {
|
||||
if (!settingsFolder.mkdirs()) {
|
||||
showError(_("Settings issues"),
|
||||
_("Arduino cannot run because it could not\n" +
|
||||
"create a folder to store your settings."), null);
|
||||
}
|
||||
}
|
||||
return settingsFolder;
|
||||
}
|
||||
|
||||
static public File getSketchbookFolder() {
|
||||
if (portableFolder != null)
|
||||
return new File(portableFolder, Preferences.get("sketchbook.path"));
|
||||
@ -376,4 +430,17 @@ public class BaseNoGui {
|
||||
return res;
|
||||
}
|
||||
|
||||
static public void showError(String title, String message, Throwable e) {
|
||||
notifier.showError(title, message, e, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an error message that's actually fatal to the program.
|
||||
* This is an error that can't be recovered. Use showWarning()
|
||||
* for errors that allow P5 to continue running.
|
||||
*/
|
||||
static public void showError(String title, String message, Throwable e, int exit_code) {
|
||||
notifier.showError(title, message, e, exit_code);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,21 +32,21 @@ public class PreferencesData {
|
||||
if (file != null)
|
||||
preferencesFile = file;
|
||||
else
|
||||
preferencesFile = Base.getSettingsFile(Preferences.PREFS_FILE);
|
||||
preferencesFile = BaseNoGui.getSettingsFile(PREFS_FILE);
|
||||
|
||||
// start by loading the defaults, in case something
|
||||
// important was deleted from the user prefs
|
||||
try {
|
||||
prefs.load(Base.getLibStream("preferences.txt"));
|
||||
prefs.load(BaseNoGui.getLibStream("preferences.txt"));
|
||||
} catch (IOException e) {
|
||||
Base.showError(null, _("Could not read default settings.\n" +
|
||||
"You'll need to reinstall Arduino."), e);
|
||||
BaseNoGui.showError(null, _("Could not read default settings.\n" +
|
||||
"You'll need to reinstall Arduino."), e);
|
||||
}
|
||||
|
||||
// set some runtime constants (not saved on preferences file)
|
||||
File hardwareFolder = Base.getHardwareFolder();
|
||||
File hardwareFolder = BaseNoGui.getHardwareFolder();
|
||||
prefs.put("runtime.ide.path", hardwareFolder.getParentFile().getAbsolutePath());
|
||||
prefs.put("runtime.ide.version", "" + Base.REVISION);
|
||||
prefs.put("runtime.ide.version", "" + BaseNoGui.REVISION);
|
||||
|
||||
// clone the hash table
|
||||
defaults = new PreferencesMap(prefs);
|
||||
@ -56,11 +56,11 @@ public class PreferencesData {
|
||||
try {
|
||||
prefs.load(preferencesFile);
|
||||
} catch (IOException ex) {
|
||||
Base.showError(_("Error reading preferences"),
|
||||
I18n.format(_("Error reading the preferences file. "
|
||||
+ "Please delete (or move)\n"
|
||||
+ "{0} and restart Arduino."),
|
||||
preferencesFile.getAbsolutePath()), ex);
|
||||
BaseNoGui.showError(_("Error reading preferences"),
|
||||
I18n.format(_("Error reading the preferences file. "
|
||||
+ "Please delete (or move)\n"
|
||||
+ "{0} and restart Arduino."),
|
||||
preferencesFile.getAbsolutePath()), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user