Skip to content

Commit 1a49263

Browse files
committed
add support for portable settings (resolves #360 and https://github.com/processing/processing/issues/3948)
1 parent f2e584b commit 1a49263

File tree

7 files changed

+69
-6
lines changed

7 files changed

+69
-6
lines changed

app/src/processing/app/Base.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ public class Base {
6868

6969
static private boolean commandLine;
7070

71+
/**
72+
* If settings.txt is present inside lib, it will be used to override
73+
* the location of the settings folder so that "portable" versions
74+
* of the software are possible.
75+
*/
76+
static private File settingsOverride;
77+
7178
// A single instance of the preferences window
7279
PreferencesFrame preferencesFrame;
7380

@@ -158,6 +165,35 @@ static private void createAndShowGUI(String[] args) {
158165
}
159166
}
160167

168+
// Detect settings.txt in the lib folder for portable versions
169+
File settingsFile = Platform.getContentFile("lib/settings.txt");
170+
if (settingsFile != null && settingsFile.exists()) {
171+
try {
172+
Settings portable = new Settings(settingsFile);
173+
String path = portable.get("settings.path");
174+
File folder = new File(path);
175+
boolean success = true;
176+
if (!folder.exists()) {
177+
success = folder.mkdirs();
178+
if (!success) {
179+
Messages.err("Could not create " + folder + " to store settings.");
180+
}
181+
}
182+
if (success) {
183+
if (!folder.canRead()) {
184+
Messages.err("Cannot read from " + folder);
185+
} else if (!folder.canWrite()) {
186+
Messages.err("Cannot write to " + folder);
187+
} else {
188+
settingsOverride = folder.getAbsoluteFile();
189+
}
190+
}
191+
} catch (IOException e) {
192+
Messages.err("Error while reading the settings.txt file", e);
193+
}
194+
}
195+
196+
161197
Platform.init();
162198
// call after Platform.init() because we need the settings folder
163199
Console.startup();
@@ -1946,7 +1982,8 @@ static public InputStream getLibStream(String filename) throws IOException {
19461982
/**
19471983
* Get the directory that can store settings. (Library on OS X, App Data or
19481984
* something similar on Windows, a dot folder on Linux.) Removed this as a
1949-
* preference for 3.0a3 because we need this to be stable.
1985+
* preference for 3.0a3 because we need this to be stable, but adding back
1986+
* for 4.0 beta 4 so that folks can do 'portable' versions again.
19501987
*/
19511988
static public File getSettingsFolder() {
19521989
File settingsFolder = null;
@@ -1973,6 +2010,11 @@ static public File getSettingsFolder() {
19732010
}
19742011

19752012

2013+
static public File getSettingsOverride() {
2014+
return settingsOverride;
2015+
}
2016+
2017+
19762018
/**
19772019
* Convenience method to get a File object for the specified filename inside
19782020
* the settings folder. Used to get preferences and recent sketch files.

app/src/processing/app/platform/DefaultPlatform.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,13 @@ public void saveLanguage(String languageCode) { }
166166
* Do not return null.
167167
*/
168168
public File getSettingsFolder() throws Exception {
169-
// otherwise make a .processing directory int the user's home dir
169+
File override = Base.getSettingsOverride();
170+
if (override != null) {
171+
return override;
172+
}
173+
174+
// If no subclass has a behavior, default to making a
175+
// ".processing" directory in the user's home directory.
170176
File home = new File(System.getProperty("user.home"));
171177
return new File(home, ".processing");
172178
}

app/src/processing/app/platform/LinuxPlatform.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ static public String getHomeDir(String user) throws Exception {
8787

8888
@Override
8989
public File getSettingsFolder() throws Exception {
90+
File override = Base.getSettingsOverride();
91+
if (override != null) {
92+
return override;
93+
}
94+
9095
// https://github.com/processing/processing4/issues/203
9196
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
9297

app/src/processing/app/platform/MacPlatform.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public void initBase(Base base) {
9393

9494

9595
public File getSettingsFolder() throws Exception {
96+
File override = Base.getSettingsOverride();
97+
if (override != null) {
98+
return override;
99+
}
96100
return new File(getLibraryFolder(), "Processing");
97101
}
98102

app/src/processing/app/platform/WindowsPlatform.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ protected void checkPath() {
292292

293293
// looking for Documents and Settings/blah/Application Data/Processing
294294
public File getSettingsFolder() throws Exception {
295+
File override = Base.getSettingsOverride();
296+
if (override != null) {
297+
return override;
298+
}
299+
295300
try {
296301
String appDataRoaming = getAppDataPath();
297302
if (appDataRoaming != null) {

build/shared/lib/defaults.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ recent.count = 10
7777
chooser.files.native = true
7878
# We were shutting this off on macOS because it broke Copy/Paste:
7979
# https://github.com/processing/processing/issues/1035
80+
# But removing again for 4.0 alpha 5, because the JFileChooser is awful,
81+
# and worse on Big Sur, so a bigger problem than the Copy/Paste issue.
8082
# https://github.com/processing/processing4/issues/77
81-
# But changing this for 4.0 alpha 5, because the JFileChooser is awful,
82-
# and even worse on Big Sur, and worse than the Copy/Paste issue.
8383
#chooser.files.native.macosx = false
8484

8585

todo.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ X write release notes about not moving to RSyntaxArea
2121
X https://github.com/processing/processing4/issues/355
2222
X https://github.com/processing/processing/issues/3199
2323
X https://github.com/processing/processing4/blob/master/app/src/processing/app/syntax/README.md
24+
X did we lose settings.path because it was too buggy?
25+
_ https://github.com/processing/processing/issues/3948
26+
_ https://github.com/processing/processing4/pull/360
2427

2528
windows scaling
2629
X Fix "Could not delete disable_hidpi" message on macOS/Linux after closing prefs
@@ -355,8 +358,6 @@ _ already reported?
355358
teaching
356359
_ teacher wants user input on the console
357360
_ https://github.com/processing/processing/issues/5779
358-
_ did we lose settings.path because it was too buggy?
359-
_ https://github.com/processing/processing/issues/3948
360361
_ proxy trouble with p5? since adding the system proxy?
361362
_ https://github.com/processing/processing/pull/3251/files
362363
_ larger problem thread https://github.com/processing/processing/issues/3891

0 commit comments

Comments
 (0)