Skip to content

Commit 5b690b9

Browse files
committed
Win32: use legacy SHGetFolderPath if SHGetKnownFolderPath is not available
This ensure windows XP compatibility
1 parent 7134056 commit 5b690b9

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

arduino-core/src/cc/arduino/os/windows/Win32KnownFolders.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,37 @@
3838
import java.nio.file.Paths;
3939

4040
import com.sun.jna.platform.win32.Shell32Util;
41+
import com.sun.jna.platform.win32.ShlObj;
4142

4243
import processing.app.PreferencesData;
4344

4445
public class Win32KnownFolders {
4546

4647
public static File getLocalAppDataFolder() {
47-
return new File(Shell32Util.getKnownFolderPath(FOLDERID_LocalAppData));
48+
try {
49+
return new File(Shell32Util.getKnownFolderPath(FOLDERID_LocalAppData));
50+
} catch (Throwable t) {
51+
// Ignore error if API call is not available
52+
}
53+
return new File(Shell32Util.getFolderPath(ShlObj.CSIDL_LOCAL_APPDATA));
4854
}
4955

5056
public static File getRoamingAppDataFolder() {
51-
return new File(Shell32Util.getKnownFolderPath(FOLDERID_RoamingAppData));
57+
try {
58+
return new File(Shell32Util.getKnownFolderPath(FOLDERID_RoamingAppData));
59+
} catch (Throwable t) {
60+
// Ignore error if API call is not available
61+
}
62+
return new File(Shell32Util.getFolderPath(ShlObj.CSIDL_APPDATA));
5263
}
5364

5465
public static File getDocumentsFolder() {
66+
try {
5567
return new File(Shell32Util.getKnownFolderPath(FOLDERID_Documents));
68+
} catch (Throwable t) {
69+
// Ignore error if API call is not available
70+
}
71+
return new File(Shell32Util.getFolderPath(ShlObj.CSIDL_MYDOCUMENTS));
5672
}
5773

5874
public static File getLocalCacheFolder() throws FileNotFoundException {

0 commit comments

Comments
 (0)