Merge e256373636851700b8a20322efb1dc66644ae7ac into 3eddfa23b70f8bd6d64ea5cf576fccbe5a0f35c2

This commit is contained in:
Zkitefly 2025-07-31 22:55:21 +08:00 committed by GitHub
commit 350a2c491a
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;
@ -45,6 +46,7 @@ public class ServerModpackCompletionTask extends Task<Void> {
private final DefaultDependencyManager dependencyManager;
private final DefaultGameRepository repository;
private final ModManager modManager;
private final String version;
private ModpackConfiguration<ServerModpackManifest> manifest;
private GetTask dependent;
@ -58,6 +60,7 @@ public class ServerModpackCompletionTask extends Task<Void> {
public ServerModpackCompletionTask(DefaultDependencyManager dependencyManager, String version, ModpackConfiguration<ServerModpackManifest> manifest) {
this.dependencyManager = dependencyManager;
this.repository = dependencyManager.getGameRepository();
this.modManager = repository.getModManager(version);
this.version = version;
if (manifest == null) {
@ -130,12 +133,21 @@ 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();
if (!actualPath.startsWith(rootPath)) {
throw new IOException("Unsecure path: " + file.getPath());
}
boolean download;
if (!files.containsKey(file.getPath())) {
boolean isModFile = modsDirectory.equals(actualPath.getParent());
if (!files.containsKey(file.getPath()) || isModFile && !modManager.hasSimpleMod(FileUtils.getName(actualPath))) {
// If old modpack does not have this entry, download it
download = true;
} else if (!Files.exists(actualPath)) {