| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 962ef24 commit 44ab414
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1726,20 +1726,20 @@ static public File getSettingsFolder() { | |||
| 1726 | 1726 | ||
| 1727 | 1727 | try { | |
| 1728 | 1728 | settingsFolder = Platform.getSettingsFolder(); | |
| 1729 | + | ||
| 1730 | + // create the folder if it doesn't exist already | ||
| 1731 | + if (!settingsFolder.exists()) { | ||
| 1732 | + if (!settingsFolder.mkdirs()) { | ||
| 1733 | + Messages.showError("Settings issues", | ||
| 1734 | + "Processing cannot run because it could not\n" + | ||
| 1735 | + "create a folder to store your settings.\n" + | ||
| 1736 | + settingsFolder.getAbsolutePath(), null); | ||
| 1737 | + } | ||
| 1738 | + } | ||
| 1729 | 1739 | } catch (Exception e) { | |
| 1730 | 1740 | Messages.showError("Problem getting the settings folder", | |
| 1731 | 1741 | "Error getting the Processing the settings folder.", e); | |
| 1732 | 1742 | } | |
| 1733 | - | ||
| 1734 | - // create the folder if it doesn't exist already | ||
| 1735 | - if (!settingsFolder.exists()) { | ||
| 1736 | - if (!settingsFolder.mkdirs()) { | ||
| 1737 | - Messages.showError("Settings issues", | ||
| 1738 | - "Processing cannot run because it could not\n" + | ||
| 1739 | - "create a folder to store your settings.\n" + | ||
| 1740 | - settingsFolder.getAbsolutePath(), null); | ||
| 1741 | - } | ||
| 1742 | - } | ||
| 1743 | 1743 | return settingsFolder; | |
| 1744 | 1744 | } | |
| 1745 | 1745 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,19 +28,14 @@ | |||
| 28 | 28 | ||
| 29 | 29 | import com.sun.jna.Library; | |
| 30 | 30 | import com.sun.jna.Native; | |
| 31 | - import com.sun.jna.platform.win32.Kernel32Util; | ||
| 32 | - import com.sun.jna.platform.win32.Shell32; | ||
| 33 | 31 | import com.sun.jna.platform.win32.Shell32Util; | |
| 34 | 32 | import com.sun.jna.platform.win32.ShlObj; | |
| 35 | - import com.sun.jna.platform.win32.WinDef; | ||
| 36 | - import com.sun.jna.platform.win32.WinError; | ||
| 37 | - import com.sun.jna.platform.win32.WinNT.HRESULT; | ||
| 38 | 33 | ||
| 39 | 34 | import processing.app.Base; | |
| 40 | 35 | import processing.app.Messages; | |
| 41 | 36 | import processing.app.Preferences; | |
| 42 | - import processing.app.platform.DefaultPlatform; | ||
| 43 | 37 | import processing.app.platform.WindowsRegistry.REGISTRY_ROOT_KEY; | |
| 38 | + | ||
| 44 | 39 | import processing.core.PApplet; | |
| 45 | 40 | ||
| 46 | 41 | ||
@@ -260,11 +255,29 @@ protected void checkPath() { | |||
| 260 | 255 | ||
| 261 | 256 | // looking for Documents and Settings/blah/Application Data/Processing | |
| 262 | 257 | public File getSettingsFolder() throws Exception { | |
| 263 | - String appData = getAppDataPath(); | ||
| 264 | - if (appData != null) { | ||
| 265 | - return new File(appData, APP_NAME); | ||
| 258 | + String appDataRoaming = getAppDataPath(); | ||
| 259 | + if (appDataRoaming != null) { | ||
| 260 | + File settingsFolder = new File(appDataRoaming, APP_NAME); | ||
| 261 | + if (settingsFolder.exists() || settingsFolder.mkdirs()) { | ||
| 262 | + return settingsFolder; | ||
| 263 | + } | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + String appDataLocal = getLocalAppDataPath(); | ||
| 267 | + if (appDataLocal != null) { | ||
| 268 | + File settingsFolder = new File(appDataLocal, APP_NAME); | ||
| 269 | + if (settingsFolder.exists() || settingsFolder.mkdirs()) { | ||
| 270 | + return settingsFolder; | ||
| 271 | + } | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + if (appDataRoaming == null && appDataLocal == null) { | ||
| 275 | + throw new IOException("Could not get the AppData folder"); | ||
| 266 | 276 | } | |
| 267 | - throw new IOException("Could not get the Application Data folder"); | ||
| 277 | + | ||
| 278 | + // https://github.com/processing/processing/issues/3838 | ||
| 279 | + throw new IOException("Please fix permissions for either " + | ||
| 280 | + appDataRoaming + " or " + appDataLocal); | ||
| 268 | 281 | } | |
| 269 | 282 | ||
| 270 | 283 | ||
@@ -279,31 +292,21 @@ public File getSettingsFolder() throws Exception { | |||
| 279 | 292 | ||
| 280 | 293 | http://blogs.msdn.com/b/patricka/archive/2010/03/18/where-should-i-store-my-data-and-configuration-files-if-i-target-multiple-os-versions.aspx | |
| 281 | 294 | */ | |
| 295 | + | ||
| 296 | + | ||
| 297 | + /** Get the Users\name\AppData\Roaming path to write settings files. */ | ||
| 282 | 298 | static private String getAppDataPath() throws Exception { | |
| 283 | 299 | return Shell32Util.getSpecialFolderPath(ShlObj.CSIDL_APPDATA, true); | |
| 300 | + } | ||
| 284 | 301 | ||
| 285 | - /* | ||
| 286 | - // this will be contain the path if SHGetFolderPath is successful | ||
| 287 | - char[] pszPath = new char[WinDef.MAX_PATH]; | ||
| 288 | - HRESULT hResult = | ||
| 289 | - Shell32.INSTANCE.SHGetFolderPath(null, ShlObj.CSIDL_APPDATA, | ||
| 290 | - null, ShlObj.SHGFP_TYPE_CURRENT, | ||
| 291 | - pszPath); | ||
| 292 | - | ||
| 293 | - if (!hResult.equals(WinError.S_OK)) { | ||
| 294 | - //System.err.println(Kernel32Util.formatMessageFromHR(hResult)); | ||
| 295 | - //throw new Exception("Problem city, population: your computer."); | ||
| 296 | - throw new Exception(Kernel32Util.formatMessageFromHR(hResult)); | ||
| 297 | - } | ||
| 298 | 302 | ||
| 299 | - String appDataPath = new String(pszPath); | ||
| 300 | - int len = appDataPath.indexOf("\0"); | ||
| 301 | - return appDataPath.substring(0, len); | ||
| 302 | - */ | ||
| 303 | + /** Get the Users\name\AppData\Local path as a settings fallback. */ | ||
| 304 | + static private String getLocalAppDataPath() throws Exception { | ||
| 305 | + return Shell32Util.getSpecialFolderPath(ShlObj.CSIDL_LOCAL_APPDATA, true); | ||
| 303 | 306 | } | |
| 304 | 307 | ||
| 305 | 308 | ||
| 306 | - // looking for Documents and Settings/blah/My Documents/Processing | ||
| 309 | + /** Get the Documents and Settings\name\My Documents\Processing folder. */ | ||
| 307 | 310 | public File getDefaultSketchbookFolder() throws Exception { | |
| 308 | 311 | String documentsPath = getDocumentsPath(); | |
| 309 | 312 | if (documentsPath != null) { | |
@@ -313,6 +316,12 @@ public File getDefaultSketchbookFolder() throws Exception { | |||
| 313 | 316 | } | |
| 314 | 317 | ||
| 315 | 318 | ||
| 319 | + static private String getDocumentsPath() throws Exception { | ||
| 320 | + return Shell32Util.getSpecialFolderPath(ShlObj.CSIDL_MYDOCUMENTS, true); | ||
| 321 | + } | ||
| 322 | + | ||
| 323 | + | ||
| 324 | + /* | ||
| 316 | 325 | static private String getDocumentsPath() throws Exception { | |
| 317 | 326 | // heh, this is a little too cheeky | |
| 318 | 327 | //new JFileChooser().getFileSystemView().getDefaultDirectory().toString(); | |
@@ -351,6 +360,7 @@ static private String getDocumentsPath() throws Exception { | |||
| 351 | 360 | int len = personalPath.indexOf("\0"); | |
| 352 | 361 | return personalPath.substring(0, len); | |
| 353 | 362 | } | |
| 363 | + */ | ||
| 354 | 364 | ||
| 355 | 365 | ||
| 356 | 366 | // @Override | |
@@ -503,6 +513,8 @@ public void openFolder(File file) throws Exception { | |||
| 503 | 513 | static WinLibC clib; | |
| 504 | 514 | ||
| 505 | 515 | ||
| 516 | + // moved to a getter so that we could handle errors in a single location | ||
| 517 | + // and at a time when it was useful/possible (rather than a static block) | ||
| 506 | 518 | static WinLibC getLibC() { | |
| 507 | 519 | if (clib == null) { | |
| 508 | 520 | try { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments