feat: display new version of updated modpack. Closes #748.

This commit is contained in:
yuhuihuang
2020-07-19 15:19:53 +08:00
parent d6859d1956
commit 4ce0a83845
15 changed files with 119 additions and 17 deletions

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hmcl.game;
import com.google.gson.JsonParseException;
import com.google.gson.reflect.TypeToken;
import org.jackhuang.hmcl.download.MaintainTask;
import org.jackhuang.hmcl.download.game.VersionJsonSaveTask;
import org.jackhuang.hmcl.event.Event;
@@ -29,11 +30,13 @@ import org.jackhuang.hmcl.event.RefreshingVersionsEvent;
import org.jackhuang.hmcl.event.RemoveVersionEvent;
import org.jackhuang.hmcl.event.RenameVersionEvent;
import org.jackhuang.hmcl.mod.ModManager;
import org.jackhuang.hmcl.mod.ModpackConfiguration;
import org.jackhuang.hmcl.task.Task;
import org.jackhuang.hmcl.util.Lang;
import org.jackhuang.hmcl.util.ToStringBuilder;
import org.jackhuang.hmcl.util.gson.JsonUtils;
import org.jackhuang.hmcl.util.io.FileUtils;
import org.jetbrains.annotations.Nullable;
import java.io.File;
import java.io.IOException;
@@ -437,6 +440,22 @@ public class DefaultGameRepository implements GameRepository {
return new File(getVersionRoot(version), "modpack.json");
}
/**
* read modpack configuration for a version.
* @param version version installed as modpack
* @param <M> manifest type of ModpackConfiguration
* @return modpack configuration object, or null if this version is not a modpack.
* @throws VersionNotFoundException if version does not exist.
* @throws IOException if an i/o error occurs.
*/
@Nullable
public <M> ModpackConfiguration<M> readModpackConfiguration(String version) throws IOException, VersionNotFoundException {
if (!hasVersion(version)) throw new VersionNotFoundException(version);
File file = getModpackConfiguration(version);
if (!file.exists()) return null;
return JsonUtils.GSON.fromJson(FileUtils.readText(file), new TypeToken<ModpackConfiguration<M>>(){}.getType());
}
public boolean isModpack(String version) {
return getModpackConfiguration(version).exists();
}

View File

@@ -41,14 +41,18 @@ public final class MinecraftInstanceTask<T> extends Task<Void> {
private final File jsonFile;
private final T manifest;
private final String type;
private final String name;
private final String version;
public MinecraftInstanceTask(File zipFile, Charset encoding, String subDirectory, T manifest, String type, File jsonFile) {
public MinecraftInstanceTask(File zipFile, Charset encoding, String subDirectory, T manifest, String type, String name, String version, File jsonFile) {
this.zipFile = zipFile;
this.encoding = encoding;
this.subDirectory = FileUtils.normalizePath(subDirectory);
this.manifest = manifest;
this.jsonFile = jsonFile;
this.type = type;
this.name = name;
this.version = version;
}
@Override
@@ -69,6 +73,6 @@ public final class MinecraftInstanceTask<T> extends Task<Void> {
});
}
FileUtils.writeText(jsonFile, JsonUtils.GSON.toJson(new ModpackConfiguration<>(manifest, type, overrides)));
FileUtils.writeText(jsonFile, JsonUtils.GSON.toJson(new ModpackConfiguration<>(manifest, type, name, version, overrides)));
}
}

View File

@@ -20,6 +20,7 @@ package org.jackhuang.hmcl.mod;
import com.google.gson.JsonParseException;
import org.jackhuang.hmcl.util.Immutable;
import org.jackhuang.hmcl.util.gson.Validation;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collections;
@@ -30,15 +31,19 @@ public final class ModpackConfiguration<T> implements Validation {
private final T manifest;
private final String type;
private final String name;
private final String version;
private final List<FileInformation> overrides;
public ModpackConfiguration() {
this(null, null, Collections.emptyList());
this(null, null, "", null, Collections.emptyList());
}
public ModpackConfiguration(T manifest, String type, List<FileInformation> overrides) {
public ModpackConfiguration(T manifest, String type, String name, String version, List<FileInformation> overrides) {
this.manifest = manifest;
this.type = type;
this.name = name;
this.version = version;
this.overrides = new ArrayList<>(overrides);
}
@@ -50,12 +55,25 @@ public final class ModpackConfiguration<T> implements Validation {
return type;
}
public String getName() {
return name;
}
@Nullable
public String getVersion() {
return version;
}
public ModpackConfiguration<T> setManifest(T manifest) {
return new ModpackConfiguration<>(manifest, type, overrides);
return new ModpackConfiguration<>(manifest, type, name, version, overrides);
}
public ModpackConfiguration<T> setOverrides(List<FileInformation> overrides) {
return new ModpackConfiguration<>(manifest, type, overrides);
return new ModpackConfiguration<>(manifest, type, name, version, overrides);
}
public ModpackConfiguration<T> setVersion(String version) {
return new ModpackConfiguration<>(manifest, type, name, version, overrides);
}
public List<FileInformation> getOverrides() {

View File

@@ -107,7 +107,7 @@ public final class CurseInstallTask extends Task<Void> {
}
this.config = config;
dependents.add(new ModpackInstallTask<>(zipFile, run, modpack.getEncoding(), manifest.getOverrides(), any -> true, config).withStage("hmcl.modpack"));
dependents.add(new MinecraftInstanceTask<>(zipFile, modpack.getEncoding(), manifest.getOverrides(), manifest, MODPACK_TYPE, repository.getModpackConfiguration(name)).withStage("hmcl.modpack"));
dependents.add(new MinecraftInstanceTask<>(zipFile, modpack.getEncoding(), manifest.getOverrides(), manifest, MODPACK_TYPE, manifest.getName(), manifest.getVersion(), repository.getModpackConfiguration(name)).withStage("hmcl.modpack"));
dependencies.add(new CurseCompletionTask(dependencyManager, name, manifest).withStage("hmcl.modpack.download"));
}

View File

@@ -131,7 +131,7 @@ public final class MultiMCModpackInstallTask extends Task<Void> {
dependents.add(new ModpackInstallTask<>(zipFile, run, modpack.getEncoding(), "/" + manifest.getName() + "/minecraft", any -> true, config).withStage("hmcl.modpack"));
}
dependents.add(new MinecraftInstanceTask<>(zipFile, modpack.getEncoding(), "/" + manifest.getName() + "/minecraft", manifest, MODPACK_TYPE, repository.getModpackConfiguration(name)).withStage("hmcl.modpack"));
dependents.add(new MinecraftInstanceTask<>(zipFile, modpack.getEncoding(), "/" + manifest.getName() + "/minecraft", manifest, MODPACK_TYPE, manifest.getName(), null, repository.getModpackConfiguration(name)).withStage("hmcl.modpack"));
}
@Override

View File

@@ -158,6 +158,6 @@ public class ServerModpackCompletionTask extends Task<Void> {
public void postExecute() throws Exception {
if (manifest == null || StringUtils.isBlank(manifest.getManifest().getFileApi())) return;
File manifestFile = repository.getModpackConfiguration(version);
FileUtils.writeText(manifestFile, JsonUtils.GSON.toJson(new ModpackConfiguration<>(remoteManifest, this.manifest.getType(), remoteManifest.getFiles())));
FileUtils.writeText(manifestFile, JsonUtils.GSON.toJson(new ModpackConfiguration<>(remoteManifest, this.manifest.getType(), this.manifest.getName(), this.manifest.getVersion(), remoteManifest.getFiles())));
}
}

View File

@@ -82,7 +82,7 @@ public class ServerModpackLocalInstallTask extends Task<Void> {
} catch (JsonParseException | IOException ignore) {
}
dependents.add(new ModpackInstallTask<>(zipFile, run, modpack.getEncoding(), "/overrides", any -> true, config).withStage("hmcl.modpack"));
dependents.add(new MinecraftInstanceTask<>(zipFile, modpack.getEncoding(), "/overrides", manifest, MODPACK_TYPE, repository.getModpackConfiguration(name)).withStage("hmcl.modpack"));
dependents.add(new MinecraftInstanceTask<>(zipFile, modpack.getEncoding(), "/overrides", manifest, MODPACK_TYPE, modpack.getName(), modpack.getVersion(), repository.getModpackConfiguration(name)).withStage("hmcl.modpack"));
}
@Override

View File

@@ -88,7 +88,7 @@ public class ServerModpackRemoteInstallTask extends Task<Void> {
@Override
public void execute() throws Exception {
dependencies.add(new ServerModpackCompletionTask(dependency, name, new ModpackConfiguration<>(manifest, MODPACK_TYPE, Collections.emptyList())));
dependencies.add(new ServerModpackCompletionTask(dependency, name, new ModpackConfiguration<>(manifest, MODPACK_TYPE, manifest.getName(), manifest.getVersion(), Collections.emptyList())));
}
public static final String MODPACK_TYPE = "Server";