Skip to content

Commit

Permalink
Fix #3200: 启动时不应补全 Modrinth 整合包中已禁用的 mod (#3308)
Browse files Browse the repository at this point in the history
* Update ModrinthCompletionTask.java

* Update ModrinthCompletionTask.java

* Update ModrinthCompletionTask.java

* Update ModrinthCompletionTask.java

* Update ModrinthCompletionTask.java

* update

* update

* update

* update

* update

* update

* update

---------

Co-authored-by: Glavo <[email protected]>
  • Loading branch information
zkitefly and Glavo authored Nov 10, 2024
1 parent 9a0db56 commit 2ca7e7c
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.jackhuang.hmcl.download.DefaultDependencyManager;
import org.jackhuang.hmcl.game.DefaultGameRepository;
import org.jackhuang.hmcl.mod.ModManager;
import org.jackhuang.hmcl.mod.ModpackCompletionException;
import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.task.Task;
Expand All @@ -27,6 +28,7 @@

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -41,6 +43,7 @@ public class ModrinthCompletionTask extends Task<Void> {

private final DefaultDependencyManager dependency;
private final DefaultGameRepository repository;
private final ModManager modManager;
private final String version;
private ModrinthManifest manifest;
private final List<Task<?>> dependencies = new ArrayList<>();
Expand Down Expand Up @@ -69,6 +72,7 @@ public ModrinthCompletionTask(DefaultDependencyManager dependencyManager, String
public ModrinthCompletionTask(DefaultDependencyManager dependencyManager, String version, ModrinthManifest manifest) {
this.dependency = dependencyManager;
this.repository = dependencyManager.getGameRepository();
this.modManager = repository.getModManager(version);
this.version = version;
this.manifest = manifest;

Expand Down Expand Up @@ -99,18 +103,28 @@ public void execute() throws Exception {
if (manifest == null)
return;

Path runDirectory = repository.getRunDirectory(version).toPath();
Path runDirectory = repository.getRunDirectory(version).toPath().toAbsolutePath().normalize();
Path modsDirectory = runDirectory.resolve("mods");

for (ModrinthManifest.File file : manifest.getFiles()) {
if (file.getEnv() != null && file.getEnv().getOrDefault("client", "required").equals("unsupported"))
continue;
Path filePath = runDirectory.resolve(file.getPath());
if (!Files.exists(filePath) && !file.getDownloads().isEmpty()) {
FileDownloadTask task = new FileDownloadTask(file.getDownloads().get(0), filePath.toFile());
task.setCacheRepository(dependency.getCacheRepository());
task.setCaching(true);
dependencies.add(task.withCounter("hmcl.modpack.download"));
}
if (file.getDownloads().isEmpty())
continue;

Path filePath = runDirectory.resolve(file.getPath()).toAbsolutePath().normalize();
if (!filePath.startsWith(runDirectory))
throw new IOException("Unsecure path: " + file.getPath());

if (Files.exists(filePath))
continue;
if (modsDirectory.equals(filePath.getParent()) && this.modManager.hasSimpleMod(FileUtils.getName(filePath)))
continue;

FileDownloadTask task = new FileDownloadTask(file.getDownloads(), filePath.toFile());
task.setCacheRepository(dependency.getCacheRepository());
task.setCaching(true);
dependencies.add(task.withCounter("hmcl.modpack.download"));
}

if (!dependencies.isEmpty()) {
Expand Down

0 comments on commit 2ca7e7c

Please sign in to comment.