From 1d3d8d67106b944fe3192e03a0102c3a29ada5ea Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Sun, 19 Aug 2018 00:39:47 +0800 Subject: [PATCH] Show OptiFine versions in dividually --- .../ui/download/AdditionalInstallersPage.java | 2 +- .../ui/download/DownloadWizardProvider.java | 8 +- .../ui/download/InstallerWizardProvider.java | 6 +- .../hmcl/ui/download/InstallersPage.java | 4 +- .../hmcl/ui/download/VersionsPage.java | 29 +++--- .../hmcl/ui/download/VersionsPageItem.java | 19 ++-- .../download/DefaultDependencyManager.java | 2 +- .../hmcl/download/DefaultGameBuilder.java | 2 +- .../hmcl/download/DependencyManager.java | 2 +- .../jackhuang/hmcl/download/GameBuilder.java | 4 +- .../hmcl/download/RemoteVersion.java | 39 +++++--- .../jackhuang/hmcl/download/VersionList.java | 20 ++-- .../download/forge/ForgeRemoteVersion.java | 4 +- .../hmcl/download/forge/ForgeVersionList.java | 7 +- .../hmcl/download/game/GameRemoteVersion.java | 62 +++---------- .../download/game/GameRemoteVersionInfo.java | 93 +++++++++++++++++++ .../download/game/GameRemoteVersionTag.java | 55 ----------- .../download/game/GameRemoteVersions.java | 6 +- .../hmcl/download/game/GameVersionList.java | 24 ++--- .../game/VersionJsonDownloadTask.java | 2 +- .../liteloader/LiteLoaderBMCLVersionList.java | 7 +- .../liteloader/LiteLoaderInstallTask.java | 4 +- .../liteloader/LiteLoaderRemoteVersion.java | 18 +++- .../LiteLoaderRemoteVersionTag.java | 54 ----------- .../liteloader/LiteLoaderVersionList.java | 7 +- .../optifine/OptiFineBMCLVersionList.java | 13 ++- .../optifine/OptiFineRemoteVersion.java | 6 +- 27 files changed, 246 insertions(+), 253 deletions(-) create mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersionInfo.java delete mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersionTag.java delete mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemoteVersionTag.java diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java index 92366f713..630371e3f 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/AdditionalInstallersPage.java @@ -103,7 +103,7 @@ class AdditionalInstallersPage extends StackPane implements WizardPage { } private String getVersion(String id) { - return Optional.ofNullable(controller.getSettings().get(id)).map(it -> (RemoteVersion) it).map(RemoteVersion::getSelfVersion).orElse(null); + return Optional.ofNullable(controller.getSettings().get(id)).map(it -> (RemoteVersion) it).map(RemoteVersion::getSelfVersion).orElse(null); } @Override diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadWizardProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadWizardProvider.java index 3c801d885..2c6721799 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadWizardProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadWizardProvider.java @@ -49,16 +49,16 @@ public final class DownloadWizardProvider implements WizardProvider { GameBuilder builder = profile.getDependency().gameBuilder(); builder.name((String) settings.get("name")); - builder.gameVersion(((RemoteVersion) settings.get("game")).getGameVersion()); + builder.gameVersion(((RemoteVersion) settings.get("game")).getGameVersion()); if (settings.containsKey("forge")) - builder.version((RemoteVersion) settings.get("forge")); + builder.version((RemoteVersion) settings.get("forge")); if (settings.containsKey("liteloader")) - builder.version((RemoteVersion) settings.get("liteloader")); + builder.version((RemoteVersion) settings.get("liteloader")); if (settings.containsKey("optifine")) - builder.version((RemoteVersion) settings.get("optifine")); + builder.version((RemoteVersion) settings.get("optifine")); return builder.buildAsync().finalized((a, b) -> profile.getRepository().refreshVersions()); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java index 1c89146be..087845ea0 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java @@ -88,13 +88,13 @@ public final class InstallerWizardProvider implements WizardProvider { Task ret = Task.empty(); if (settings.containsKey("forge")) - ret = ret.then(profile.getDependency().installLibraryAsync(version, (RemoteVersion) settings.get("forge"))); + ret = ret.then(profile.getDependency().installLibraryAsync(version, (RemoteVersion) settings.get("forge"))); if (settings.containsKey("liteloader")) - ret = ret.then(profile.getDependency().installLibraryAsync(version, (RemoteVersion) settings.get("liteloader"))); + ret = ret.then(profile.getDependency().installLibraryAsync(version, (RemoteVersion) settings.get("liteloader"))); if (settings.containsKey("optifine")) - ret = ret.then(profile.getDependency().installLibraryAsync(version, (RemoteVersion) settings.get("optifine"))); + ret = ret.then(profile.getDependency().installLibraryAsync(version, (RemoteVersion) settings.get("optifine"))); return ret.then(profile.getRepository().refreshVersionsAsync()); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java index 2898c9418..4f48a2acf 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java @@ -74,7 +74,7 @@ public class InstallersPage extends StackPane implements WizardPage { FXUtils.loadFXML(this, "/assets/fxml/download/installers.fxml"); - String gameVersion = ((RemoteVersion) controller.getSettings().get("game")).getGameVersion(); + String gameVersion = ((RemoteVersion) controller.getSettings().get("game")).getGameVersion(); Validator hasVersion = new Validator(s -> !repository.hasVersion(s) && StringUtils.isNotBlank(s)); hasVersion.setMessage(i18n("install.new_game.already_exists")); txtName.getValidators().add(hasVersion); @@ -103,7 +103,7 @@ public class InstallersPage extends StackPane implements WizardPage { } private String getVersion(String id) { - return ((RemoteVersion) controller.getSettings().get(id)).getSelfVersion(); + return ((RemoteVersion) controller.getSettings().get(id)).getSelfVersion(); } @Override diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java index c8611384a..f7c425e35 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPage.java @@ -27,9 +27,8 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import org.jackhuang.hmcl.download.DownloadProvider; +import org.jackhuang.hmcl.download.RemoteVersion; import org.jackhuang.hmcl.download.VersionList; -import org.jackhuang.hmcl.download.game.GameRemoteVersionTag; -import org.jackhuang.hmcl.download.game.GameVersionList; import org.jackhuang.hmcl.task.TaskExecutor; import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.animation.ContainerAnimations; @@ -79,7 +78,7 @@ public final class VersionsPage extends StackPane implements WizardPage, Refresh FXUtils.loadFXML(this, "/assets/fxml/download/versions.fxml"); - if (versionList instanceof GameVersionList) { + if (versionList.hasType()) { centrePane.getChildren().setAll(checkPane, list); } else centrePane.getChildren().setAll(list); @@ -99,21 +98,21 @@ public final class VersionsPage extends StackPane implements WizardPage, Refresh } private List loadVersions() { - boolean isGameVersionList = versionList instanceof GameVersionList; return versionList.getVersions(gameVersion).stream() .filter(it -> { - if (isGameVersionList) - switch (((GameRemoteVersionTag) it.getTag()).getType()) { - case RELEASE: - return chkRelease.isSelected(); - case SNAPSHOT: - return chkSnapshot.isSelected(); - default: - return chkOld.isSelected(); - } - else return true; + if (it.getVersionType() == null) + return true; + switch (it.getVersionType()) { + case RELEASE: + return chkRelease.isSelected(); + case SNAPSHOT: + return chkSnapshot.isSelected(); + case OLD: + return chkOld.isSelected(); + default: + return true; + } }) - .filter(Objects::nonNull) .sorted() .map(VersionsPageItem::new).collect(Collectors.toList()); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPageItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPageItem.java index 299a6fc43..bfdc5ae91 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPageItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/VersionsPageItem.java @@ -25,8 +25,9 @@ import javafx.scene.layout.HBox; import javafx.scene.layout.StackPane; import org.jackhuang.hmcl.download.RemoteVersion; -import org.jackhuang.hmcl.download.game.GameRemoteVersionTag; -import org.jackhuang.hmcl.download.liteloader.LiteLoaderRemoteVersionTag; +import org.jackhuang.hmcl.download.forge.ForgeRemoteVersion; +import org.jackhuang.hmcl.download.game.GameRemoteVersion; +import org.jackhuang.hmcl.download.liteloader.LiteLoaderRemoteVersion; import org.jackhuang.hmcl.download.optifine.OptiFineRemoteVersion; import org.jackhuang.hmcl.ui.FXUtils; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; @@ -37,7 +38,7 @@ import java.util.Objects; * @author huangyuhui */ public final class VersionsPageItem extends StackPane { - private final RemoteVersion remoteVersion; + private final RemoteVersion remoteVersion; @FXML private Label lblSelfVersion; @FXML @@ -49,14 +50,14 @@ public final class VersionsPageItem extends StackPane { @FXML private StackPane imageViewContainer; - public VersionsPageItem(RemoteVersion remoteVersion) { + public VersionsPageItem(RemoteVersion remoteVersion) { this.remoteVersion = Objects.requireNonNull(remoteVersion); FXUtils.loadFXML(this, "/assets/fxml/download/versions-list-item.fxml"); lblSelfVersion.setText(remoteVersion.getSelfVersion()); - if (remoteVersion.getTag() instanceof GameRemoteVersionTag) { - switch (((GameRemoteVersionTag) remoteVersion.getTag()).getType()) { + if (remoteVersion instanceof GameRemoteVersion) { + switch (remoteVersion.getVersionType()) { case RELEASE: lblGameVersion.setText(i18n("version.game.release")); imageView.setImage(new Image("/assets/img/icon.png", 32, 32, false, true)); @@ -70,13 +71,13 @@ public final class VersionsPageItem extends StackPane { imageView.setImage(new Image("/assets/img/grass.png", 32, 32, false, true)); break; } - } else if (remoteVersion.getTag() instanceof LiteLoaderRemoteVersionTag) { + } else if (remoteVersion instanceof LiteLoaderRemoteVersion) { imageView.setImage(new Image("/assets/img/chicken.png", 32, 32, false, true)); lblGameVersion.setText(remoteVersion.getGameVersion()); } else if (remoteVersion instanceof OptiFineRemoteVersion) { // optifine has no icon. lblGameVersion.setText(remoteVersion.getGameVersion()); - } else { // forge + } else if (remoteVersion instanceof ForgeRemoteVersion) { imageView.setImage(new Image("/assets/img/forge.png", 32, 32, false, true)); lblGameVersion.setText(remoteVersion.getGameVersion()); } @@ -84,7 +85,7 @@ public final class VersionsPageItem extends StackPane { leftPane.getChildren().remove(imageViewContainer); } - public RemoteVersion getRemoteVersion() { + public RemoteVersion getRemoteVersion() { return remoteVersion; } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultDependencyManager.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultDependencyManager.java index b1297fecc..c7a84d427 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultDependencyManager.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultDependencyManager.java @@ -77,7 +77,7 @@ public class DefaultDependencyManager extends AbstractDependencyManager { } @Override - public Task installLibraryAsync(Version version, RemoteVersion libraryVersion) { + public Task installLibraryAsync(Version version, RemoteVersion libraryVersion) { if (libraryVersion instanceof ForgeRemoteVersion) return new ForgeInstallTask(this, version, (ForgeRemoteVersion) libraryVersion) .then(variables -> new LibrariesUniqueTask(variables.get("version"))) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultGameBuilder.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultGameBuilder.java index b3f838b47..1d02fba28 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultGameBuilder.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultGameBuilder.java @@ -67,7 +67,7 @@ public class DefaultGameBuilder extends GameBuilder { if (toolVersions.containsKey("optifine")) result = result.then(libraryTaskHelper(gameVersion, "optifine")); - for (RemoteVersion remoteVersion : remoteVersions) + for (RemoteVersion remoteVersion : remoteVersions) result = result.then(var -> dependencyManager.installLibraryAsync(var.get("version"), remoteVersion)); return result; diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DependencyManager.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DependencyManager.java index c3b00047b..d54e303a5 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DependencyManager.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DependencyManager.java @@ -67,7 +67,7 @@ public interface DependencyManager { * @param libraryVersion the remote version of being installed library. * @return the task to install the specific library. */ - Task installLibraryAsync(Version version, RemoteVersion libraryVersion); + Task installLibraryAsync(Version version, RemoteVersion libraryVersion); /** * Get registered version list. diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/GameBuilder.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/GameBuilder.java index cf7319408..a07f77e0f 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/GameBuilder.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/GameBuilder.java @@ -31,7 +31,7 @@ public abstract class GameBuilder { protected String name = ""; protected String gameVersion = ""; protected final Map toolVersions = new HashMap<>(); - protected final Set> remoteVersions = new HashSet<>(); + protected final Set remoteVersions = new HashSet<>(); public String getName() { return name; @@ -64,7 +64,7 @@ public abstract class GameBuilder { return this; } - public GameBuilder version(RemoteVersion remoteVersion) { + public GameBuilder version(RemoteVersion remoteVersion) { remoteVersions.add(remoteVersion); return this; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/RemoteVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/RemoteVersion.java index de189fe40..1cc7a5bd6 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/RemoteVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/RemoteVersion.java @@ -27,26 +27,36 @@ import java.util.Objects; * * @author huangyuhui */ -public class RemoteVersion implements Comparable> { +public class RemoteVersion implements Comparable { private final String gameVersion; private final String selfVersion; private final String url; - private final T tag; + private final Type type; /** * Constructor. * * @param gameVersion the Minecraft version that this remote version suits. * @param selfVersion the version string of the remote version. - * @param url the installer or universal jar URL. - * @param tag some necessary information for Installer Task. + * @param url the installer or universal jar URL. */ - public RemoteVersion(String gameVersion, String selfVersion, String url, T tag) { + public RemoteVersion(String gameVersion, String selfVersion, String url) { + this(gameVersion, selfVersion, url, null); + } + + /** + * Constructor. + * + * @param gameVersion the Minecraft version that this remote version suits. + * @param selfVersion the version string of the remote version. + * @param url the installer or universal jar URL. + */ + public RemoteVersion(String gameVersion, String selfVersion, String url, Type type) { this.gameVersion = Objects.requireNonNull(gameVersion); this.selfVersion = Objects.requireNonNull(selfVersion); this.url = Objects.requireNonNull(url); - this.tag = tag; + this.type = type; } public String getGameVersion() { @@ -57,14 +67,14 @@ public class RemoteVersion implements Comparable> { return selfVersion; } - public T getTag() { - return tag; - } - public String getUrl() { return url; } + public Type getVersionType() { + return type; + } + @Override public boolean equals(Object obj) { return obj instanceof RemoteVersion && Objects.equals(selfVersion, ((RemoteVersion) obj).selfVersion); @@ -80,13 +90,18 @@ public class RemoteVersion implements Comparable> { return new ToStringBuilder(this) .append("selfVersion", selfVersion) .append("gameVersion", gameVersion) - .append("tag", tag) .toString(); } @Override - public int compareTo(RemoteVersion o) { + public int compareTo(RemoteVersion o) { // newer versions are smaller than older versions return VersionNumber.asVersion(o.selfVersion).compareTo(VersionNumber.asVersion(selfVersion)); } + + public enum Type { + RELEASE, + SNAPSHOT, + OLD + } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/VersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/VersionList.java index 374bef77b..b6e0daf91 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/VersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/VersionList.java @@ -26,18 +26,18 @@ import java.util.concurrent.locks.ReentrantReadWriteLock; /** * The remote version list. * - * @param The type of {@code RemoteVersion}, the type of tags. + * @param The subclass of {@code RemoteVersion}, the type of RemoteVersion. * * @author huangyuhui */ -public abstract class VersionList { +public abstract class VersionList { /** * the remote version list. * key: game version. * values: corresponding remote versions. */ - protected final SimpleMultimap> versions = new SimpleMultimap>(HashMap::new, TreeSet::new); + protected final SimpleMultimap versions = new SimpleMultimap(HashMap::new, TreeSet::new); /** * True if the version list has been loaded. @@ -46,6 +46,8 @@ public abstract class VersionList { return !versions.isEmpty(); } + public abstract boolean hasType(); + protected final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); /** @@ -68,10 +70,10 @@ public abstract class VersionList { }); } - private Collection> getVersionsImpl(String gameVersion) { + private Collection getVersionsImpl(String gameVersion) { lock.readLock().lock(); try { - Collection> ans = versions.get(gameVersion); + Collection ans = versions.get(gameVersion); return ans.isEmpty() ? versions.values() : ans; } finally { lock.readLock().unlock(); @@ -84,7 +86,7 @@ public abstract class VersionList { * @param gameVersion the Minecraft version that remote versions belong to * @return the collection of specific remote versions */ - public final Collection> getVersions(String gameVersion) { + public final Collection getVersions(String gameVersion) { return Collections.unmodifiableCollection(getVersionsImpl(gameVersion)); } @@ -95,11 +97,11 @@ public abstract class VersionList { * @param remoteVersion the version of the remote version. * @return the specific remote version, null if it is not found. */ - public final Optional> getVersion(String gameVersion, String remoteVersion) { + public final Optional getVersion(String gameVersion, String remoteVersion) { lock.readLock().lock(); try { - RemoteVersion result = null; - for (RemoteVersion it : versions.get(gameVersion)) + T result = null; + for (T it : versions.get(gameVersion)) if (remoteVersion.equals(it.getSelfVersion())) result = it; return Optional.ofNullable(result); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeRemoteVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeRemoteVersion.java index 53299e69b..abd04e3a9 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeRemoteVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeRemoteVersion.java @@ -19,7 +19,7 @@ package org.jackhuang.hmcl.download.forge; import org.jackhuang.hmcl.download.RemoteVersion; -public class ForgeRemoteVersion extends RemoteVersion { +public class ForgeRemoteVersion extends RemoteVersion { /** * Constructor. * @@ -28,6 +28,6 @@ public class ForgeRemoteVersion extends RemoteVersion { * @param url the installer or universal jar URL. */ public ForgeRemoteVersion(String gameVersion, String selfVersion, String url) { - super(gameVersion, selfVersion, url, null); + super(gameVersion, selfVersion, url); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeVersionList.java index 4c0e46e07..c5c6f18df 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/forge/ForgeVersionList.java @@ -32,13 +32,18 @@ import java.util.*; * * @author huangyuhui */ -public final class ForgeVersionList extends VersionList { +public final class ForgeVersionList extends VersionList { public static final ForgeVersionList INSTANCE = new ForgeVersionList(); private ForgeVersionList() { } + @Override + public boolean hasType() { + return false; + } + @Override public Task refreshAsync(DownloadProvider downloadProvider) { final GetTask task = new GetTask(NetworkUtils.toURL(downloadProvider.injectURL(FORGE_LIST))); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersion.java index cf5e720c8..ac86f3f0e 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersion.java @@ -17,12 +17,9 @@ */ package org.jackhuang.hmcl.download.game; -import com.google.gson.JsonParseException; -import com.google.gson.annotations.SerializedName; +import org.jackhuang.hmcl.download.RemoteVersion; import org.jackhuang.hmcl.game.ReleaseType; -import org.jackhuang.hmcl.util.Constants; -import org.jackhuang.hmcl.util.StringUtils; -import org.jackhuang.hmcl.util.Validation; +import org.jackhuang.hmcl.util.Immutable; import java.util.Date; @@ -30,64 +27,31 @@ import java.util.Date; * * @author huangyuhui */ -public final class GameRemoteVersion implements Validation { +@Immutable +public final class GameRemoteVersion extends RemoteVersion { - @SerializedName("id") - private final String gameVersion; - - @SerializedName("time") + private final ReleaseType type; private final Date time; - @SerializedName("releaseTime") - private final Date releaseTime; - - @SerializedName("type") - private final ReleaseType type; - - @SerializedName("url") - private final String url; - - public GameRemoteVersion() { - this("", new Date(), new Date(), ReleaseType.UNKNOWN); - } - - public GameRemoteVersion(String gameVersion, Date time, Date releaseTime, ReleaseType type) { - this(gameVersion, time, releaseTime, type, Constants.DEFAULT_LIBRARY_URL + gameVersion + "/" + gameVersion + ".json"); - } - - public GameRemoteVersion(String gameVersion, Date time, Date releaseTime, ReleaseType type, String url) { - this.gameVersion = gameVersion; - this.time = time; - this.releaseTime = releaseTime; + public GameRemoteVersion(String gameVersion, String selfVersion, String url, ReleaseType type, Date time) { + super(gameVersion, selfVersion, url); this.type = type; - this.url = url; - } - - public String getGameVersion() { - return gameVersion; + this.time = time; } public Date getTime() { return time; } - public Date getReleaseTime() { - return releaseTime; - } - public ReleaseType getType() { return type; } - public String getUrl() { - return url; - } - @Override - public void validate() throws JsonParseException { - if (StringUtils.isBlank(gameVersion)) - throw new JsonParseException("GameRemoteVersion id cannot be blank"); - if (StringUtils.isBlank(url)) - throw new JsonParseException("GameRemoteVersion url cannot be blank"); + public int compareTo(RemoteVersion o) { + if (!(o instanceof GameRemoteVersion)) + return 0; + + return ((GameRemoteVersion) o).getTime().compareTo(getTime()); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersionInfo.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersionInfo.java new file mode 100644 index 000000000..23056d855 --- /dev/null +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersionInfo.java @@ -0,0 +1,93 @@ +/* + * Hello Minecraft! Launcher. + * Copyright (C) 2018 huangyuhui + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see {http://www.gnu.org/licenses/}. + */ +package org.jackhuang.hmcl.download.game; + +import com.google.gson.JsonParseException; +import com.google.gson.annotations.SerializedName; +import org.jackhuang.hmcl.game.ReleaseType; +import org.jackhuang.hmcl.util.Constants; +import org.jackhuang.hmcl.util.StringUtils; +import org.jackhuang.hmcl.util.Validation; + +import java.util.Date; + +/** + * + * @author huangyuhui + */ +public final class GameRemoteVersionInfo implements Validation { + + @SerializedName("id") + private final String gameVersion; + + @SerializedName("time") + private final Date time; + + @SerializedName("releaseTime") + private final Date releaseTime; + + @SerializedName("type") + private final ReleaseType type; + + @SerializedName("url") + private final String url; + + public GameRemoteVersionInfo() { + this("", new Date(), new Date(), ReleaseType.UNKNOWN); + } + + public GameRemoteVersionInfo(String gameVersion, Date time, Date releaseTime, ReleaseType type) { + this(gameVersion, time, releaseTime, type, Constants.DEFAULT_LIBRARY_URL + gameVersion + "/" + gameVersion + ".json"); + } + + public GameRemoteVersionInfo(String gameVersion, Date time, Date releaseTime, ReleaseType type, String url) { + this.gameVersion = gameVersion; + this.time = time; + this.releaseTime = releaseTime; + this.type = type; + this.url = url; + } + + public String getGameVersion() { + return gameVersion; + } + + public Date getTime() { + return time; + } + + public Date getReleaseTime() { + return releaseTime; + } + + public ReleaseType getType() { + return type; + } + + public String getUrl() { + return url; + } + + @Override + public void validate() throws JsonParseException { + if (StringUtils.isBlank(gameVersion)) + throw new JsonParseException("GameRemoteVersion id cannot be blank"); + if (StringUtils.isBlank(url)) + throw new JsonParseException("GameRemoteVersion url cannot be blank"); + } +} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersionTag.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersionTag.java deleted file mode 100644 index 5eb09685e..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersionTag.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Hello Minecraft! Launcher. - * Copyright (C) 2018 huangyuhui - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see {http://www.gnu.org/licenses/}. - */ -package org.jackhuang.hmcl.download.game; - -import org.jackhuang.hmcl.game.ReleaseType; -import org.jackhuang.hmcl.util.Immutable; - -import java.util.Date; - -/** - * - * @author huangyuhui - */ -@Immutable -public final class GameRemoteVersionTag { - - private final ReleaseType type; - private final Date time; - - /** - * No-arg constructor for Gson. - */ - @SuppressWarnings("unused") - public GameRemoteVersionTag() { - this(ReleaseType.UNKNOWN, new Date()); - } - - public GameRemoteVersionTag(ReleaseType type, Date time) { - this.type = type; - this.time = time; - } - - public Date getTime() { - return time; - } - - public ReleaseType getType() { - return type; - } -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersions.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersions.java index 3e3de34d2..1c2112b98 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersions.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameRemoteVersions.java @@ -31,7 +31,7 @@ import java.util.List; public final class GameRemoteVersions { @SerializedName("versions") - private final List versions; + private final List versions; @SerializedName("latest") private final GameRemoteLatestVersions latest; @@ -44,7 +44,7 @@ public final class GameRemoteVersions { this(Collections.emptyList(), null); } - public GameRemoteVersions(List versions, GameRemoteLatestVersions latest) { + public GameRemoteVersions(List versions, GameRemoteLatestVersions latest) { this.versions = versions; this.latest = latest; } @@ -53,7 +53,7 @@ public final class GameRemoteVersions { return latest; } - public List getVersions() { + public List getVersions() { return versions; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameVersionList.java index 7aa1b01cd..3c4a65e37 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/GameVersionList.java @@ -32,13 +32,18 @@ import java.util.Collections; * * @author huangyuhui */ -public final class GameVersionList extends VersionList { +public final class GameVersionList extends VersionList { public static final GameVersionList INSTANCE = new GameVersionList(); private GameVersionList() { } + @Override + public boolean hasType() { + return true; + } + @Override public Task refreshAsync(DownloadProvider downloadProvider) { GetTask task = new GetTask(NetworkUtils.toURL(downloadProvider.getVersionListURL())); @@ -56,12 +61,12 @@ public final class GameVersionList extends VersionList { versions.clear(); GameRemoteVersions root = Constants.GSON.fromJson(task.getResult(), GameRemoteVersions.class); - for (GameRemoteVersion remoteVersion : root.getVersions()) { - versions.put(remoteVersion.getGameVersion(), new RemoteVersionGame( + for (GameRemoteVersionInfo remoteVersion : root.getVersions()) { + versions.put(remoteVersion.getGameVersion(), new GameRemoteVersion( remoteVersion.getGameVersion(), remoteVersion.getGameVersion(), remoteVersion.getUrl(), - new GameRemoteVersionTag(remoteVersion.getType(), remoteVersion.getReleaseTime())) + remoteVersion.getType(), remoteVersion.getReleaseTime()) ); } } finally { @@ -70,15 +75,4 @@ public final class GameVersionList extends VersionList { } }; } - - private static class RemoteVersionGame extends RemoteVersion { - public RemoteVersionGame(String gameVersion, String selfVersion, String url, GameRemoteVersionTag tag) { - super(gameVersion, selfVersion, url, tag); - } - - @Override - public int compareTo(RemoteVersion o) { - return o.getTag().getTime().compareTo(getTag().getTime()); - } - } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/VersionJsonDownloadTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/VersionJsonDownloadTask.java index 061c393ca..bd27c53b9 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/VersionJsonDownloadTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/VersionJsonDownloadTask.java @@ -62,7 +62,7 @@ public final class VersionJsonDownloadTask extends Task { @Override public void execute() { - RemoteVersion remoteVersion = gameVersionList.getVersions(gameVersion).stream().findFirst() + RemoteVersion remoteVersion = gameVersionList.getVersions(gameVersion).stream().findFirst() .orElseThrow(() -> new IllegalStateException("Cannot find specific version " + gameVersion + " in remote repository")); String jsonURL = dependencyManager.getDownloadProvider().injectURL(remoteVersion.getUrl()); dependencies.add(new GetTask(NetworkUtils.toURL(jsonURL), ID)); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBMCLVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBMCLVersionList.java index d60674e25..e599bae28 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBMCLVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderBMCLVersionList.java @@ -39,13 +39,18 @@ import java.util.Optional; * * @author huangyuhui */ -public final class LiteLoaderBMCLVersionList extends VersionList { +public final class LiteLoaderBMCLVersionList extends VersionList { public static final LiteLoaderBMCLVersionList INSTANCE = new LiteLoaderBMCLVersionList(); private LiteLoaderBMCLVersionList() { } + @Override + public boolean hasType() { + return false; + } + @Override public Task refreshAsync(DownloadProvider downloadProvider) { GetTask task = new GetTask(NetworkUtils.toURL(downloadProvider.injectURL(LITELOADER_LIST))); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderInstallTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderInstallTask.java index 3cf3b2b22..09ea039ab 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderInstallTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderInstallTask.java @@ -74,7 +74,7 @@ public final class LiteLoaderInstallTask extends TaskResult { new LibrariesDownloadInfo(new LibraryDownloadInfo(null, remote.getUrl())) ); - Version tempVersion = version.setLibraries(Lang.merge(remote.getTag().getLibraries(), Collections.singleton(library))); + Version tempVersion = version.setLibraries(Lang.merge(remote.getLibraries(), Collections.singleton(library))); String mcArg = version.getMinecraftArguments().orElse(""); if (mcArg.contains("--tweakClass optifine.OptiFineTweaker")) @@ -84,7 +84,7 @@ public final class LiteLoaderInstallTask extends TaskResult { .setMainClass("net.minecraft.launchwrapper.Launch") .setLibraries(Lang.merge(tempVersion.getLibraries(), version.getLibraries())) .setLogging(Collections.emptyMap()) - .setMinecraftArguments(mcArg + " --tweakClass " + remote.getTag().getTweakClass()) + .setMinecraftArguments(mcArg + " --tweakClass " + remote.getTweakClass()) //.setArguments(Arguments.addGameArguments(Lang.get(version.getArguments()), "--tweakClass", remote.getTag().getTweakClass())) ); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemoteVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemoteVersion.java index 2e0d2692d..0f1507be1 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemoteVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemoteVersion.java @@ -22,7 +22,9 @@ import org.jackhuang.hmcl.game.Library; import java.util.Collection; -public class LiteLoaderRemoteVersion extends RemoteVersion { +public class LiteLoaderRemoteVersion extends RemoteVersion { + private final String tweakClass; + private final Collection libraries; /** * Constructor. * @@ -31,6 +33,18 @@ public class LiteLoaderRemoteVersion extends RemoteVersion libraries) { - super(gameVersion, selfVersion, url, new LiteLoaderRemoteVersionTag(tweakClass, libraries)); + super(gameVersion, selfVersion, url); + + this.tweakClass = tweakClass; + this.libraries = libraries; } + + public Collection getLibraries() { + return libraries; + } + + public String getTweakClass() { + return tweakClass; + } + } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemoteVersionTag.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemoteVersionTag.java deleted file mode 100644 index 0914ec74c..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemoteVersionTag.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Hello Minecraft! Launcher. - * Copyright (C) 2018 huangyuhui - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see {http://www.gnu.org/licenses/}. - */ -package org.jackhuang.hmcl.download.liteloader; - -import org.jackhuang.hmcl.game.Library; - -import java.util.Collection; -import java.util.Collections; - -/** - * - * @author huangyuhui - */ -public final class LiteLoaderRemoteVersionTag { - private final String tweakClass; - private final Collection libraries; - - /** - * No-arg constructor for Gson. - */ - @SuppressWarnings("unused") - public LiteLoaderRemoteVersionTag() { - this("", Collections.emptySet()); - } - - public LiteLoaderRemoteVersionTag(String tweakClass, Collection libraries) { - this.tweakClass = tweakClass; - this.libraries = libraries; - } - - public Collection getLibraries() { - return libraries; - } - - public String getTweakClass() { - return tweakClass; - } - -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionList.java index d3b243e46..d5dd66534 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/liteloader/LiteLoaderVersionList.java @@ -39,13 +39,18 @@ import java.util.Optional; * * @author huangyuhui */ -public final class LiteLoaderVersionList extends VersionList { +public final class LiteLoaderVersionList extends VersionList { public static final LiteLoaderVersionList INSTANCE = new LiteLoaderVersionList(); private LiteLoaderVersionList() { } + @Override + public boolean hasType() { + return false; + } + @Override public Task refreshAsync(DownloadProvider downloadProvider) { GetTask task = new GetTask(NetworkUtils.toURL(downloadProvider.injectURL(LITELOADER_LIST))); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineBMCLVersionList.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineBMCLVersionList.java index f6c9cc675..7602e2022 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineBMCLVersionList.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineBMCLVersionList.java @@ -33,13 +33,18 @@ import java.util.*; * * @author huangyuhui */ -public final class OptiFineBMCLVersionList extends VersionList { +public final class OptiFineBMCLVersionList extends VersionList { public static final OptiFineBMCLVersionList INSTANCE = new OptiFineBMCLVersionList(); private OptiFineBMCLVersionList() { } + @Override + public boolean hasType() { + return true; + } + @Override public Task refreshAsync(DownloadProvider downloadProvider) { GetTask task = new GetTask(NetworkUtils.toURL("http://bmclapi2.bangbang93.com/optifine/versionlist")); @@ -57,16 +62,16 @@ public final class OptiFineBMCLVersionList extends VersionList { }.getType()); for (OptiFineVersion element : root) { String version = element.getType() + "_" + element.getPatch(); - if (element.getType() == null || "pre".equals(element.getPatch())) - continue; String mirror = "http://bmclapi2.bangbang93.com/optifine/" + element.getGameVersion() + "/" + element.getType() + "/" + element.getPatch(); if (!duplicates.add(mirror)) continue; + boolean isPre = element.getPatch() != null && (element.getPatch().equals("pre") || element.getPatch().startsWith("alpha")); + if (StringUtils.isBlank(element.getGameVersion())) continue; VersionNumber.parseVersion(element.getGameVersion()) - .ifPresent(gameVersion -> versions.put(gameVersion, new OptiFineRemoteVersion(gameVersion, version, () -> mirror))); + .ifPresent(gameVersion -> versions.put(gameVersion, new OptiFineRemoteVersion(gameVersion, version, () -> mirror, isPre))); } } }; diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineRemoteVersion.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineRemoteVersion.java index c197c147c..8f66bd811 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineRemoteVersion.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/optifine/OptiFineRemoteVersion.java @@ -21,11 +21,11 @@ import org.jackhuang.hmcl.download.RemoteVersion; import java.util.function.Supplier; -public class OptiFineRemoteVersion extends RemoteVersion { +public class OptiFineRemoteVersion extends RemoteVersion { private final Supplier url; - public OptiFineRemoteVersion(String gameVersion, String selfVersion, Supplier url) { - super(gameVersion, selfVersion, "", null); + public OptiFineRemoteVersion(String gameVersion, String selfVersion, Supplier url, boolean snapshot) { + super(gameVersion, selfVersion, "", snapshot ? Type.SNAPSHOT : Type.RELEASE); this.url = url; }