Fix 3955: 启动时不应补全服务端自动更新整合包中已禁用的 mod (#3956)

Co-authored-by: Glavo <zjx001202@gmail.com>
This commit is contained in:
Zkitefly 2025-08-13 16:03:53 +08:00 committed by GitHub
parent 0d5d1ae4e6
commit a705b7cf95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,7 @@ import com.google.gson.JsonParseException;
import org.jackhuang.hmcl.download.DefaultDependencyManager;
import org.jackhuang.hmcl.download.GameBuilder;
import org.jackhuang.hmcl.game.DefaultGameRepository;
import org.jackhuang.hmcl.mod.ModManager;
import org.jackhuang.hmcl.mod.ModpackConfiguration;
import org.jackhuang.hmcl.task.FileDownloadTask;
import org.jackhuang.hmcl.task.GetTask;
@ -120,7 +121,7 @@ public class ServerModpackCompletionTask extends Task<Void> {
dependencies.add(builder.buildAsync());
}
Path rootPath = repository.getVersionRoot(version).toPath();
Path rootPath = repository.getVersionRoot(version).toPath().toAbsolutePath().normalize();
Map<String, ModpackConfiguration.FileInformation> files = manifest.getManifest().getFiles().stream()
.collect(Collectors.toMap(ModpackConfiguration.FileInformation::getPath,
Function.identity()));
@ -128,12 +129,24 @@ public class ServerModpackCompletionTask extends Task<Void> {
Set<String> remoteFiles = remoteManifest.getFiles().stream().map(ModpackConfiguration.FileInformation::getPath)
.collect(Collectors.toSet());
Path runDirectory = repository.getRunDirectory(version).toPath().toAbsolutePath().normalize();
Path modsDirectory = runDirectory.resolve("mods");
int total = 0;
// for files in new modpack
for (ModpackConfiguration.FileInformation file : remoteManifest.getFiles()) {
Path actualPath = rootPath.resolve(file.getPath());
Path actualPath = rootPath.resolve(file.getPath()).toAbsolutePath().normalize();
String fileName = actualPath.getFileName().toString();
if (!actualPath.startsWith(rootPath)) {
throw new IOException("Unsecure path: " + file.getPath());
}
boolean download;
if (!files.containsKey(file.getPath())) {
if (!files.containsKey(file.getPath()) ||
modsDirectory.equals(actualPath.getParent())
&& Files.notExists(actualPath.resolveSibling(fileName + ModManager.DISABLED_EXTENSION))
&& Files.notExists(actualPath.resolveSibling(fileName + ModManager.OLD_EXTENSION))) {
// If old modpack does not have this entry, download it
download = true;
} else if (!Files.exists(actualPath)) {