-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
308 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 20 additions & 4 deletions
24
jmccc-cli/src/main/java/jmccc/cli/download/ModLoaderDownloader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,34 @@ | ||
package jmccc.cli.download; | ||
|
||
import org.to2mbn.jmccc.mcdownloader.provider.fabric.FabricVersion; | ||
import org.to2mbn.jmccc.mcdownloader.provider.forge.ForgeVersion; | ||
import org.to2mbn.jmccc.mcdownloader.provider.liteloader.LiteloaderVersion; | ||
|
||
import java.util.concurrent.ExecutionException; | ||
|
||
public class ModLoaderDownloader { | ||
public static ForgeVersion getLatestForge() throws ExecutionException, InterruptedException { | ||
return SimpleDownloader.downloader.download(SimpleDownloader.forgeProvider.forgeVersionList(), null) | ||
.get().getLatest(); | ||
return SimpleDownloader.get(SimpleDownloader.forgeProvider.forgeVersionList()).getLatest(); | ||
} | ||
|
||
public static LiteloaderVersion getLatestLiteLoader() throws ExecutionException, InterruptedException { | ||
return SimpleDownloader.downloader.download(SimpleDownloader.liteloaderProvider.liteloaderVersionList(), null) | ||
.get().getSnapshot("1.12.2"); | ||
return SimpleDownloader.get(SimpleDownloader.liteloaderProvider.liteloaderVersionList()) | ||
.getSnapshot("1.12.2"); | ||
} | ||
|
||
public static FabricVersion getLatestFabric() throws ExecutionException, InterruptedException { | ||
return SimpleDownloader.get(SimpleDownloader.fabricProvider.fabricVersionList()).getLatestRelease(); | ||
} | ||
|
||
public static FabricVersion getLatestFabricSnapshot() throws ExecutionException, InterruptedException { | ||
return SimpleDownloader.get(SimpleDownloader.fabricProvider.fabricVersionList()).getLatestSnapshot(); | ||
} | ||
|
||
public static FabricVersion getLatestQuilt() throws ExecutionException, InterruptedException { | ||
return SimpleDownloader.get(SimpleDownloader.quiltProvider.fabricVersionList()).getLatestRelease(); | ||
} | ||
|
||
public static FabricVersion getLatestQuiltSnapshot() throws ExecutionException, InterruptedException { | ||
return SimpleDownloader.get(SimpleDownloader.quiltProvider.fabricVersionList()).getLatestSnapshot(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...r/src/main/java/org/to2mbn/jmccc/mcdownloader/provider/fabric/FabricDownloadProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.to2mbn.jmccc.mcdownloader.provider.fabric; | ||
|
||
import org.to2mbn.jmccc.mcdownloader.download.cache.CacheNames; | ||
import org.to2mbn.jmccc.mcdownloader.download.combine.CombinedDownloadTask; | ||
import org.to2mbn.jmccc.mcdownloader.download.tasks.MemoryDownloadTask; | ||
import org.to2mbn.jmccc.mcdownloader.provider.*; | ||
import org.to2mbn.jmccc.option.MinecraftDirectory; | ||
|
||
public class FabricDownloadProvider extends AbstractMinecraftDownloadProvider implements ExtendedDownloadProvider { | ||
private MinecraftDownloadProvider upstreamProvider; | ||
private FabricDownloadSource source; | ||
|
||
public FabricDownloadProvider(FabricDownloadSource source) { | ||
this.source = source; | ||
} | ||
|
||
public FabricDownloadProvider() { | ||
this(new FabricDownloadSource.Default()); | ||
} | ||
|
||
@Override | ||
public void setUpstreamProvider(MinecraftDownloadProvider upstreamProvider) { | ||
this.upstreamProvider = upstreamProvider; | ||
} | ||
|
||
public CombinedDownloadTask<FabricVersionList> fabricVersionList() { | ||
return CombinedDownloadTask.single(new MemoryDownloadTask(source.getFabricVersionsUrl()) | ||
.andThen(new JsonDecoder()) | ||
.andThen(FabricVersionList::fromJson) | ||
.cacheable() | ||
.cachePool(CacheNames.FABRIC_VERSION_LIST)); | ||
} | ||
|
||
@Override | ||
public CombinedDownloadTask<String> gameVersionJson(MinecraftDirectory mcdir, String version) { | ||
FabricVersion fabricVersion = FabricVersion.resolve(getLoaderName(), version); | ||
if (fabricVersion == null) { | ||
return null; | ||
} | ||
String url = source.getFabricProfileUrl( | ||
fabricVersion.getMinecraftVersion(), fabricVersion.getFabricLoaderVersion()); | ||
return CombinedDownloadTask.single(new MemoryDownloadTask(url)) | ||
.andThen(new JsonDecoder()) | ||
.andThen(new VersionJsonInstaller(mcdir)); | ||
} | ||
|
||
protected String getLoaderName() { | ||
return "fabric"; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...der/src/main/java/org/to2mbn/jmccc/mcdownloader/provider/fabric/FabricDownloadSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.to2mbn.jmccc.mcdownloader.provider.fabric; | ||
|
||
public interface FabricDownloadSource { | ||
default String getFabricMetaBaseUrl() { | ||
return "https://meta.fabricmc.net/v2/"; | ||
} | ||
|
||
default String getFabricVersionsUrl() { | ||
return getFabricMetaBaseUrl() + "versions"; | ||
} | ||
|
||
default String getFabricProfileUrl(String minecraftVersion, String loaderVersion) { | ||
return String.format("%sversions/loader/%s/%s/profile/json", getFabricMetaBaseUrl(), | ||
minecraftVersion, loaderVersion); | ||
} | ||
|
||
class Default implements FabricDownloadSource { | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...downloader/src/main/java/org/to2mbn/jmccc/mcdownloader/provider/fabric/FabricVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.to2mbn.jmccc.mcdownloader.provider.fabric; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class FabricVersion { | ||
private final String minecraftVersion; | ||
private final String fabricLoaderVersion; | ||
private final String loaderName; | ||
|
||
public FabricVersion(String minecraftVersion, String fabricLoaderVersion, String loaderName) { | ||
this.minecraftVersion = minecraftVersion; | ||
this.fabricLoaderVersion = fabricLoaderVersion; | ||
this.loaderName = loaderName; | ||
} | ||
|
||
private static final Pattern PATTERN = Pattern.compile("^([\\w.\\-]+)-loader-([\\w.\\-]+)-([\\w.\\-]+)$"); | ||
|
||
public static FabricVersion resolve(String loaderName, String version) { | ||
Matcher m = PATTERN.matcher(version); | ||
if (m.matches()) { | ||
//Check loader name | ||
if (!loaderName.equals(m.group(1))) { | ||
return null; | ||
} | ||
return new FabricVersion(m.group(3), m.group(2), m.group(1)); | ||
} | ||
return null; | ||
} | ||
|
||
public String getVersionName() { | ||
return loaderName + "-loader-" + fabricLoaderVersion + "-" + minecraftVersion; | ||
} | ||
|
||
public String getMinecraftVersion() { | ||
return minecraftVersion; | ||
} | ||
|
||
public String getFabricLoaderVersion() { | ||
return fabricLoaderVersion; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...loader/src/main/java/org/to2mbn/jmccc/mcdownloader/provider/fabric/FabricVersionList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.to2mbn.jmccc.mcdownloader.provider.fabric; | ||
|
||
import org.to2mbn.jmccc.internal.org.json.JSONArray; | ||
import org.to2mbn.jmccc.internal.org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FabricVersionList { | ||
private final List<String> minecraftReleaseVersions; | ||
private final List<String> minecraftSnapshotVersions; | ||
private final List<String> fabricLoaderVersions; | ||
private final String loaderName; | ||
|
||
public FabricVersionList(List<String> minecraftReleaseVersions, List<String> minecraftSnapshotVersions, List<String> fabricLoaderVersions, String loaderName) { | ||
this.minecraftReleaseVersions = minecraftReleaseVersions; | ||
this.minecraftSnapshotVersions = minecraftSnapshotVersions; | ||
this.fabricLoaderVersions = fabricLoaderVersions; | ||
this.loaderName = loaderName; | ||
} | ||
|
||
public FabricVersion getLatest(String minecraftVersion) { | ||
return new FabricVersion(minecraftVersion, fabricLoaderVersions.get(0), loaderName); | ||
} | ||
|
||
public FabricVersion getLatestRelease() { | ||
return new FabricVersion(minecraftReleaseVersions.get(0), fabricLoaderVersions.get(0), loaderName); | ||
} | ||
|
||
public FabricVersion getLatestSnapshot() { | ||
return new FabricVersion(minecraftSnapshotVersions.get(0), fabricLoaderVersions.get(0), loaderName); | ||
} | ||
|
||
public static FabricVersionList fromJson(JSONObject json) { | ||
JSONArray game = json.getJSONArray("game"); | ||
List<String> minecraftReleaseVersions = new ArrayList<>(); | ||
List<String> minecraftSnapshotVersions = new ArrayList<>(); | ||
for (Object obj : game) { | ||
JSONObject it = (JSONObject) obj; | ||
(it.getBoolean("stable") ? minecraftReleaseVersions : minecraftSnapshotVersions) | ||
.add(it.getString("version")); | ||
} | ||
|
||
JSONArray loader = json.getJSONArray("loader"); | ||
List<String> fabricLoaderVersions = new ArrayList<>(); | ||
String loaderName = "fabric"; | ||
for (Object obj : loader) { | ||
JSONObject it = (JSONObject) obj; | ||
if (it.getString("maven").contains("quilt")) { | ||
loaderName = "quilt"; | ||
} | ||
fabricLoaderVersions.add(it.getString("version")); | ||
} | ||
|
||
return new FabricVersionList(minecraftReleaseVersions, minecraftSnapshotVersions, | ||
fabricLoaderVersions, loaderName); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "FabricVersionList{ Latest: " + fabricLoaderVersions.get(0) + " }"; | ||
} | ||
} |
Oops, something went wrong.