Improve curseforge fetcher
This commit is contained in:
parent
58ffdcaeb0
commit
0fb768a90e
11
build.gradle
11
build.gradle
|
@ -11,18 +11,17 @@ archivesBaseName = project.archives_base_name
|
||||||
version = project.mod_version
|
version = project.mod_version
|
||||||
group = project.maven_group
|
group = project.maven_group
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven { url = "https://maven.terraformersmc.com/"; name = "ModMenu" }
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
//to change the versions see the gradle.properties file
|
|
||||||
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
minecraft "com.mojang:minecraft:${project.minecraft_version}"
|
||||||
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
|
||||||
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
|
||||||
|
|
||||||
// Fabric API. This is technically optional, but you probably want it anyway.
|
|
||||||
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
|
||||||
|
modCompile "com.terraformersmc:modmenu:1.16.7"
|
||||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
|
||||||
// You may need to force-disable transitiveness on them.
|
|
||||||
modCompile("io.github.prospector:modmenu:1.14.9+build.14")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
|
|
|
@ -2,13 +2,13 @@
|
||||||
org.gradle.jvmargs=-Xmx1G
|
org.gradle.jvmargs=-Xmx1G
|
||||||
# Fabric Properties
|
# Fabric Properties
|
||||||
# check these on https://modmuss50.me/fabric.html
|
# check these on https://modmuss50.me/fabric.html
|
||||||
minecraft_version=1.16.4
|
minecraft_version=1.16.5
|
||||||
yarn_mappings=1.16.4+build.7
|
yarn_mappings=1.16.5+build.4
|
||||||
loader_version=0.10.8
|
loader_version=0.11.1
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.2.0
|
mod_version=1.3.0
|
||||||
maven_group=io.gitlab.jfronny
|
maven_group=io.gitlab.jfronny
|
||||||
archives_base_name=resclone
|
archives_base_name=resclone
|
||||||
# Dependencies
|
# Dependencies
|
||||||
# check this on https://modmuss50.me/fabric.html
|
# check this on https://modmuss50.me/fabric.html
|
||||||
fabric_version=0.25.1+build.416-1.16
|
fabric_version=0.30.3+1.16
|
||||||
|
|
|
@ -31,6 +31,7 @@ public class Resclone implements ModInitializer, RescloneApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
|
System.out.println("[resclone] Beginning init, will download packs");
|
||||||
conf.clear();
|
conf.clear();
|
||||||
fetcherInstances.clear();
|
fetcherInstances.clear();
|
||||||
processors.clear();
|
processors.clear();
|
||||||
|
@ -45,6 +46,7 @@ public class Resclone implements ModInitializer, RescloneApi {
|
||||||
}
|
}
|
||||||
addProcessor(new RemoveEmptyProcessor());
|
addProcessor(new RemoveEmptyProcessor());
|
||||||
reload();
|
reload();
|
||||||
|
System.out.println("[resclone] Completed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
package io.gitlab.jfronny.resclone.data;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class CfAddon {
|
||||||
|
public String downloadUrl;
|
||||||
|
public String fileDate;
|
||||||
|
public Set<String> gameVersion;
|
||||||
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
package io.gitlab.jfronny.resclone.fetchers;
|
package io.gitlab.jfronny.resclone.fetchers;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import io.gitlab.jfronny.resclone.data.CfAddon;
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import io.gitlab.jfronny.resclone.data.RescloneException;
|
import io.gitlab.jfronny.resclone.data.RescloneException;
|
||||||
|
import net.minecraft.MinecraftVersion;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public class CurseforgeFetcher extends PackFetcher {
|
public class CurseforgeFetcher extends PackFetcher {
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,8 +16,31 @@ public class CurseforgeFetcher extends PackFetcher {
|
||||||
@Override
|
@Override
|
||||||
public String getDownloadUrl(String baseUrl) throws RescloneException {
|
public String getDownloadUrl(String baseUrl) throws RescloneException {
|
||||||
try {
|
try {
|
||||||
JsonObject latest = (JsonObject)readJsonFromURL("https://addons-ecs.forgesvc.net/api/v2/addon/" + baseUrl + "/files", JsonArray.class).get(0);
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SSS'Z'");
|
||||||
return latest.get("downloadUrl").getAsString();
|
|
||||||
|
String version = MinecraftVersion.field_25319.getName();
|
||||||
|
|
||||||
|
CfAddon latest = null;
|
||||||
|
Date latestDate = null;
|
||||||
|
boolean foundMatchingVersion = false;
|
||||||
|
|
||||||
|
for (CfAddon addon : readJsonFromURLSet("https://addons-ecs.forgesvc.net/api/v2/addon/" + baseUrl + "/files", CfAddon.class)) {
|
||||||
|
Date d = df.parse(addon.fileDate);
|
||||||
|
if (foundMatchingVersion && !addon.gameVersion.contains(version))
|
||||||
|
continue;
|
||||||
|
if (!foundMatchingVersion && addon.gameVersion.contains(version)) {
|
||||||
|
foundMatchingVersion = true;
|
||||||
|
latest = null;
|
||||||
|
}
|
||||||
|
if (latest == null || d.after(latestDate)) {
|
||||||
|
latest = addon;
|
||||||
|
latestDate = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundMatchingVersion)
|
||||||
|
System.err.println("Could not find pack for matching version, using latest");
|
||||||
|
return latest.downloadUrl;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new RescloneException("Could not get CF download for " + baseUrl, e);
|
throw new RescloneException("Could not get CF download for " + baseUrl, e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package io.gitlab.jfronny.resclone.fetchers;
|
package io.gitlab.jfronny.resclone.fetchers;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
import io.gitlab.jfronny.resclone.Resclone;
|
import io.gitlab.jfronny.resclone.Resclone;
|
||||||
import io.gitlab.jfronny.resclone.data.RescloneException;
|
import io.gitlab.jfronny.resclone.data.RescloneException;
|
||||||
|
|
||||||
|
@ -12,6 +13,7 @@ import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public abstract class PackFetcher {
|
public abstract class PackFetcher {
|
||||||
abstract public String getSourceTypeName(); // The name for users to specify in the config
|
abstract public String getSourceTypeName(); // The name for users to specify in the config
|
||||||
|
@ -41,8 +43,13 @@ public abstract class PackFetcher {
|
||||||
return gson.fromJson(readStringFromURL(requestUrl), classOfT);
|
return gson.fromJson(readStringFromURL(requestUrl), classOfT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> Set<T> readJsonFromURLSet(String requestUrl, Class<T> classOfT) throws IOException {
|
||||||
|
return gson.fromJson(readStringFromURL(requestUrl), TypeToken.getParameterized(Set.class, classOfT).getType());
|
||||||
|
}
|
||||||
|
|
||||||
public void get(String baseUrl, Path targetPath) throws RescloneException {
|
public void get(String baseUrl, Path targetPath) throws RescloneException {
|
||||||
String url = getDownloadUrl(baseUrl);
|
String url = getDownloadUrl(baseUrl);
|
||||||
|
System.out.println("Downloading pack " + url);
|
||||||
try (InputStream is = new URL(url).openStream()) {
|
try (InputStream is = new URL(url).openStream()) {
|
||||||
FileOutputStream os = new FileOutputStream(targetPath.toFile());
|
FileOutputStream os = new FileOutputStream(targetPath.toFile());
|
||||||
byte[] dataBuffer = new byte[1024];
|
byte[] dataBuffer = new byte[1024];
|
||||||
|
@ -50,6 +57,7 @@ public abstract class PackFetcher {
|
||||||
while ((bytesRead = is.read(dataBuffer, 0, 1024)) != -1) {
|
while ((bytesRead = is.read(dataBuffer, 0, 1024)) != -1) {
|
||||||
os.write(dataBuffer, 0, bytesRead);
|
os.write(dataBuffer, 0, bytesRead);
|
||||||
}
|
}
|
||||||
|
System.out.println("Completed download");
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
throw new RescloneException("Could not download pack", e);
|
throw new RescloneException("Could not download pack", e);
|
||||||
|
|
|
@ -21,21 +21,23 @@ public class PruneVanillaProcessor extends PackProcessor {
|
||||||
public void process(FileSystem p) throws RescloneException {
|
public void process(FileSystem p) throws RescloneException {
|
||||||
ClassLoader cl = MinecraftClient.class.getClassLoader();
|
ClassLoader cl = MinecraftClient.class.getClassLoader();
|
||||||
try {
|
try {
|
||||||
Files.walkFileTree(p.getPath("/assets/minecraft"), new PathPruneVisitor((s) -> {
|
if (Files.isDirectory(p.getPath("/assets/minecraft"))) {
|
||||||
if (Files.isDirectory(s))
|
Files.walkFileTree(p.getPath("/assets/minecraft"), new PathPruneVisitor((s) -> {
|
||||||
return false;
|
if (Files.isDirectory(s))
|
||||||
try {
|
return false;
|
||||||
InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString());
|
try {
|
||||||
if (vn != null) {
|
InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString());
|
||||||
InputStream pk = Files.newInputStream(s, StandardOpenOption.READ);
|
if (vn != null) {
|
||||||
return IOUtils.contentEquals(vn, pk);
|
InputStream pk = Files.newInputStream(s, StandardOpenOption.READ);
|
||||||
|
return IOUtils.contentEquals(vn, pk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
catch (Throwable e) {
|
||||||
catch (Throwable e) {
|
e.printStackTrace();
|
||||||
e.printStackTrace();
|
}
|
||||||
}
|
return false;
|
||||||
return false;
|
}));
|
||||||
}));
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RescloneException("Could not prune vanilla files", e);
|
throw new RescloneException("Could not prune vanilla files", e);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue