1212
1313import java .io .InputStream ;
1414import java .io .InputStreamReader ;
15+ import java .nio .file .Files ;
1516import java .nio .file .Path ;
1617import java .nio .file .Paths ;
1718import java .util .ArrayList ;
@@ -32,11 +33,8 @@ public static void init(Path minecraftPath, String minecraftVersion, String load
3233 }
3334 Log .info (String .format ("I18nUpdate Mod %s is loaded in %s with %s" , MOD_VERSION , minecraftVersion , loader ));
3435 Log .debug (String .format ("Minecraft path: %s" , minecraftPath ));
35- String userHome = System .getProperty ("user.home" );
36- if (userHome .equals ("null" )) {
37- userHome = minecraftPath .toString ();
38- }
39- Log .debug (String .format ("User home: %s" , userHome ));
36+ String localStorage = getLocalStoragePos (minecraftPath );
37+ Log .debug (String .format ("Local Storage Pos: %s" , localStorage ));
4038
4139 try {
4240 Class .forName ("com.netease.mc.mod.network.common.Library" );
@@ -64,15 +62,15 @@ public static void init(Path minecraftPath, String minecraftVersion, String load
6462 boolean convertNotNeed = assets .downloads .size () == 1 && assets .downloads .get (0 ).targetVersion .equals (minecraftVersion );
6563 String applyFileName = assets .downloads .get (0 ).fileName ;
6664 for (GameAssetDetail .AssetDownloadDetail it : assets .downloads ) {
67- FileUtil .setTemporaryDirPath (Paths .get (userHome , "." + MOD_ID , it .targetVersion ));
65+ FileUtil .setTemporaryDirPath (Paths .get (localStorage , "." + MOD_ID , it .targetVersion ));
6866 ResourcePack languagePack = new ResourcePack (it .fileName , convertNotNeed );
6967 languagePack .checkUpdate (it .fileUrl , it .md5Url );
7068 languagePacks .add (languagePack );
7169 }
7270
7371 //Convert resourcepack
7472 if (!convertNotNeed ) {
75- FileUtil .setTemporaryDirPath (Paths .get (userHome , "." + MOD_ID , minecraftVersion ));
73+ FileUtil .setTemporaryDirPath (Paths .get (localStorage , "." + MOD_ID , minecraftVersion ));
7674 applyFileName = assets .covertFileName ;
7775 ResourcePackConverter converter = new ResourcePackConverter (languagePacks , applyFileName );
7876 converter .convert (assets .covertPackFormat , getResourcePackDescription (assets .downloads ));
@@ -97,4 +95,22 @@ private static String getResourcePackDescription(List<GameAssetDetail.AssetDownl
9795 downloads .get (0 ).targetVersion );
9896
9997 }
98+
99+ public static String getLocalStoragePos (Path minecraftPath ) {
100+ String userHome = System .getProperty ("user.home" );
101+ Path oldPath = Paths .get (userHome , "." + MOD_ID );
102+ if (Files .exists (oldPath )) {
103+ return userHome ;
104+ }
105+
106+ String localAppData = System .getenv ("LocalAppData" );
107+ 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 ();
114+ }
115+ }
100116}
0 commit comments