Skip to content

Commit 895d394

Browse files
Cristian MaglieCristian Maglie
Cristian Maglie
authored and
Cristian Maglie
committed
Added command line option "--preferences-file" to manually set the path of preferences.
1 parent dd02dcf commit 895d394

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

app/src/processing/app/Base.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static public void main(String args[]) throws Exception {
140140
portableFolder = null;
141141

142142
// run static initialization that grabs all the prefs
143-
Preferences.init(null);
143+
Preferences.init(args);
144144

145145
try {
146146
File versionFile = getContentFile("lib/version.txt");
@@ -368,6 +368,13 @@ public Base(String[] args) throws Exception {
368368
processPrefArgument(args[i]);
369369
continue;
370370
}
371+
if (args[i].equals("--preferences-file")) {
372+
i++;
373+
if (i >= args.length)
374+
showError(null, "Argument required for --preferences-file", 3);
375+
// Argument should be already processed by Preferences.init(...)
376+
continue;
377+
}
371378
if (args[i].startsWith("--"))
372379
showError(null, I18n.format(_("unknown option: {0}"), args[i]), 3);
373380

app/src/processing/app/Preferences.java

+25-35
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ public String toString() {
218218
static File preferencesFile;
219219

220220

221-
static protected void init(String commandLinePrefs) {
221+
static protected void init(String args[]) {
222222

223223
// start by loading the defaults, in case something
224224
// important was deleted from the user prefs
@@ -250,41 +250,31 @@ static protected void init(String commandLinePrefs) {
250250
// clone the hash table
251251
defaults = new Hashtable<String, String>(table);
252252

253-
// Load a prefs file if specified on the command line
254-
if (commandLinePrefs != null) {
255-
try {
256-
load(new FileInputStream(commandLinePrefs));
257-
258-
} catch (Exception poe) {
259-
Base.showError(_("Error"),
260-
I18n.format(
261-
_("Could not read preferences from {0}"),
262-
commandLinePrefs
263-
), poe);
253+
// next load user preferences file
254+
preferencesFile = Base.getSettingsFile(PREFS_FILE);
255+
256+
// load a preferences file if specified on the command line
257+
if (args != null) {
258+
for (int i = 0; i < args.length - 1; i++) {
259+
if (args[i].equals("--preferences-file"))
260+
preferencesFile = new File(args[i + 1]);
264261
}
265-
} else if (!Base.isCommandLine()) {
266-
// next load user preferences file
267-
preferencesFile = Base.getSettingsFile(PREFS_FILE);
268-
if (!preferencesFile.exists()) {
269-
// create a new preferences file if none exists
270-
// saves the defaults out to the file
271-
save();
272-
273-
} else {
274-
// load the previous preferences file
275-
276-
try {
277-
load(new FileInputStream(preferencesFile));
278-
279-
} catch (Exception ex) {
280-
Base.showError(_("Error reading preferences"),
281-
I18n.format(
282-
_("Error reading the preferences file. " +
283-
"Please delete (or move)\n" +
284-
"{0} and restart Arduino."),
285-
preferencesFile.getAbsolutePath()
286-
), ex);
287-
}
262+
}
263+
264+
if (!preferencesFile.exists()) {
265+
// create a new preferences file if none exists
266+
// saves the defaults out to the file
267+
save();
268+
} else {
269+
// load the previous preferences file
270+
try {
271+
load(new FileInputStream(preferencesFile));
272+
} catch (Exception ex) {
273+
Base.showError(_("Error reading preferences"),
274+
I18n.format(_("Error reading the preferences file. "
275+
+ "Please delete (or move)\n"
276+
+ "{0} and restart Arduino."),
277+
preferencesFile.getAbsolutePath()), ex);
288278
}
289279
}
290280

0 commit comments

Comments
 (0)