diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index d33490323..0a5056554 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -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("--")) diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index ca3900845..3e0d564eb 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -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(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 {