diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPage.java index fb87db469..66745e5ad 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DatapackListPage.java @@ -21,6 +21,7 @@ import javafx.beans.property.BooleanProperty; import javafx.collections.ObservableList; import javafx.scene.control.Skin; import javafx.stage.FileChooser; +import org.jackhuang.hmcl.game.World; import org.jackhuang.hmcl.mod.Datapack; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; @@ -44,13 +45,13 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n; import static org.jackhuang.hmcl.util.logging.Logger.LOG; public final class DatapackListPage extends ListPageBase implements WorldManagePage.WorldRefreshable { - private final Path worldDir; + private final World world; private final Datapack datapack; final BooleanProperty readOnly; public DatapackListPage(WorldManagePage worldManagePage) { - this.worldDir = worldManagePage.getWorld().getFile(); - datapack = new Datapack(worldDir.resolve("datapacks")); + world = worldManagePage.getWorld(); + datapack = new Datapack(world.getFile().resolve("datapacks")); setItems(MappedObservableList.create(datapack.getPacks(), DatapackListPageSkin.DatapackInfoObject::new)); readOnly = worldManagePage.readOnlyProperty(); FXUtils.applyDragListener(this, it -> Objects.equals("zip", FileUtils.getExtension(it)), @@ -68,7 +69,7 @@ public final class DatapackListPage extends ListPageBase 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(); }