1717import java .nio .file .Paths ;
1818import java .util .ArrayList ;
1919import java .util .List ;
20+ import java .util .Objects ;
2021import java .util .stream .Collectors ;
22+ import java .util .stream .Stream ;
2123
2224public class I18nUpdateMod {
2325 public static final String MOD_ID = "i18nupdatemod" ;
@@ -97,20 +99,26 @@ private static String getResourcePackDescription(List<GameAssetDetail.AssetDownl
9799 }
98100
99101 public static String getLocalStoragePos (Path minecraftPath ) {
100- String userHome = System .getProperty ("user.home" );
101- Path oldPath = Paths . get ( userHome , "." + MOD_ID );
102+ Path userHome = Paths . get ( System .getProperty ("user.home" ) );
103+ Path oldPath = userHome . resolve ( "." + MOD_ID );
102104 if (Files .exists (oldPath )) {
103- return userHome ;
105+ return userHome . toString () ;
104106 }
105107
108+ // https://developer.apple.com/documentation/foundation/url/3988452-applicationsupportdirectory#discussion
109+ String macAppSupport = System .getProperty ("os.name" ).contains ("OS X" ) ?
110+ userHome .resolve ("Library/Application Support" ).toString () : null ;
106111 String localAppData = System .getenv ("LocalAppData" );
112+
113+ // XDG_DATA_HOME fallbacks to ~/.local/share
114+ // https://specifications.freedesktop.org/basedir-spec/latest/#variables
107115 String xdgDataHome = System .getenv ("XDG_DATA_HOME" );
108- if (localAppData != null ) {
109- return localAppData ;
110- } else if (xdgDataHome != null ) {
111- return xdgDataHome ;
112- } else {
113- return minecraftPath .toString ();
116+ if (xdgDataHome == null ) {
117+ xdgDataHome = userHome .resolve (".local/share" ).toString ();
114118 }
119+
120+ return Stream .of (localAppData , macAppSupport ).filter (
121+ Objects ::nonNull
122+ ).findFirst ().orElse (xdgDataHome );
115123 }
116124}
0 commit comments