Skip to content

Commit

Permalink
Use Java 22's foreign function API for Windows
Browse files Browse the repository at this point in the history
- Drop all existing mechanisms for retrieving this info on Windows
- This increases the required Java version of the library to 22

Fixes #49.
  • Loading branch information
brcolow authored and soc committed Oct 21, 2024
1 parent d8b2093 commit fcf0332
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 204 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
- name: Set up JDK 22
uses: actions/setup-java@v2
with:
java-version: '11'
distribution: 'adopt'
java-version: '22'
distribution: 'temurin'
- name: Run tests
run: sbt test
7 changes: 3 additions & 4 deletions src/main/java/dev/dirs/BaseDirectories.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,9 @@ private BaseDirectories() {
runtimeDir = null;
break;
case Constants.WIN:
String[] winDirs = Windows.getWinDirs("5E6C858F-0E22-4760-9AFE-EA3317B67173", "3EB685DB-65F9-4CF6-A03A-E3EF65729F3D", "F1B32785-6FBA-4FCF-9D55-7B8E7F157091");
homeDir = winDirs[0];
dataDir = winDirs[1];
dataLocalDir = winDirs[2];
homeDir = Windows.getProfileDir();
dataDir = Windows.getRoamingAppDataDir();
dataLocalDir = Windows.getLocalAppDataDir();
configDir = dataDir;
cacheDir = dataLocalDir;
executableDir = null;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/dev/dirs/ProjectDirectories.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,8 @@ public static ProjectDirectories fromPath(String path) {
preferenceDir = homeDir + "/Library/Preferences/" + path;
break;
case Constants.WIN:
String[] winDirs = Windows.getWinDirs("3EB685DB-65F9-4CF6-A03A-E3EF65729F3D", "F1B32785-6FBA-4FCF-9D55-7B8E7F157091");
String appDataRoaming = winDirs[0] + '\\' + path;
String appDataLocal = winDirs[1] + '\\' + path;
String appDataRoaming = Windows.getRoamingAppDataDir() + '\\' + path;
String appDataLocal = Windows.getLocalAppDataDir() + '\\' + path;
dataDir = appDataRoaming + "\\data";
dataLocalDir = appDataLocal + "\\data";
configDir = appDataRoaming + "\\config";
Expand Down
28 changes: 9 additions & 19 deletions src/main/java/dev/dirs/UserDirectories.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,26 +343,16 @@ private UserDirectories() {
videoDir = homeDir + "/Movies";
break;
case Constants.WIN:
String[] winDirs = Windows.getWinDirs(
"5E6C858F-0E22-4760-9AFE-EA3317B67173",
"4BD8D571-6D19-48D3-BE97-422220080E43",
"B4BFCC3A-DB2C-424C-B029-7FE99A87C641",
"FDD39AD0-238F-46AF-ADB4-6C85480369C7",
"374DE290-123F-4565-9164-39C4925E467B",
"33E28130-4E1E-4676-835A-98395C3BC3BB",
"DFDF76A2-C82A-4D63-906A-5644AC457385",
"A63293E8-664E-48DB-A079-DF759E0509F7",
"18989B1D-99B5-455B-841C-AB7C74E4DDFC");
homeDir = winDirs[0];
audioDir = winDirs[1];
homeDir = Windows.getProfileDir();
audioDir = Windows.getMusicDir();
fontDir = null;
desktopDir = winDirs[2];
documentDir = winDirs[3];
downloadDir = winDirs[4];
pictureDir = winDirs[5];
publicDir = winDirs[6];
templateDir = winDirs[7];
videoDir = winDirs[8];
desktopDir = Windows.getDesktopDir();
documentDir = Windows.getDocumentsDir();
downloadDir = Windows.getDownloadsDir();
pictureDir = Windows.getPicturesDir();
publicDir = Windows.getPublicDir();
templateDir = Windows.getTemplatesDir();
videoDir = Windows.getVideosDir();
break;
default:
throw new UnsupportedOperatingSystemException("User directories are not supported on " + Constants.operatingSystemName);
Expand Down
Loading

0 comments on commit fcf0332

Please sign in to comment.