feat: 添加新版本世界指定资源包位置支持 (#5552)
This commit is contained in:
@@ -29,6 +29,7 @@ import org.jackhuang.hmcl.util.gson.JsonUtils;
|
||||
import org.jackhuang.hmcl.util.io.CompressingUtils;
|
||||
import org.jackhuang.hmcl.util.io.FileUtils;
|
||||
import org.jackhuang.hmcl.util.io.Unzipper;
|
||||
import org.jackhuang.hmcl.util.versioning.GameVersionNumber;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
@@ -57,7 +58,7 @@ public class Datapack {
|
||||
return packs;
|
||||
}
|
||||
|
||||
public static void installPack(Path sourceDatapackPath, Path targetDatapackDirectory) throws IOException {
|
||||
public static void installPack(Path sourceDatapackPath, Path targetDatapackDirectory, GameVersionNumber gameVersionNumber) throws IOException {
|
||||
boolean containsMultiplePacks;
|
||||
Set<String> packs = new HashSet<>();
|
||||
try (FileSystem fs = CompressingUtils.readonly(sourceDatapackPath).setAutoDetectEncoding(true).build()) {
|
||||
@@ -106,7 +107,19 @@ public class Datapack {
|
||||
.setSubDirectory("/datapacks/")
|
||||
.unzip();
|
||||
|
||||
try (FileSystem outputResourcesZipFS = CompressingUtils.createWritableZipFileSystem(targetDatapackDirectory.getParent().resolve("resources.zip"));
|
||||
Path targetResourceZipPath;
|
||||
// When the version cannot be obtained, the old version logic is used by default.
|
||||
boolean useNewResourcePath = gameVersionNumber != null
|
||||
&& gameVersionNumber.compareTo("26.1-snapshot-6") >= 0;
|
||||
|
||||
if (useNewResourcePath) {
|
||||
Files.createDirectories(targetDatapackDirectory.getParent().resolve("resourcepacks"));
|
||||
targetResourceZipPath = targetDatapackDirectory.getParent().resolve("resourcepacks/resources.zip");
|
||||
} else {
|
||||
targetResourceZipPath = targetDatapackDirectory.getParent().resolve("resources.zip");
|
||||
}
|
||||
|
||||
try (FileSystem outputResourcesZipFS = CompressingUtils.createWritableZipFileSystem(targetResourceZipPath);
|
||||
FileSystem inputPackZipFS = CompressingUtils.createReadOnlyZipFileSystem(sourceDatapackPath)) {
|
||||
Path resourcesZip = inputPackZipFS.getPath("resources.zip");
|
||||
if (Files.isRegularFile(resourcesZip)) {
|
||||
@@ -138,8 +151,8 @@ public class Datapack {
|
||||
}
|
||||
}
|
||||
|
||||
public void installPack(Path sourcePackPath) throws IOException {
|
||||
installPack(sourcePackPath, path);
|
||||
public void installPack(Path sourcePackPath, GameVersionNumber gameVersionNumber) throws IOException {
|
||||
installPack(sourcePackPath, path, gameVersionNumber);
|
||||
loadFromDir();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user