feat: use XDG_DATA_HOME as for Linux working directories (#1948)

This commit is contained in:
Yingchi Long 2022-12-30 01:58:15 +08:00 committed by GitHub
parent 9750c69742
commit 2e7e2d261c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,8 @@
*/ */
package org.jackhuang.hmcl.util.platform; package org.jackhuang.hmcl.util.platform;
import org.jackhuang.hmcl.util.StringUtils;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -274,7 +276,11 @@ public enum OperatingSystem {
String home = System.getProperty("user.home", "."); String home = System.getProperty("user.home", ".");
switch (OperatingSystem.CURRENT_OS) { switch (OperatingSystem.CURRENT_OS) {
case LINUX: case LINUX:
return Paths.get(home, "." + folder); String xdgData = System.getenv("XDG_DATA_HOME");
if (StringUtils.isNotBlank(xdgData)) {
return Paths.get(xdgData, folder);
}
return Paths.get(home, ".local", "share", folder);
case WINDOWS: case WINDOWS:
String appdata = System.getenv("APPDATA"); String appdata = System.getenv("APPDATA");
return Paths.get(appdata == null ? home : appdata, "." + folder); return Paths.get(appdata == null ? home : appdata, "." + folder);