mirror of
https://github.com/arduino/Arduino.git
synced 2024-11-29 10:24:12 +01:00
Parse --preferences-file in main instead of Preferences.init
Parsing commandline arguments inside Preferences isn't very elegant, this is better suited for the main function. Also, this change prepares for taking --curdir into account for --preferences-file as well.
This commit is contained in:
parent
e494f39255
commit
9e17e52f63
@ -139,8 +139,20 @@ public class Base {
|
||||
if (!portableFolder.exists())
|
||||
portableFolder = null;
|
||||
|
||||
File preferencesFile = null;
|
||||
|
||||
// Do a first pass over the commandline arguments, the rest of them
|
||||
// will be processed by the Base constructor. Note that this loop
|
||||
// does not look at the last element of args, to prevent crashing
|
||||
// when no parameter was specified to an option. Later, Base() will
|
||||
// then show an error for these.
|
||||
for (int i = 0; i < args.length - 1; i++) {
|
||||
if (args[i].equals("--preferences-file"))
|
||||
preferencesFile = new File(args[i + 1]);
|
||||
}
|
||||
|
||||
// run static initialization that grabs all the prefs
|
||||
Preferences.init(args);
|
||||
Preferences.init(preferencesFile);
|
||||
|
||||
try {
|
||||
File versionFile = getContentFile("lib/version.txt");
|
||||
@ -402,7 +414,7 @@ public class Base {
|
||||
i++;
|
||||
if (i >= args.length)
|
||||
showError(null, _("Argument required for --preferences-file"), 3);
|
||||
// Argument should be already processed by Preferences.init(...)
|
||||
// Argument should be already processed by Base.main(...)
|
||||
continue;
|
||||
}
|
||||
if (args[i].startsWith("--"))
|
||||
|
@ -223,7 +223,11 @@ public class Preferences {
|
||||
static boolean doSave = true;
|
||||
|
||||
|
||||
static protected void init(String args[]) {
|
||||
static protected void init(File file) {
|
||||
if (file != null)
|
||||
preferencesFile = file;
|
||||
else
|
||||
preferencesFile = Base.getSettingsFile(Preferences.PREFS_FILE);
|
||||
|
||||
// start by loading the defaults, in case something
|
||||
// important was deleted from the user prefs
|
||||
@ -255,17 +259,6 @@ public class Preferences {
|
||||
// clone the hash table
|
||||
defaults = new Hashtable<String, String>(table);
|
||||
|
||||
// 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()) {
|
||||
// load the previous preferences file
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user