mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-18 00:10:33 -04:00
refactor: ensure that VersionLists fetch original download URL
This commit is contained in:
parent
80f27f5ea4
commit
986a430e92
@ -24,6 +24,7 @@ import javafx.beans.InvalidationListener;
|
|||||||
import javafx.beans.Observable;
|
import javafx.beans.Observable;
|
||||||
import javafx.beans.property.*;
|
import javafx.beans.property.*;
|
||||||
import org.jackhuang.hmcl.download.DefaultDependencyManager;
|
import org.jackhuang.hmcl.download.DefaultDependencyManager;
|
||||||
|
import org.jackhuang.hmcl.download.DownloadProvider;
|
||||||
import org.jackhuang.hmcl.event.EventBus;
|
import org.jackhuang.hmcl.event.EventBus;
|
||||||
import org.jackhuang.hmcl.event.EventPriority;
|
import org.jackhuang.hmcl.event.EventPriority;
|
||||||
import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
|
import org.jackhuang.hmcl.event.RefreshedVersionsEvent;
|
||||||
@ -162,7 +163,11 @@ public final class Profile implements Observable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DefaultDependencyManager getDependency() {
|
public DefaultDependencyManager getDependency() {
|
||||||
return new DefaultDependencyManager(repository, DownloadProviders.getDownloadProvider(), DownloadProviders.getPreferredDownloadProviders(), HMCLCacheRepository.REPOSITORY);
|
return getDependency(DownloadProviders.getDownloadProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
public DefaultDependencyManager getDependency(DownloadProvider downloadProvider) {
|
||||||
|
return new DefaultDependencyManager(repository, downloadProvider, HMCLCacheRepository.REPOSITORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public VersionSetting getVersionSetting(String id) {
|
public VersionSetting getVersionSetting(String id) {
|
||||||
|
@ -23,16 +23,18 @@ import org.jackhuang.hmcl.download.RemoteVersion;
|
|||||||
import org.jackhuang.hmcl.game.Version;
|
import org.jackhuang.hmcl.game.Version;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class FabricRemoteVersion extends RemoteVersion {
|
public class FabricRemoteVersion extends RemoteVersion {
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param gameVersion the Minecraft version that this remote version suits.
|
* @param gameVersion the Minecraft version that this remote version suits.
|
||||||
* @param selfVersion the version string of the remote version.
|
* @param selfVersion the version string of the remote version.
|
||||||
* @param url the installer or universal jar URL.
|
* @param urls the installer or universal jar original URL.
|
||||||
*/
|
*/
|
||||||
FabricRemoteVersion(String gameVersion, String selfVersion, String url) {
|
FabricRemoteVersion(String gameVersion, String selfVersion, List<String> urls) {
|
||||||
super(LibraryAnalyzer.LibraryType.FABRIC.getPatchId(), gameVersion, selfVersion, url);
|
super(LibraryAnalyzer.LibraryType.FABRIC.getPatchId(), gameVersion, selfVersion, urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,6 +28,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import javax.xml.stream.XMLStreamException;
|
import javax.xml.stream.XMLStreamException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -56,7 +57,8 @@ public final class FabricVersionList extends VersionList<FabricRemoteVersion> {
|
|||||||
try {
|
try {
|
||||||
for (String gameVersion : gameVersions)
|
for (String gameVersion : gameVersions)
|
||||||
for (String loaderVersion : loaderVersions)
|
for (String loaderVersion : loaderVersions)
|
||||||
versions.put(gameVersion, new FabricRemoteVersion(gameVersion, loaderVersion, ""));
|
versions.put(gameVersion, new FabricRemoteVersion(gameVersion, loaderVersion,
|
||||||
|
Collections.singletonList(getLaunchMetaUrl(gameVersion, loaderVersion))));
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
@ -73,6 +75,10 @@ public final class FabricVersionList extends VersionList<FabricRemoteVersion> {
|
|||||||
}.getType()).stream().map(GameVersion::getVersion).collect(Collectors.toList());
|
}.getType()).stream().map(GameVersion::getVersion).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getLaunchMetaUrl(String gameVersion, String loaderVersion) {
|
||||||
|
return String.format("https://meta.fabricmc.net/v2/versions/loader/%s/%s", gameVersion, loaderVersion);
|
||||||
|
}
|
||||||
|
|
||||||
private static class GameVersion {
|
private static class GameVersion {
|
||||||
private final String version;
|
private final String version;
|
||||||
private final String maven;
|
private final String maven;
|
||||||
|
@ -102,8 +102,7 @@ public final class ForgeBMCLVersionList extends VersionList<ForgeRemoteVersion>
|
|||||||
if (urls.isEmpty())
|
if (urls.isEmpty())
|
||||||
continue;
|
continue;
|
||||||
versions.put(gameVersion, new ForgeRemoteVersion(
|
versions.put(gameVersion, new ForgeRemoteVersion(
|
||||||
version.getGameVersion(), version.getVersion(), urls.toArray(new String[0])
|
version.getGameVersion(), version.getVersion(), urls));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
|
@ -26,7 +26,9 @@ import org.jackhuang.hmcl.util.gson.JsonUtils;
|
|||||||
import org.jackhuang.hmcl.util.io.NetworkUtils;
|
import org.jackhuang.hmcl.util.io.NetworkUtils;
|
||||||
import org.jackhuang.hmcl.util.versioning.VersionNumber;
|
import org.jackhuang.hmcl.util.versioning.VersionNumber;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -76,13 +78,13 @@ public final class ForgeVersionList extends VersionList<ForgeRemoteVersion> {
|
|||||||
String classifier = version.getGameVersion() + "-" + version.getVersion()
|
String classifier = version.getGameVersion() + "-" + version.getVersion()
|
||||||
+ (StringUtils.isNotBlank(version.getBranch()) ? "-" + version.getBranch() : "");
|
+ (StringUtils.isNotBlank(version.getBranch()) ? "-" + version.getBranch() : "");
|
||||||
String fileName = root.getArtifact() + "-" + classifier + "-" + file[1] + "." + file[0];
|
String fileName = root.getArtifact() + "-" + classifier + "-" + file[1] + "." + file[0];
|
||||||
jar = downloadProvider.injectURL(root.getWebPath() + classifier + "/" + fileName);
|
jar = root.getWebPath() + classifier + "/" + fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (jar == null)
|
if (jar == null)
|
||||||
continue;
|
continue;
|
||||||
versions.put(gameVersion, new ForgeRemoteVersion(
|
versions.put(gameVersion, new ForgeRemoteVersion(
|
||||||
version.getGameVersion(), version.getVersion(), jar
|
version.getGameVersion(), version.getVersion(), Collections.singletonList(jar)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import org.jackhuang.hmcl.task.Task;
|
|||||||
import org.jackhuang.hmcl.util.Immutable;
|
import org.jackhuang.hmcl.util.Immutable;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -37,7 +38,7 @@ public final class GameRemoteVersion extends RemoteVersion {
|
|||||||
private final ReleaseType type;
|
private final ReleaseType type;
|
||||||
private final Date time;
|
private final Date time;
|
||||||
|
|
||||||
public GameRemoteVersion(String gameVersion, String selfVersion, String url, ReleaseType type, Date time) {
|
public GameRemoteVersion(String gameVersion, String selfVersion, List<String> url, ReleaseType type, Date time) {
|
||||||
super(LibraryAnalyzer.LibraryType.MINECRAFT.getPatchId(), gameVersion, selfVersion, getReleaseType(type), url);
|
super(LibraryAnalyzer.LibraryType.MINECRAFT.getPatchId(), gameVersion, selfVersion, getReleaseType(type), url);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
|
@ -74,7 +74,7 @@ public final class GameVersionList extends VersionList<GameRemoteVersion> {
|
|||||||
versions.put(remoteVersion.getGameVersion(), new GameRemoteVersion(
|
versions.put(remoteVersion.getGameVersion(), new GameRemoteVersion(
|
||||||
remoteVersion.getGameVersion(),
|
remoteVersion.getGameVersion(),
|
||||||
remoteVersion.getGameVersion(),
|
remoteVersion.getGameVersion(),
|
||||||
remoteVersion.getUrl(),
|
Collections.singletonList(remoteVersion.getUrl()),
|
||||||
remoteVersion.getType(), remoteVersion.getReleaseTime())
|
remoteVersion.getType(), remoteVersion.getReleaseTime())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ public final class LiteLoaderBMCLVersionList extends VersionList<LiteLoaderRemot
|
|||||||
}
|
}
|
||||||
|
|
||||||
versions.put(key, new LiteLoaderRemoteVersion(gameVersion,
|
versions.put(key, new LiteLoaderRemoteVersion(gameVersion,
|
||||||
version, url,
|
version, Collections.singletonList(url),
|
||||||
v.getTweakClass(), v.getLibraries()
|
v.getTweakClass(), v.getLibraries()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public final class LiteLoaderInstallTask extends Task<Version> {
|
|||||||
Library library = new Library(
|
Library library = new Library(
|
||||||
new Artifact("com.mumfrey", "liteloader", remote.getSelfVersion()),
|
new Artifact("com.mumfrey", "liteloader", remote.getSelfVersion()),
|
||||||
"http://dl.liteloader.com/versions/",
|
"http://dl.liteloader.com/versions/",
|
||||||
new LibrariesDownloadInfo(new LibraryDownloadInfo(null, remote.getUrl()[0]))
|
new LibrariesDownloadInfo(new LibraryDownloadInfo(null, remote.getUrls().get(0)))
|
||||||
);
|
);
|
||||||
|
|
||||||
setResult(new Version(LibraryAnalyzer.LibraryType.LITELOADER.getPatchId(),
|
setResult(new Version(LibraryAnalyzer.LibraryType.LITELOADER.getPatchId(),
|
||||||
|
@ -25,6 +25,7 @@ import org.jackhuang.hmcl.game.Version;
|
|||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class LiteLoaderRemoteVersion extends RemoteVersion {
|
public class LiteLoaderRemoteVersion extends RemoteVersion {
|
||||||
private final String tweakClass;
|
private final String tweakClass;
|
||||||
@ -34,10 +35,10 @@ public class LiteLoaderRemoteVersion extends RemoteVersion {
|
|||||||
*
|
*
|
||||||
* @param gameVersion the Minecraft version that this remote version suits.
|
* @param gameVersion the Minecraft version that this remote version suits.
|
||||||
* @param selfVersion the version string of the remote version.
|
* @param selfVersion the version string of the remote version.
|
||||||
* @param url the installer or universal jar URL.
|
* @param urls the installer or universal jar original URL.
|
||||||
*/
|
*/
|
||||||
LiteLoaderRemoteVersion(String gameVersion, String selfVersion, String url, String tweakClass, Collection<Library> libraries) {
|
LiteLoaderRemoteVersion(String gameVersion, String selfVersion, List<String> urls, String tweakClass, Collection<Library> libraries) {
|
||||||
super(LibraryAnalyzer.LibraryType.LITELOADER.getPatchId(), gameVersion, selfVersion, url);
|
super(LibraryAnalyzer.LibraryType.LITELOADER.getPatchId(), gameVersion, selfVersion, urls);
|
||||||
|
|
||||||
this.tweakClass = tweakClass;
|
this.tweakClass = tweakClass;
|
||||||
this.libraries = libraries;
|
this.libraries = libraries;
|
||||||
|
@ -102,7 +102,7 @@ public final class LiteLoaderVersionList extends VersionList<LiteLoaderRemoteVer
|
|||||||
}
|
}
|
||||||
|
|
||||||
versions.put(key, new LiteLoaderRemoteVersion(gameVersion,
|
versions.put(key, new LiteLoaderRemoteVersion(gameVersion,
|
||||||
version, downloadProvider.injectURL(url),
|
version, Collections.singletonList(url),
|
||||||
v.getTweakClass(), v.getLibraries()
|
v.getTweakClass(), v.getLibraries()
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ public final class OptiFineBMCLVersionList extends VersionList<OptiFineRemoteVer
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
String gameVersion = VersionNumber.normalize(element.getGameVersion());
|
String gameVersion = VersionNumber.normalize(element.getGameVersion());
|
||||||
versions.put(gameVersion, new OptiFineRemoteVersion(gameVersion, version, mirror, isPre));
|
versions.put(gameVersion, new OptiFineRemoteVersion(gameVersion, version, Collections.singletonList(mirror), isPre));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
lock.writeLock().unlock();
|
lock.writeLock().unlock();
|
||||||
|
@ -81,7 +81,7 @@ public final class OptiFineInstallTask extends Task<Version> {
|
|||||||
new Artifact("optifine", "OptiFine", mavenVersion, "installer"), null,
|
new Artifact("optifine", "OptiFine", mavenVersion, "installer"), null,
|
||||||
new LibrariesDownloadInfo(new LibraryDownloadInfo(
|
new LibrariesDownloadInfo(new LibraryDownloadInfo(
|
||||||
"optifine/OptiFine/" + mavenVersion + "/OptiFine-" + mavenVersion + "-installer.jar",
|
"optifine/OptiFine/" + mavenVersion + "/OptiFine-" + mavenVersion + "-installer.jar",
|
||||||
remote.getUrl()[0]))
|
remote.getUrls().get(0).toString()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ public final class OptiFineInstallTask extends Task<Version> {
|
|||||||
throw new VersionMismatchException(mcVersion, gameVersion.get());
|
throw new VersionMismatchException(mcVersion, gameVersion.get());
|
||||||
|
|
||||||
return new OptiFineInstallTask(dependencyManager, version,
|
return new OptiFineInstallTask(dependencyManager, version,
|
||||||
new OptiFineRemoteVersion(mcVersion, ofEdition + "_" + ofRelease, "", false), installer);
|
new OptiFineRemoteVersion(mcVersion, ofEdition + "_" + ofRelease, Collections.singletonList(""), false), installer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ import org.jackhuang.hmcl.download.RemoteVersion;
|
|||||||
import org.jackhuang.hmcl.game.Version;
|
import org.jackhuang.hmcl.game.Version;
|
||||||
import org.jackhuang.hmcl.task.Task;
|
import org.jackhuang.hmcl.task.Task;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
import java.util.List;
|
||||||
|
|
||||||
public class OptiFineRemoteVersion extends RemoteVersion {
|
public class OptiFineRemoteVersion extends RemoteVersion {
|
||||||
|
|
||||||
public OptiFineRemoteVersion(String gameVersion, String selfVersion, String url, boolean snapshot) {
|
public OptiFineRemoteVersion(String gameVersion, String selfVersion, List<String> urls, boolean snapshot) {
|
||||||
super(LibraryAnalyzer.LibraryType.OPTIFINE.getPatchId(), gameVersion, selfVersion, snapshot ? Type.SNAPSHOT : Type.RELEASE, url);
|
super(LibraryAnalyzer.LibraryType.OPTIFINE.getPatchId(), gameVersion, selfVersion, snapshot ? Type.SNAPSHOT : Type.RELEASE, urls);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user