From 5b690b9b9e31802fa5f84d87517a65e0ba70da37 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Mon, 21 Nov 2016 12:39:47 +0100 Subject: [PATCH] Win32: use legacy SHGetFolderPath if SHGetKnownFolderPath is not available This ensure windows XP compatibility --- .../arduino/os/windows/Win32KnownFolders.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/arduino-core/src/cc/arduino/os/windows/Win32KnownFolders.java b/arduino-core/src/cc/arduino/os/windows/Win32KnownFolders.java index e8f66cbf9..ce991a957 100644 --- a/arduino-core/src/cc/arduino/os/windows/Win32KnownFolders.java +++ b/arduino-core/src/cc/arduino/os/windows/Win32KnownFolders.java @@ -38,21 +38,37 @@ import java.io.FileNotFoundException; import java.nio.file.Paths; import com.sun.jna.platform.win32.Shell32Util; +import com.sun.jna.platform.win32.ShlObj; import processing.app.PreferencesData; public class Win32KnownFolders { public static File getLocalAppDataFolder() { - return new File(Shell32Util.getKnownFolderPath(FOLDERID_LocalAppData)); + try { + return new File(Shell32Util.getKnownFolderPath(FOLDERID_LocalAppData)); + } catch (Throwable t) { + // Ignore error if API call is not available + } + return new File(Shell32Util.getFolderPath(ShlObj.CSIDL_LOCAL_APPDATA)); } public static File getRoamingAppDataFolder() { - return new File(Shell32Util.getKnownFolderPath(FOLDERID_RoamingAppData)); + try { + return new File(Shell32Util.getKnownFolderPath(FOLDERID_RoamingAppData)); + } catch (Throwable t) { + // Ignore error if API call is not available + } + return new File(Shell32Util.getFolderPath(ShlObj.CSIDL_APPDATA)); } public static File getDocumentsFolder() { + try { return new File(Shell32Util.getKnownFolderPath(FOLDERID_Documents)); + } catch (Throwable t) { + // Ignore error if API call is not available + } + return new File(Shell32Util.getFolderPath(ShlObj.CSIDL_MYDOCUMENTS)); } public static File getLocalCacheFolder() throws FileNotFoundException {