|
23 | 23 |
|
24 | 24 | package processing.app; |
25 | 25 |
|
26 | | -import java.awt.*; |
27 | | -import java.awt.event.ActionListener; |
28 | | -import java.io.*; |
29 | | -import java.lang.reflect.InvocationTargetException; |
30 | | -import java.util.*; |
31 | | -import java.util.List; |
32 | | -import java.util.Map.Entry; |
33 | | - |
34 | | -import javax.swing.*; |
35 | | -import javax.swing.tree.DefaultMutableTreeNode; |
36 | | - |
37 | 26 | import com.formdev.flatlaf.FlatDarkLaf; |
38 | 27 | import com.formdev.flatlaf.FlatLaf; |
39 | 28 | import com.formdev.flatlaf.FlatLightLaf; |
40 | 29 | import processing.app.contrib.*; |
41 | 30 | import processing.app.tools.Tool; |
42 | 31 | import processing.app.ui.*; |
43 | 32 | import processing.app.ui.Toolkit; |
44 | | -import processing.core.*; |
| 33 | +import processing.core.PApplet; |
45 | 34 | import processing.data.StringList; |
46 | 35 |
|
| 36 | +import javax.swing.*; |
| 37 | +import javax.swing.tree.DefaultMutableTreeNode; |
| 38 | +import java.awt.*; |
| 39 | +import java.awt.event.ActionListener; |
| 40 | +import java.io.File; |
| 41 | +import java.io.FileInputStream; |
| 42 | +import java.io.IOException; |
| 43 | +import java.io.InputStream; |
| 44 | +import java.lang.reflect.InvocationTargetException; |
| 45 | +import java.util.*; |
| 46 | +import java.util.List; |
| 47 | +import java.util.Map.Entry; |
| 48 | + |
47 | 49 | /** |
48 | 50 | * The base class for the main processing application. |
49 | 51 | * Primary role of this class is for platform identification and |
@@ -2212,29 +2214,50 @@ static public InputStream getLibStream(String filename) throws IOException { |
2212 | 2214 | * something similar on Windows, a dot folder on Linux.) Removed this as a |
2213 | 2215 | * preference for 3.0a3 because we need this to be stable, but adding back |
2214 | 2216 | * for 4.0 beta 4 so that folks can do 'portable' versions again. |
| 2217 | + * |
| 2218 | + * @deprecated use processing.utils.Settings.getFolder() instead, this method will invoke AWT |
2215 | 2219 | */ |
2216 | 2220 | static public File getSettingsFolder() { |
2217 | | - File settingsFolder = null; |
2218 | | - |
2219 | | - try { |
2220 | | - settingsFolder = Platform.getSettingsFolder(); |
2221 | | - |
2222 | | - // create the folder if it doesn't exist already |
2223 | | - if (!settingsFolder.exists()) { |
2224 | | - if (!settingsFolder.mkdirs()) { |
2225 | | - Messages.showError("Settings issues", |
2226 | | - "Processing cannot run because it could not\n" + |
2227 | | - "create a folder to store your settings at\n" + |
2228 | | - settingsFolder, null); |
2229 | | - } |
| 2221 | + try { |
| 2222 | + return processing.utils.Settings.getFolder(); |
| 2223 | + } catch (processing.utils.Settings.SettingsFolderException e) { |
| 2224 | + switch (e.getType()) { |
| 2225 | + case COULD_NOT_CREATE_FOLDER -> Messages.showError("Settings issues", |
| 2226 | + """ |
| 2227 | + Processing cannot run because it could not |
| 2228 | + create a folder to store your settings at |
| 2229 | + """ + e.getMessage(), null); |
| 2230 | + case WINDOWS_APPDATA_NOT_FOUND -> Messages.showError("Settings issues", |
| 2231 | + """ |
| 2232 | + Processing cannot run because it could not |
| 2233 | + find the AppData or LocalAppData folder on your system. |
| 2234 | + """, null); |
| 2235 | + case MACOS_LIBRARY_FOLDER_NOT_FOUND -> Messages.showError("Settings issues", |
| 2236 | + """ |
| 2237 | + Processing cannot run because it could not |
| 2238 | + find the Library folder on your system. |
| 2239 | + """, null); |
| 2240 | + case LINUX_CONFIG_FOLDER_NOT_FOUND -> Messages.showError("Settings issues", |
| 2241 | + """ |
| 2242 | + Processing cannot run because either your |
| 2243 | + XDG_CONFIG_HOME or SNAP_USER_COMMON is set |
| 2244 | + but the folder does not exist. |
| 2245 | + """, null); |
| 2246 | + case LINUX_SUDO_USER_ERROR -> Messages.showError("Settings issues", |
| 2247 | + """ |
| 2248 | + Processing cannot run because it was started |
| 2249 | + with sudo and Processing could not resolve |
| 2250 | + the original users home directory. |
| 2251 | + """, null); |
| 2252 | + default -> Messages.showTrace("An rare and unknowable thing happened", |
| 2253 | + """ |
| 2254 | + Could not get the settings folder. Please report: |
| 2255 | + http://github.com/processing/processing4/issues/new |
| 2256 | + """, |
| 2257 | + e, true); |
| 2258 | + } |
2230 | 2259 | } |
2231 | | - } catch (Exception e) { |
2232 | | - Messages.showTrace("An rare and unknowable thing happened", |
2233 | | - "Could not get the settings folder. Please report:\n" + |
2234 | | - "http://github.com/processing/processing/issues/new", |
2235 | | - e, true); |
2236 | | - } |
2237 | | - return settingsFolder; |
| 2260 | + throw new RuntimeException("Unreachable code in Base.getSettingsFolder()"); |
2238 | 2261 | } |
2239 | 2262 |
|
2240 | 2263 |
|
|
0 commit comments