@@ -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.
0 commit comments