Skip to content

Commit

Permalink
调整.i18nupdatemod目录存放位置 (#19)
Browse files Browse the repository at this point in the history
* Issus18

* Update: Refactored getLocalStoragePos function

* Update: Refactored getLocalStoragePos function
  • Loading branch information
Chenr0315 authored May 12, 2024
1 parent 4658625 commit 6cdb8a3
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/main/java/i18nupdatemod/I18nUpdateMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
Expand All @@ -32,11 +33,8 @@ public static void init(Path minecraftPath, String minecraftVersion, String load
}
Log.info(String.format("I18nUpdate Mod %s is loaded in %s with %s", MOD_VERSION, minecraftVersion, loader));
Log.debug(String.format("Minecraft path: %s", minecraftPath));
String userHome = System.getProperty("user.home");
if (userHome.equals("null")) {
userHome = minecraftPath.toString();
}
Log.debug(String.format("User home: %s", userHome));
String localStorage = getLocalStoragePos(minecraftPath);
Log.debug(String.format("Local Storage Pos: %s", localStorage));

try {
Class.forName("com.netease.mc.mod.network.common.Library");
Expand Down Expand Up @@ -64,15 +62,15 @@ public static void init(Path minecraftPath, String minecraftVersion, String load
boolean convertNotNeed = assets.downloads.size() == 1 && assets.downloads.get(0).targetVersion.equals(minecraftVersion);
String applyFileName = assets.downloads.get(0).fileName;
for (GameAssetDetail.AssetDownloadDetail it : assets.downloads) {
FileUtil.setTemporaryDirPath(Paths.get(userHome, "." + MOD_ID, it.targetVersion));
FileUtil.setTemporaryDirPath(Paths.get(localStorage, "." + MOD_ID, it.targetVersion));
ResourcePack languagePack = new ResourcePack(it.fileName, convertNotNeed);
languagePack.checkUpdate(it.fileUrl, it.md5Url);
languagePacks.add(languagePack);
}

//Convert resourcepack
if (!convertNotNeed) {
FileUtil.setTemporaryDirPath(Paths.get(userHome, "." + MOD_ID, minecraftVersion));
FileUtil.setTemporaryDirPath(Paths.get(localStorage, "." + MOD_ID, minecraftVersion));
applyFileName = assets.covertFileName;
ResourcePackConverter converter = new ResourcePackConverter(languagePacks, applyFileName);
converter.convert(assets.covertPackFormat, getResourcePackDescription(assets.downloads));
Expand All @@ -97,4 +95,22 @@ private static String getResourcePackDescription(List<GameAssetDetail.AssetDownl
downloads.get(0).targetVersion);

}

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

String localAppData = System.getenv("LocalAppData");
String xdgDataHome = System.getenv("XDG_DATA_HOME");
if (localAppData != null) {
return localAppData;
} else if (xdgDataHome != null) {
return xdgDataHome;
} else {
return minecraftPath.toString();
}
}
}

0 comments on commit 6cdb8a3

Please sign in to comment.