mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
Added command line option "--preferences-file" to manually set the path of preferences.
This commit is contained in:
parent
dd02dcffab
commit
895d394565
@ -140,7 +140,7 @@ public class Base {
|
||||
portableFolder = null;
|
||||
|
||||
// run static initialization that grabs all the prefs
|
||||
Preferences.init(null);
|
||||
Preferences.init(args);
|
||||
|
||||
try {
|
||||
File versionFile = getContentFile("lib/version.txt");
|
||||
@ -368,6 +368,13 @@ public class Base {
|
||||
processPrefArgument(args[i]);
|
||||
continue;
|
||||
}
|
||||
if (args[i].equals("--preferences-file")) {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
showError(null, "Argument required for --preferences-file", 3);
|
||||
// Argument should be already processed by Preferences.init(...)
|
||||
continue;
|
||||
}
|
||||
if (args[i].startsWith("--"))
|
||||
showError(null, I18n.format(_("unknown option: {0}"), args[i]), 3);
|
||||
|
||||
|
@ -218,7 +218,7 @@ public class Preferences {
|
||||
static File preferencesFile;
|
||||
|
||||
|
||||
static protected void init(String commandLinePrefs) {
|
||||
static protected void init(String args[]) {
|
||||
|
||||
// start by loading the defaults, in case something
|
||||
// important was deleted from the user prefs
|
||||
@ -250,41 +250,31 @@ public class Preferences {
|
||||
// clone the hash table
|
||||
defaults = new Hashtable<String, String>(table);
|
||||
|
||||
// Load a prefs file if specified on the command line
|
||||
if (commandLinePrefs != null) {
|
||||
try {
|
||||
load(new FileInputStream(commandLinePrefs));
|
||||
|
||||
} catch (Exception poe) {
|
||||
Base.showError(_("Error"),
|
||||
I18n.format(
|
||||
_("Could not read preferences from {0}"),
|
||||
commandLinePrefs
|
||||
), poe);
|
||||
}
|
||||
} else if (!Base.isCommandLine()) {
|
||||
// next load user preferences file
|
||||
preferencesFile = Base.getSettingsFile(PREFS_FILE);
|
||||
|
||||
// load a preferences file if specified on the command line
|
||||
if (args != null) {
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
if (args[i].equals("--preferences-file"))
|
||||
preferencesFile = new File(args[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (!preferencesFile.exists()) {
|
||||
// create a new preferences file if none exists
|
||||
// saves the defaults out to the file
|
||||
save();
|
||||
|
||||
} else {
|
||||
// load the previous preferences file
|
||||
|
||||
try {
|
||||
load(new FileInputStream(preferencesFile));
|
||||
|
||||
} catch (Exception 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);
|
||||
}
|
||||
I18n.format(_("Error reading the preferences file. "
|
||||
+ "Please delete (or move)\n"
|
||||
+ "{0} and restart Arduino."),
|
||||
preferencesFile.getAbsolutePath()), ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user