Skip to content

Added preference key to disable preferences.txt saving #7879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions arduino-core/src/processing/app/PreferencesData.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
Expand Down
22 changes: 8 additions & 14 deletions arduino-core/src/processing/app/legacy/PApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand Down
3 changes: 3 additions & 0 deletions build/shared/lib/preferences.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---------------------------------

Expand Down