From 895d394565a2869cde410d26975c6799bd6e616b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 23 Jan 2014 17:20:58 +0100 Subject: [PATCH] Added command line option "--preferences-file" to manually set the path of preferences. --- app/src/processing/app/Base.java | 9 +++- app/src/processing/app/Preferences.java | 56 ++++++++++--------------- 2 files changed, 31 insertions(+), 34 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 4d4eeeb5f..f3101eb65 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -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); diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 294c07603..68cc27698 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -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(table); - // Load a prefs file if specified on the command line - if (commandLinePrefs != null) { - try { - load(new FileInputStream(commandLinePrefs)); + // next load user preferences file + preferencesFile = Base.getSettingsFile(PREFS_FILE); - } catch (Exception poe) { - Base.showError(_("Error"), - I18n.format( - _("Could not read preferences from {0}"), - commandLinePrefs - ), poe); + // 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]); } - } else if (!Base.isCommandLine()) { - // next load user preferences file - preferencesFile = Base.getSettingsFile(PREFS_FILE); - 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); - } + 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); } }