@@ -2212,29 +2212,50 @@ static public InputStream getLibStream(String filename) throws IOException {
22122212 * something similar on Windows, a dot folder on Linux.) Removed this as a
22132213 * preference for 3.0a3 because we need this to be stable, but adding back
22142214 * for 4.0 beta 4 so that folks can do 'portable' versions again.
2215+ *
2216+ * @deprecated use processing.utils.Settings.getFolder() instead, this method will invoke AWT
22152217 */
22162218 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- }
2219+ try {
2220+ return processing .utils .Settings .getFolder ();
2221+ } catch (processing .utils .Settings .SettingsFolderException e ) {
2222+ switch (e .getType ()) {
2223+ case COULD_NOT_CREATE_FOLDER -> Messages .showError ("Settings issues" ,
2224+ """
2225+ Processing cannot run because it could not
2226+ create a folder to store your settings at
2227+ """ + e .getMessage (), null );
2228+ case WINDOWS_APPDATA_NOT_FOUND -> Messages .showError ("Settings issues" ,
2229+ """
2230+ Processing cannot run because it could not
2231+ find the AppData or LocalAppData folder on your system.
2232+ """ , null );
2233+ case MACOS_LIBRARY_FOLDER_NOT_FOUND -> Messages .showError ("Settings issues" ,
2234+ """
2235+ Processing cannot run because it could not
2236+ find the Library folder on your system.
2237+ """ , null );
2238+ case LINUX_CONFIG_FOLDER_NOT_FOUND -> Messages .showError ("Settings issues" ,
2239+ """
2240+ Processing cannot run because either your
2241+ XDG_CONFIG_HOME or SNAP_USER_COMMON is set
2242+ but the folder does not exist.
2243+ """ , null );
2244+ case LINUX_SUDO_USER_ERROR -> Messages .showError ("Settings issues" ,
2245+ """
2246+ Processing cannot run because it was started
2247+ with sudo and Processing could not resolve
2248+ the original users home directory.
2249+ """ , null );
2250+ default -> Messages .showTrace ("An rare and unknowable thing happened" ,
2251+ """
2252+ Could not get the settings folder. Please report:
2253+ http://github.com/processing/processing4/issues/new
2254+ """ ,
2255+ e , true );
2256+ }
22302257 }
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 ;
2258+ throw new RuntimeException ("Unreachable code in Base.getSettingsFolder()" );
22382259 }
22392260
22402261
0 commit comments