diff --git a/arduino-core/src/processing/app/PreferencesData.java b/arduino-core/src/processing/app/PreferencesData.java index 6d9530f336d..8ab4852b0b9 100644 --- a/arduino-core/src/processing/app/PreferencesData.java +++ b/arduino-core/src/processing/app/PreferencesData.java @@ -1,14 +1,9 @@ package processing.app; -import org.apache.commons.compress.utils.IOUtils; - -import cc.arduino.i18n.Languages; -import processing.app.helpers.PreferencesHelper; -import processing.app.helpers.PreferencesMap; -import processing.app.legacy.PApplet; -import processing.app.legacy.PConstants; +import static processing.app.I18n.format; +import static processing.app.I18n.tr; -import java.awt.*; +import java.awt.Font; import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -18,7 +13,13 @@ import java.util.MissingResourceException; import java.util.stream.Collectors; -import static processing.app.I18n.tr; +import org.apache.commons.compress.utils.IOUtils; + +import cc.arduino.i18n.Languages; +import processing.app.helpers.PreferencesHelper; +import processing.app.helpers.PreferencesMap; +import processing.app.legacy.PApplet; +import processing.app.legacy.PConstants; public class PreferencesData { @@ -114,6 +115,9 @@ static protected void save() { if (!doSave) return; + if (getBoolean("preferences.readonly")) + return; + // on startup, don't worry about it // this is trying to update the prefs for who is open // before Preferences.init() has been called. @@ -133,6 +137,9 @@ static protected void save() { } writer.flush(); + } catch (Throwable e) { + System.err.println(format(tr("Could not write preferences file: {0}"), e.getMessage())); + return; } finally { IOUtils.closeQuietly(writer); } diff --git a/arduino-core/src/processing/app/legacy/PApplet.java b/arduino-core/src/processing/app/legacy/PApplet.java index 23010a42b27..d9eea95fd12 100644 --- a/arduino-core/src/processing/app/legacy/PApplet.java +++ b/arduino-core/src/processing/app/legacy/PApplet.java @@ -552,26 +552,20 @@ static final public String[] str(int x[]) { /** * I want to print lines to a file. I have RSI from typing these * eight lines of code so many times. + * @throws IOException */ - static public PrintWriter createWriter(File file) { + static public PrintWriter createWriter(File file) throws IOException { + createPath(file); // make sure in-between folders exist + OutputStream output = new FileOutputStream(file); try { - createPath(file); // make sure in-between folders exist - OutputStream output = new FileOutputStream(file); if (file.getName().toLowerCase().endsWith(".gz")) { output = new GZIPOutputStream(output); } - return createWriter(output); - - } catch (Exception e) { - if (file == null) { - throw new RuntimeException("File passed to createWriter() was null"); - } else { - e.printStackTrace(); - throw new RuntimeException("Couldn't create a writer for " + - file.getAbsolutePath()); - } + } catch (IOException e) { + output.close(); + throw e; } - //return null; + return createWriter(output); } diff --git a/build/shared/lib/preferences.txt b/build/shared/lib/preferences.txt index f442cdb3e66..e777627af3d 100644 --- a/build/shared/lib/preferences.txt +++ b/build/shared/lib/preferences.txt @@ -279,6 +279,9 @@ serial.line_ending=1 # default chosen language (none for none) editor.languages.current = +# Disable saving of preferences.txt file (settings will not survive Arduino IDE reboot) +preferences.readonly=false + # Debugging/Development Preferences # ---------------------------------