Skip to content

Commit

Permalink
Change the storage locations on macOS and Linux (#24)
Browse files Browse the repository at this point in the history
* Change Storage location to Application Support on macOS
Give XDG_DATA_HOME the right fallback ~/.local/share

* remove unused imports
  • Loading branch information
ghostflyby authored Oct 23, 2024
1 parent aa5ea26 commit 080c112
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/main/java/i18nupdatemod/I18nUpdateMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class I18nUpdateMod {
public static final String MOD_ID = "i18nupdatemod";
Expand Down Expand Up @@ -97,20 +99,26 @@ private static String getResourcePackDescription(List<GameAssetDetail.AssetDownl
}

public static String getLocalStoragePos(Path minecraftPath) {
String userHome = System.getProperty("user.home");
Path oldPath = Paths.get(userHome, "." + MOD_ID);
Path userHome = Paths.get(System.getProperty("user.home"));
Path oldPath = userHome.resolve("." + MOD_ID);
if (Files.exists(oldPath)) {
return userHome;
return userHome.toString();
}

// https://developer.apple.com/documentation/foundation/url/3988452-applicationsupportdirectory#discussion
String macAppSupport = System.getProperty("os.name").contains("OS X") ?
userHome.resolve("Library/Application Support").toString() : null;
String localAppData = System.getenv("LocalAppData");

// XDG_DATA_HOME fallbacks to ~/.local/share
// https://specifications.freedesktop.org/basedir-spec/latest/#variables
String xdgDataHome = System.getenv("XDG_DATA_HOME");
if (localAppData != null) {
return localAppData;
} else if (xdgDataHome != null) {
return xdgDataHome;
} else {
return minecraftPath.toString();
if (xdgDataHome == null) {
xdgDataHome = userHome.resolve(".local/share").toString();
}

return Stream.of(localAppData, macAppSupport).filter(
Objects::nonNull
).findFirst().orElse(xdgDataHome);
}
}

0 comments on commit 080c112

Please sign in to comment.