From 785205143e9afca31ea335864b1255296fde3d90 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 10 Aug 2018 20:04:50 +0200 Subject: [PATCH 1/3] Added preferences.txt option to disable preferences save Fix #5668 --- arduino-core/src/processing/app/PreferencesData.java | 3 +++ build/shared/lib/preferences.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/arduino-core/src/processing/app/PreferencesData.java b/arduino-core/src/processing/app/PreferencesData.java index 6d9530f336d..84b8703573b 100644 --- a/arduino-core/src/processing/app/PreferencesData.java +++ b/arduino-core/src/processing/app/PreferencesData.java @@ -114,6 +114,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. 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 # --------------------------------- From 1401ce8271bc8f84f24e00ee4753436fb04465bb Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 10 Aug 2018 20:08:18 +0200 Subject: [PATCH 2/3] Do not crash if preferences.txt can't be written --- .../src/processing/app/PreferencesData.java | 22 +++++++++++-------- .../src/processing/app/legacy/PApplet.java | 5 +---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/arduino-core/src/processing/app/PreferencesData.java b/arduino-core/src/processing/app/PreferencesData.java index 84b8703573b..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 { @@ -136,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..b2e82e526d8 100644 --- a/arduino-core/src/processing/app/legacy/PApplet.java +++ b/arduino-core/src/processing/app/legacy/PApplet.java @@ -566,12 +566,9 @@ static public PrintWriter createWriter(File file) { 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()); + throw new RuntimeException("Couldn't create a writer for " + file.getAbsolutePath(), e); } } - //return null; } From 056817d0815f68f2768d3b6785f4254f66beab8b Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 10 Aug 2018 20:09:01 +0200 Subject: [PATCH 3/3] Simplified overly complicated error handling in PApplet.createWriter --- .../src/processing/app/legacy/PApplet.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/arduino-core/src/processing/app/legacy/PApplet.java b/arduino-core/src/processing/app/legacy/PApplet.java index b2e82e526d8..d9eea95fd12 100644 --- a/arduino-core/src/processing/app/legacy/PApplet.java +++ b/arduino-core/src/processing/app/legacy/PApplet.java @@ -552,23 +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 { - throw new RuntimeException("Couldn't create a writer for " + file.getAbsolutePath(), e); - } + } catch (IOException e) { + output.close(); + throw e; } + return createWriter(output); }