Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
00b43abd02 | |||
981d10d426 | |||
6df388aad7 | |||
88f071d919 | |||
e8d0b38121 | |||
12dd3f3301 | |||
6495212095 | |||
c4d424b792 | |||
d828de9464 | |||
4f6e31f584 |
@ -1,16 +1,47 @@
|
|||||||
import io.gitlab.jfronny.scripts.*
|
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("jfmod") version "1.3-SNAPSHOT"
|
id("jfmod") version "1.6-SNAPSHOT"
|
||||||
|
}
|
||||||
|
|
||||||
|
loom {
|
||||||
|
accessWidenerPath.set(file("src/main/resources/resclone.accesswidener"))
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects { group = "io.gitlab.jfronny" }
|
||||||
|
base.archivesName = "resclone"
|
||||||
|
|
||||||
|
val modmenuVersion = "11.0.0-beta.1"
|
||||||
|
val commonsVersion = "2.0.0-SNAPSHOT"
|
||||||
|
jfMod {
|
||||||
|
minecraftVersion = "1.21"
|
||||||
|
yarn("build.1")
|
||||||
|
loaderVersion = "0.15.11"
|
||||||
|
libJfVersion = "3.16.0"
|
||||||
|
fabricApiVersion = "0.100.1+1.21"
|
||||||
|
|
||||||
|
modrinth {
|
||||||
|
projectId = "resclone"
|
||||||
|
optionalDependencies.add("fabric-api")
|
||||||
|
}
|
||||||
|
curseforge {
|
||||||
|
projectId = "839008"
|
||||||
|
optionalDependencies.add("fabric-api")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
include(modImplementation("io.gitlab.jfronny.libjf:libjf-base:${prop("libjf_version")}")!!) // for JfCommons
|
include(modImplementation("io.gitlab.jfronny.libjf:libjf-base")!!) // for JfCommons
|
||||||
include(modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v1:${prop("libjf_version")}")!!) // for JfCommons
|
include(modImplementation("io.gitlab.jfronny.libjf:libjf-config-core-v2")!!) // for JfCommons
|
||||||
include(modImplementation(fabricApi.module("fabric-resource-loader-v0", prop("fabric_version")))!!)
|
include(modImplementation("net.fabricmc.fabric-api:fabric-resource-loader-v0")!!)
|
||||||
|
|
||||||
|
compileOnly("io.gitlab.jfronny:commons-serialize-generator-annotations:$commonsVersion")
|
||||||
|
annotationProcessor("io.gitlab.jfronny:commons-serialize-generator:$commonsVersion")
|
||||||
|
|
||||||
// Dev env
|
// Dev env
|
||||||
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-config-ui-tiny-v1:${prop("libjf_version")}")
|
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-config-ui-tiny")
|
||||||
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-devutil:${prop("libjf_version")}")
|
modLocalRuntime("io.gitlab.jfronny.libjf:libjf-devutil")
|
||||||
modLocalRuntime("com.terraformersmc:modmenu:${prop("modmenu_version")}")
|
modLocalRuntime("com.terraformersmc:modmenu:$modmenuVersion")
|
||||||
|
// for modmenu
|
||||||
|
modLocalRuntime("net.fabricmc.fabric-api:fabric-resource-loader-v0")
|
||||||
|
modLocalRuntime("net.fabricmc.fabric-api:fabric-screen-api-v1")
|
||||||
|
modLocalRuntime("net.fabricmc.fabric-api:fabric-key-binding-api-v1")
|
||||||
}
|
}
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
# https://fabricmc.net/develop
|
|
||||||
minecraft_version=1.19.4
|
|
||||||
yarn_mappings=build.1
|
|
||||||
loader_version=0.14.17
|
|
||||||
|
|
||||||
maven_group=io.gitlab.jfronny
|
|
||||||
archives_base_name=resclone
|
|
||||||
|
|
||||||
modrinth_id=resclone
|
|
||||||
|
|
||||||
fabric_version=0.75.3+1.19.4
|
|
||||||
libjf_version=3.6.0
|
|
||||||
modmenu_version=6.1.0-rc.1
|
|
@ -1,7 +1,6 @@
|
|||||||
package io.gitlab.jfronny.resclone;
|
package io.gitlab.jfronny.resclone;
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.log.Logger;
|
import io.gitlab.jfronny.commons.logger.SystemLoggerPlus;
|
||||||
import io.gitlab.jfronny.commons.serialize.gson.api.v1.GsonHolders;
|
|
||||||
import io.gitlab.jfronny.resclone.data.PackMetaLoaded;
|
import io.gitlab.jfronny.resclone.data.PackMetaLoaded;
|
||||||
import io.gitlab.jfronny.resclone.data.PackMetaUnloaded;
|
import io.gitlab.jfronny.resclone.data.PackMetaUnloaded;
|
||||||
import io.gitlab.jfronny.resclone.fetchers.*;
|
import io.gitlab.jfronny.resclone.fetchers.*;
|
||||||
@ -26,7 +25,7 @@ public class Resclone implements ModInitializer {
|
|||||||
public static final Set<PackMetaLoaded> NEW_PACKS = new LinkedHashSet<>(); // Client-only!
|
public static final Set<PackMetaLoaded> NEW_PACKS = new LinkedHashSet<>(); // Client-only!
|
||||||
|
|
||||||
public static final String MOD_ID = "resclone";
|
public static final String MOD_ID = "resclone";
|
||||||
public static final Logger LOGGER = Logger.forName(MOD_ID);
|
public static final SystemLoggerPlus LOGGER = SystemLoggerPlus.forName(MOD_ID);
|
||||||
public static final String USER_AGENT = "jfmods/" + MOD_ID + "/" + FabricLoader.getInstance()
|
public static final String USER_AGENT = "jfmods/" + MOD_ID + "/" + FabricLoader.getInstance()
|
||||||
.getModContainer(MOD_ID).orElseThrow()
|
.getModContainer(MOD_ID).orElseThrow()
|
||||||
.getMetadata()
|
.getMetadata()
|
||||||
@ -40,23 +39,24 @@ public class Resclone implements ModInitializer {
|
|||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
LOGGER.info("Initialising Resclone.");
|
LOGGER.info("Initialising Resclone.");
|
||||||
GsonHolders.registerSerializer();
|
|
||||||
|
|
||||||
urlCache = new PackUrlCache(getConfigPath().resolve("urlCache.properties"));
|
urlCache = new PackUrlCache(getConfigPath().resolve("urlCache.properties"));
|
||||||
FETCHER_INSTANCES.clear();
|
FETCHER_INSTANCES.clear();
|
||||||
PROCESSORS.clear();
|
PROCESSORS.clear();
|
||||||
DOWNLOADED_PACKS.clear();
|
DOWNLOADED_PACKS.clear();
|
||||||
|
|
||||||
addProcessor(new RootPathProcessor()); //This should be run before any other processor to make sure the path is valid
|
addProcessor(new RootPathProcessor()); //This should be run before any other processor to make sure the root is correct
|
||||||
addFetcher(new BasicFileFetcher());
|
addFetcher(new BasicFileFetcher());
|
||||||
addFetcher(new GitHubFetcher());
|
addFetcher(new GitHubFetcher());
|
||||||
addFetcher(new CurseforgeFetcher());
|
addFetcher(new CurseforgeFetcher());
|
||||||
addFetcher(new ModrinthFetcher());
|
addFetcher(new ModrinthFetcher());
|
||||||
|
if (RescloneConfig.filterPacks) {
|
||||||
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) addProcessor(new PruneVanillaProcessor());
|
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) addProcessor(new PruneVanillaProcessor());
|
||||||
addProcessor(new RemoveEmptyProcessor());
|
addProcessor(new RemoveEmptyProcessor());
|
||||||
|
}
|
||||||
reload();
|
reload();
|
||||||
|
|
||||||
LOGGER.info("Installed {} resource pack{}.", packCount, packCount == 1 ? "" : "s");
|
LOGGER.info("Installed {0} resource pack{1}.", packCount, packCount == 1 ? "" : "s");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addFetcher(PackFetcher fetcher) {
|
public void addFetcher(PackFetcher fetcher) {
|
||||||
@ -85,8 +85,7 @@ public class Resclone implements ModInitializer {
|
|||||||
LOGGER.info("No resclone pack was specified, add one");
|
LOGGER.info("No resclone pack was specified, add one");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try (ExecutorService pool = Executors.newFixedThreadPool(RescloneConfig.packs.size())) {
|
||||||
ExecutorService pool = Executors.newFixedThreadPool(RescloneConfig.packs.size());
|
|
||||||
for (PackMetaUnloaded s : RescloneConfig.packs) {
|
for (PackMetaUnloaded s : RescloneConfig.packs) {
|
||||||
pool.submit(generateTask(s, metas));
|
pool.submit(generateTask(s, metas));
|
||||||
}
|
}
|
||||||
@ -108,15 +107,15 @@ public class Resclone implements ModInitializer {
|
|||||||
private Runnable generateTask(PackMetaUnloaded meta, Set<PackMetaLoaded> metas) {
|
private Runnable generateTask(PackMetaUnloaded meta, Set<PackMetaLoaded> metas) {
|
||||||
return () -> {
|
return () -> {
|
||||||
try {
|
try {
|
||||||
if (!FETCHER_INSTANCES.containsKey(meta.fetcher))
|
if (!FETCHER_INSTANCES.containsKey(meta.fetcher()))
|
||||||
throw new Exception("Invalid fetcher: " + meta.fetcher);
|
throw new Exception("Invalid fetcher: " + meta.fetcher());
|
||||||
Path cacheDir = getConfigPath().resolve("cache");
|
Path cacheDir = getConfigPath().resolve("cache");
|
||||||
PackMetaLoaded p;
|
PackMetaLoaded p;
|
||||||
try {
|
try {
|
||||||
boolean isNew = !urlCache.containsKey(meta.source);
|
boolean isNew = !urlCache.containsKey(meta.source());
|
||||||
//Download
|
//Download
|
||||||
PackFetcher.Result fr = FETCHER_INSTANCES.get(meta.fetcher).get(meta.source, cacheDir, meta.forceDownload);
|
PackFetcher.Result fr = FETCHER_INSTANCES.get(meta.fetcher()).get(meta.source(), cacheDir, meta.forceDownload());
|
||||||
p = new PackMetaLoaded(fr.downloadPath(), meta.name, meta.forceEnable);
|
p = new PackMetaLoaded(fr.downloadPath(), meta.name(), meta.forceEnable());
|
||||||
metas.add(p);
|
metas.add(p);
|
||||||
if (isNew && FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) NEW_PACKS.add(p);
|
if (isNew && FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) NEW_PACKS.add(p);
|
||||||
if (fr.freshDownload()) {
|
if (fr.freshDownload()) {
|
||||||
@ -136,7 +135,7 @@ public class Resclone implements ModInitializer {
|
|||||||
throw new Exception("Failed to download pack", e);
|
throw new Exception("Failed to download pack", e);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
LOGGER.error("Encountered issue while preparing " + meta.name, e);
|
LOGGER.error("Encountered issue while preparing " + meta.name(), e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,18 @@
|
|||||||
package io.gitlab.jfronny.resclone;
|
package io.gitlab.jfronny.resclone;
|
||||||
|
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import io.gitlab.jfronny.commons.serialize.gson.api.v1.GsonHolders;
|
import io.gitlab.jfronny.commons.serialize.MalformedDataException;
|
||||||
import io.gitlab.jfronny.gson.JsonParseException;
|
import io.gitlab.jfronny.commons.serialize.Token;
|
||||||
import io.gitlab.jfronny.gson.stream.*;
|
import io.gitlab.jfronny.commons.serialize.json.JsonReader;
|
||||||
import io.gitlab.jfronny.libjf.config.api.v1.JfCustomConfig;
|
import io.gitlab.jfronny.commons.serialize.json.JsonWriter;
|
||||||
import io.gitlab.jfronny.libjf.config.api.v1.dsl.DSL;
|
import io.gitlab.jfronny.libjf.LibJf;
|
||||||
|
import io.gitlab.jfronny.libjf.config.api.v2.JfCustomConfig;
|
||||||
|
import io.gitlab.jfronny.libjf.config.api.v2.dsl.DSL;
|
||||||
|
import io.gitlab.jfronny.resclone.data.GC_PackMetaUnloaded;
|
||||||
import io.gitlab.jfronny.resclone.data.PackMetaUnloaded;
|
import io.gitlab.jfronny.resclone.data.PackMetaUnloaded;
|
||||||
|
import io.gitlab.jfronny.resclone.util.ListAdaptation;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Type;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -18,68 +21,108 @@ import java.util.Set;
|
|||||||
public class RescloneConfig implements JfCustomConfig {
|
public class RescloneConfig implements JfCustomConfig {
|
||||||
public static Set<PackMetaUnloaded> packs;
|
public static Set<PackMetaUnloaded> packs;
|
||||||
public static boolean pruneUnused;
|
public static boolean pruneUnused;
|
||||||
|
public static boolean filterPacks;
|
||||||
|
public static boolean logProcessing;
|
||||||
|
|
||||||
|
private static final String ERR_DUPLICATE = "Unexpected duplicate \"%s\" in Resclone config";
|
||||||
private static final String PACKS = "packs";
|
private static final String PACKS = "packs";
|
||||||
private static final String PRUNE_UNUSED = "pruneUnused";
|
private static final String PRUNE_UNUSED = "pruneUnused";
|
||||||
private static final Type META_SET = new TypeToken<Set<PackMetaUnloaded>>(){}.getType();
|
private static final String FILTER_PACKS = "filterPacks";
|
||||||
|
private static final String LOG_PROCESSING = "logProcessing";
|
||||||
|
|
||||||
private static void load(Path path) throws IOException {
|
private static void load(Path path) throws IOException {
|
||||||
if (!Files.exists(path)) {
|
if (!Files.exists(path)) {
|
||||||
packs = new HashSet<>();
|
packs = new HashSet<>();
|
||||||
pruneUnused = true;
|
pruneUnused = true;
|
||||||
|
filterPacks = true;
|
||||||
|
logProcessing = false;
|
||||||
write(path);
|
write(path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean updateRequired = false;
|
boolean updateRequired = false;
|
||||||
try (BufferedReader br = Files.newBufferedReader(path);
|
try (BufferedReader br = Files.newBufferedReader(path);
|
||||||
JsonReader reader = GsonHolders.CONFIG.getGson().newJsonReader(br)) {
|
JsonReader reader = LibJf.LENIENT_TRANSPORT.createReader(br)) {
|
||||||
if (reader.peek() == JsonToken.BEGIN_ARRAY) {
|
if (reader.peek() == Token.BEGIN_ARRAY) {
|
||||||
// Legacy format compatibility
|
// Legacy format compatibility
|
||||||
packs = GsonHolders.CONFIG.getGson().fromJson(reader, META_SET);
|
packs = ListAdaptation.deserializeSet(reader, GC_PackMetaUnloaded::deserialize);
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
} else if (reader.peek() == JsonToken.BEGIN_OBJECT) {
|
} else if (reader.peek() == Token.BEGIN_OBJECT) {
|
||||||
// New format
|
// New format
|
||||||
reader.beginObject();
|
reader.beginObject();
|
||||||
Set<PackMetaUnloaded> packs = null;
|
Set<PackMetaUnloaded> packs = null;
|
||||||
Boolean pruneUnused = null;
|
Boolean pruneUnused = null;
|
||||||
while (reader.peek() != JsonToken.END_OBJECT) {
|
Boolean filterPacks = null;
|
||||||
|
Boolean logProcessing = null;
|
||||||
|
while (reader.peek() != Token.END_OBJECT) {
|
||||||
final String name = reader.nextName();
|
final String name = reader.nextName();
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case PACKS -> {
|
case PACKS -> {
|
||||||
if (packs != null) throw new JsonParseException("Unexpected duplicate \"" + PACKS + "\" in Resclone config");
|
if (packs != null) throw new MalformedDataException(ERR_DUPLICATE.formatted(PACKS));
|
||||||
packs = GsonHolders.CONFIG.getGson().fromJson(reader, META_SET);
|
if (reader.peek() == Token.BEGIN_ARRAY) {
|
||||||
|
packs = ListAdaptation.deserializeSet(reader, GC_PackMetaUnloaded::deserialize);
|
||||||
|
} else {
|
||||||
|
packs = Set.of(GC_PackMetaUnloaded.deserialize(reader));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case PRUNE_UNUSED -> {
|
case PRUNE_UNUSED -> {
|
||||||
if (pruneUnused != null) throw new JsonParseException("Unexpected duplicate \"" + PRUNE_UNUSED + "\" in Resclone config");
|
if (pruneUnused != null) throw new MalformedDataException(ERR_DUPLICATE.formatted(PRUNE_UNUSED));
|
||||||
pruneUnused = reader.nextBoolean();
|
pruneUnused = reader.nextBoolean();
|
||||||
}
|
}
|
||||||
default -> throw new JsonParseException("Unexpected element: \"" + name + "\" in Resclone config");
|
case FILTER_PACKS -> {
|
||||||
|
if (filterPacks != null) throw new MalformedDataException(ERR_DUPLICATE.formatted(FILTER_PACKS));
|
||||||
|
filterPacks = reader.nextBoolean();
|
||||||
|
}
|
||||||
|
case LOG_PROCESSING -> {
|
||||||
|
if (logProcessing != null) throw new MalformedDataException(ERR_DUPLICATE.formatted(LOG_PROCESSING));
|
||||||
|
logProcessing = reader.nextBoolean();
|
||||||
|
}
|
||||||
|
default -> throw new MalformedDataException("Unexpected element: \"" + name + "\" in Resclone config");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
reader.endObject();
|
reader.endObject();
|
||||||
if (packs == null) throw new JsonParseException("Expected Resclone config object to contain packs");
|
if (packs == null) throw new MalformedDataException("Expected Resclone config object to contain packs");
|
||||||
if (pruneUnused == null) {
|
if (pruneUnused == null) {
|
||||||
pruneUnused = true;
|
pruneUnused = true;
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
}
|
}
|
||||||
|
if (filterPacks == null) {
|
||||||
|
filterPacks = true;
|
||||||
|
updateRequired = true;
|
||||||
|
}
|
||||||
|
if (logProcessing == null) {
|
||||||
|
logProcessing = false;
|
||||||
|
updateRequired = true;
|
||||||
|
}
|
||||||
RescloneConfig.packs = packs;
|
RescloneConfig.packs = packs;
|
||||||
RescloneConfig.pruneUnused = pruneUnused;
|
RescloneConfig.pruneUnused = pruneUnused;
|
||||||
} else throw new JsonParseException("Expected Resclone config to be an object or array");
|
RescloneConfig.filterPacks = filterPacks;
|
||||||
|
RescloneConfig.logProcessing = logProcessing;
|
||||||
|
} else throw new MalformedDataException("Expected Resclone config to be an object or array");
|
||||||
}
|
}
|
||||||
if (updateRequired) write(path);
|
if (updateRequired) write(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void write(Path path) throws IOException {
|
private static void write(Path path) throws IOException {
|
||||||
try (BufferedWriter bw = Files.newBufferedWriter(path);
|
try (BufferedWriter bw = Files.newBufferedWriter(path);
|
||||||
JsonWriter writer = GsonHolders.CONFIG.getGson().newJsonWriter(bw)) {
|
JsonWriter writer = LibJf.LENIENT_TRANSPORT.createWriter(bw)) {
|
||||||
writer.beginObject()
|
writer.beginObject()
|
||||||
.comment("The packs to be loaded by resclone")
|
.comment("The packs to be loaded by resclone")
|
||||||
.name(PACKS);
|
.name(PACKS)
|
||||||
GsonHolders.CONFIG.getGson().toJson(packs, META_SET, writer);
|
.beginArray();
|
||||||
writer.comment("Whether to prune unused packs from the cache")
|
for (PackMetaUnloaded pack : packs) {
|
||||||
|
GC_PackMetaUnloaded.serialize(pack, writer);
|
||||||
|
}
|
||||||
|
writer.endArray()
|
||||||
|
.comment("Automatically remove all downloaded packs that are not in the config to free up unneeded space")
|
||||||
.name(PRUNE_UNUSED)
|
.name(PRUNE_UNUSED)
|
||||||
.value(pruneUnused)
|
.value(pruneUnused)
|
||||||
|
.comment("Whether to filter packs to remove files unchanged from vanilla and empty directories")
|
||||||
|
.name(FILTER_PACKS)
|
||||||
|
.value(filterPacks)
|
||||||
|
.comment("Log automatic processing steps applied to downloaded packs")
|
||||||
|
.name(LOG_PROCESSING)
|
||||||
|
.value(logProcessing)
|
||||||
.endObject();
|
.endObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,8 +143,10 @@ public class RescloneConfig implements JfCustomConfig {
|
|||||||
Resclone.LOGGER.error("Could not write config", e);
|
Resclone.LOGGER.error("Could not write config", e);
|
||||||
}
|
}
|
||||||
}).setPath(path)
|
}).setPath(path)
|
||||||
.<Set<PackMetaUnloaded>>value(PACKS, new HashSet<>(), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, io.gitlab.jfronny.libjf.config.api.v1.type.Type.ofClass(META_SET), 100, () -> packs, p -> packs = p)
|
.<Set<PackMetaUnloaded>>value(PACKS, new HashSet<>(), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, io.gitlab.jfronny.libjf.config.api.v2.type.Type.ofClass(new TypeToken<Set<PackMetaUnloaded>>(){}.getType()), 100, () -> packs, p -> packs = p)
|
||||||
.value(PRUNE_UNUSED, pruneUnused, () -> pruneUnused, p -> pruneUnused = p)
|
.value(PRUNE_UNUSED, pruneUnused, () -> pruneUnused, p -> pruneUnused = p)
|
||||||
|
.value(FILTER_PACKS, filterPacks, () -> filterPacks, p -> filterPacks = p)
|
||||||
|
.value(LOG_PROCESSING, logProcessing, () -> logProcessing, p -> logProcessing = p)
|
||||||
).load();
|
).load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,26 +3,57 @@ package io.gitlab.jfronny.resclone;
|
|||||||
import net.fabricmc.fabric.api.resource.ModResourcePack;
|
import net.fabricmc.fabric.api.resource.ModResourcePack;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.api.metadata.ModMetadata;
|
import net.fabricmc.loader.api.metadata.ModMetadata;
|
||||||
import net.minecraft.resource.ZipResourcePack;
|
import net.minecraft.resource.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class RescloneResourcePack extends ZipResourcePack implements ModResourcePack {
|
public class RescloneResourcePack extends ZipResourcePack implements ModResourcePack {
|
||||||
private static final ModMetadata METADATA = FabricLoader.getInstance().getModContainer(Resclone.MOD_ID).orElseThrow().getMetadata();
|
private static final ModMetadata METADATA = FabricLoader.getInstance().getModContainer(Resclone.MOD_ID).orElseThrow().getMetadata();
|
||||||
private final String name;
|
private final ResourcePackInfo info;
|
||||||
|
private final ZipFileWrapper file;
|
||||||
|
|
||||||
public RescloneResourcePack(File file, String name) {
|
RescloneResourcePack(ZipFileWrapper file, ResourcePackInfo info, String overlay) {
|
||||||
super(name, file, true);
|
super(info, file, overlay);
|
||||||
this.name = name;
|
this.info = info;
|
||||||
}
|
this.file = file;
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModMetadata getFabricModMetadata() {
|
public ModMetadata getFabricModMetadata() {
|
||||||
return METADATA;
|
return METADATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModResourcePack createOverlay(String overlay) {
|
||||||
|
return new RescloneResourcePack(this.file, this.info, overlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Factory implements ResourcePackProfile.PackFactory {
|
||||||
|
private final File file;
|
||||||
|
private final ResourcePackInfo info;
|
||||||
|
|
||||||
|
public Factory(File file, ResourcePackInfo info) {
|
||||||
|
this.file = file;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourcePack open(ResourcePackInfo info) {
|
||||||
|
ZipFileWrapper zipFileWrapper = new ZipFileWrapper(this.file);
|
||||||
|
return new RescloneResourcePack(zipFileWrapper, this.info, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ResourcePack openWithOverlays(ResourcePackInfo info, ResourcePackProfile.Metadata metadata) {
|
||||||
|
ZipFileWrapper zipFileWrapper = new ZipFileWrapper(this.file);
|
||||||
|
ZipResourcePack resourcePack = new RescloneResourcePack(zipFileWrapper, this.info, "");
|
||||||
|
List<String> overlays = metadata.overlays();
|
||||||
|
if (overlays.isEmpty()) return resourcePack;
|
||||||
|
List<ResourcePack> overlayPacks = new ArrayList<>(overlays.size());
|
||||||
|
for (String string : overlays) overlayPacks.add(new RescloneResourcePack(zipFileWrapper, this.info, string));
|
||||||
|
return new OverlayResourcePack(resourcePack, overlayPacks);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,7 @@
|
|||||||
package io.gitlab.jfronny.resclone.data;
|
package io.gitlab.jfronny.resclone.data;
|
||||||
|
|
||||||
// Represents a pack as present in the config
|
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
|
||||||
// Can't be a record since it'll need to be parsed by Gson
|
|
||||||
@SuppressWarnings("ClassCanBeRecord")
|
|
||||||
public class PackMetaUnloaded {
|
|
||||||
public final String fetcher;
|
|
||||||
public final String source;
|
|
||||||
public final String name;
|
|
||||||
public final boolean forceDownload;
|
|
||||||
public final boolean forceEnable;
|
|
||||||
|
|
||||||
public PackMetaUnloaded(String fetcher, String source, String name, boolean forceDownload, boolean forceEnable) {
|
@GSerializable
|
||||||
this.fetcher = fetcher;
|
public record PackMetaUnloaded(String fetcher, String source, String name, boolean forceDownload, boolean forceEnable) {
|
||||||
this.source = source;
|
|
||||||
this.name = name;
|
|
||||||
this.forceDownload = forceDownload;
|
|
||||||
this.forceEnable = forceEnable;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package io.gitlab.jfronny.resclone.data.curseforge;
|
package io.gitlab.jfronny.resclone.data.curseforge;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public class GetModFilesResponse {
|
public class GetModFilesResponse {
|
||||||
public List<Data> data;
|
public List<Data> data;
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public static class Data {
|
public static class Data {
|
||||||
public String downloadUrl;
|
public String downloadUrl;
|
||||||
public Date fileDate;
|
public Date fileDate;
|
||||||
|
@ -1,8 +1,12 @@
|
|||||||
package io.gitlab.jfronny.resclone.data.curseforge;
|
package io.gitlab.jfronny.resclone.data.curseforge;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public class GetModResponse {
|
public class GetModResponse {
|
||||||
public Data data;
|
public Data data;
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public static class Data {
|
public static class Data {
|
||||||
public Boolean allowModDistribution;
|
public Boolean allowModDistribution;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,15 @@
|
|||||||
package io.gitlab.jfronny.resclone.data.github;
|
package io.gitlab.jfronny.resclone.data.github;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public class Release {
|
public class Release {
|
||||||
public List<Asset> assets;
|
public List<Asset> assets;
|
||||||
public String zipball_url;
|
public String zipball_url;
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public static class Asset {
|
public static class Asset {
|
||||||
public String name;
|
public String name;
|
||||||
public String content_type;
|
public String content_type;
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package io.gitlab.jfronny.resclone.data.github;
|
package io.gitlab.jfronny.resclone.data.github;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public class Repository {
|
public class Repository {
|
||||||
public String default_branch;
|
public String default_branch;
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package io.gitlab.jfronny.resclone.data.modrinth;
|
package io.gitlab.jfronny.resclone.data.modrinth;
|
||||||
|
|
||||||
import io.gitlab.jfronny.gson.annotations.SerializedName;
|
import io.gitlab.jfronny.commons.serialize.annotations.SerializedName;
|
||||||
|
import io.gitlab.jfronny.commons.serialize.generator.annotations.GSerializable;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public class Version {
|
public class Version {
|
||||||
public String name;
|
public String name;
|
||||||
public String version_number;
|
public String version_number;
|
||||||
@ -24,6 +26,7 @@ public class Version {
|
|||||||
public Integer downloads;
|
public Integer downloads;
|
||||||
public List<File> files;
|
public List<File> files;
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public static class Dependency {
|
public static class Dependency {
|
||||||
@Nullable public String version_id;
|
@Nullable public String version_id;
|
||||||
@Nullable public String project_id;
|
@Nullable public String project_id;
|
||||||
@ -43,6 +46,7 @@ public class Version {
|
|||||||
listed, archived, draft, unlisted, scheduled, unknown
|
listed, archived, draft, unlisted, scheduled, unknown
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public static class File {
|
public static class File {
|
||||||
public Hashes hashes;
|
public Hashes hashes;
|
||||||
public String url;
|
public String url;
|
||||||
@ -51,6 +55,7 @@ public class Version {
|
|||||||
public Integer size;
|
public Integer size;
|
||||||
@Nullable public Type file_type;
|
@Nullable public Type file_type;
|
||||||
|
|
||||||
|
@GSerializable
|
||||||
public static class Hashes {
|
public static class Hashes {
|
||||||
public String sha512;
|
public String sha512;
|
||||||
public String sha1;
|
public String sha1;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package io.gitlab.jfronny.resclone.fetchers;
|
package io.gitlab.jfronny.resclone.fetchers;
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.HttpUtils;
|
import io.gitlab.jfronny.commons.http.client.HttpClient;
|
||||||
import io.gitlab.jfronny.resclone.Resclone;
|
import io.gitlab.jfronny.resclone.Resclone;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -32,7 +32,7 @@ public abstract class BasePackFetcher implements PackFetcher {
|
|||||||
|
|
||||||
Resclone.LOGGER.info("Downloading pack: " + url);
|
Resclone.LOGGER.info("Downloading pack: " + url);
|
||||||
|
|
||||||
try (InputStream is = HttpUtils.get(url).userAgent(Resclone.USER_AGENT).sendInputStream();
|
try (InputStream is = HttpClient.get(url).userAgent(Resclone.USER_AGENT).sendInputStream();
|
||||||
OutputStream os = Files.newOutputStream(p)) {
|
OutputStream os = Files.newOutputStream(p)) {
|
||||||
byte[] dataBuffer = new byte[1024];
|
byte[] dataBuffer = new byte[1024];
|
||||||
int bytesRead;
|
int bytesRead;
|
||||||
|
@ -1,13 +1,19 @@
|
|||||||
package io.gitlab.jfronny.resclone.fetchers;
|
package io.gitlab.jfronny.resclone.fetchers;
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.HttpUtils;
|
import io.gitlab.jfronny.commons.http.client.HttpClient;
|
||||||
|
import io.gitlab.jfronny.commons.serialize.json.JsonReader;
|
||||||
|
import io.gitlab.jfronny.commons.throwable.ThrowingFunction;
|
||||||
|
import io.gitlab.jfronny.libjf.LibJf;
|
||||||
import io.gitlab.jfronny.resclone.Resclone;
|
import io.gitlab.jfronny.resclone.Resclone;
|
||||||
|
import io.gitlab.jfronny.resclone.data.curseforge.GC_GetModFilesResponse;
|
||||||
|
import io.gitlab.jfronny.resclone.data.curseforge.GC_GetModResponse;
|
||||||
import io.gitlab.jfronny.resclone.data.curseforge.GetModFilesResponse;
|
import io.gitlab.jfronny.resclone.data.curseforge.GetModFilesResponse;
|
||||||
import io.gitlab.jfronny.resclone.data.curseforge.GetModResponse;
|
import io.gitlab.jfronny.resclone.data.curseforge.GetModResponse;
|
||||||
import net.minecraft.MinecraftVersion;
|
import net.minecraft.MinecraftVersion;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -33,7 +39,7 @@ public class CurseforgeFetcher extends BasePackFetcher {
|
|||||||
@Override
|
@Override
|
||||||
public String getDownloadUrl(String baseUrl) throws Exception {
|
public String getDownloadUrl(String baseUrl) throws Exception {
|
||||||
try {
|
try {
|
||||||
GetModResponse response = GET(baseUrl, GetModResponse.class);
|
GetModResponse response = GET(baseUrl, GC_GetModResponse::deserialize);
|
||||||
if (!response.data.allowModDistribution)
|
if (!response.data.allowModDistribution)
|
||||||
throw new Exception("The author of " + baseUrl + " disabled access to this pack outside of the curseforge launcher");
|
throw new Exception("The author of " + baseUrl + " disabled access to this pack outside of the curseforge launcher");
|
||||||
|
|
||||||
@ -43,7 +49,7 @@ public class CurseforgeFetcher extends BasePackFetcher {
|
|||||||
Date latestDate = null;
|
Date latestDate = null;
|
||||||
boolean foundMatchingVersion = false;
|
boolean foundMatchingVersion = false;
|
||||||
|
|
||||||
for (GetModFilesResponse.Data addon : GET(baseUrl + "/files", GetModFilesResponse.class).data) {
|
for (GetModFilesResponse.Data addon : GET(baseUrl + "/files", GC_GetModFilesResponse::deserialize).data) {
|
||||||
if (foundMatchingVersion && !addon.gameVersions.contains(version)) continue;
|
if (foundMatchingVersion && !addon.gameVersions.contains(version)) continue;
|
||||||
if (!foundMatchingVersion && addon.gameVersions.contains(version)) {
|
if (!foundMatchingVersion && addon.gameVersions.contains(version)) {
|
||||||
foundMatchingVersion = true;
|
foundMatchingVersion = true;
|
||||||
@ -63,8 +69,11 @@ public class CurseforgeFetcher extends BasePackFetcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> T GET(String suffix, Class<T> klazz) throws URISyntaxException, IOException {
|
private static <T> T GET(String suffix, ThrowingFunction<JsonReader, T, IOException> klazz) throws URISyntaxException, IOException {
|
||||||
return HttpUtils.get("https://api.curseforge.com/v1/mods/" + suffix).header("x-api-key", API_KEY).sendSerialized(klazz);
|
try (Reader r = HttpClient.get("https://api.curseforge.com/v1/mods/" + suffix).header("x-api-key", API_KEY).sendReader();
|
||||||
|
JsonReader jr = LibJf.LENIENT_TRANSPORT.createReader(r)) {
|
||||||
|
return klazz.apply(jr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static byte[] unsalt(byte[] data, int salt) {
|
private static byte[] unsalt(byte[] data, int salt) {
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
package io.gitlab.jfronny.resclone.fetchers;
|
package io.gitlab.jfronny.resclone.fetchers;
|
||||||
|
|
||||||
import io.gitlab.jfronny.commons.HttpUtils;
|
import io.gitlab.jfronny.commons.http.client.HttpClient;
|
||||||
|
import io.gitlab.jfronny.commons.serialize.json.JsonReader;
|
||||||
|
import io.gitlab.jfronny.libjf.LibJf;
|
||||||
import io.gitlab.jfronny.resclone.Resclone;
|
import io.gitlab.jfronny.resclone.Resclone;
|
||||||
|
import io.gitlab.jfronny.resclone.data.github.GC_Release;
|
||||||
|
import io.gitlab.jfronny.resclone.data.github.GC_Repository;
|
||||||
import io.gitlab.jfronny.resclone.data.github.Release;
|
import io.gitlab.jfronny.resclone.data.github.Release;
|
||||||
import io.gitlab.jfronny.resclone.data.github.Repository;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
public class GitHubFetcher extends BasePackFetcher {
|
public class GitHubFetcher extends BasePackFetcher {
|
||||||
@ -39,8 +43,9 @@ public class GitHubFetcher extends BasePackFetcher {
|
|||||||
|
|
||||||
//"user/repo/release" - Gets from the latest release.
|
//"user/repo/release" - Gets from the latest release.
|
||||||
else if (parts[2].equalsIgnoreCase("release")) {
|
else if (parts[2].equalsIgnoreCase("release")) {
|
||||||
try {
|
try (Reader r = HttpClient.get("https://api.github.com/repos/" + parts[0] + "/" + parts[1] + "/releases/latest").sendReader();
|
||||||
Release latestRelease = HttpUtils.get("https://api.github.com/repos/" + parts[0] + "/" + parts[1] + "/releases/latest").sendSerialized(Release.class);
|
JsonReader jr = LibJf.LENIENT_TRANSPORT.createReader(r)) {
|
||||||
|
Release latestRelease = GC_Release.deserialize(jr);
|
||||||
String res = null;
|
String res = null;
|
||||||
|
|
||||||
for (Release.Asset asset : latestRelease.assets) {
|
for (Release.Asset asset : latestRelease.assets) {
|
||||||
@ -73,8 +78,9 @@ public class GitHubFetcher extends BasePackFetcher {
|
|||||||
|
|
||||||
private String getFromBranch(String repo, @Nullable String branch) {
|
private String getFromBranch(String repo, @Nullable String branch) {
|
||||||
if (branch == null) {
|
if (branch == null) {
|
||||||
try {
|
try (Reader r = HttpClient.get("https://api.github.com/repos/" + repo).sendReader();
|
||||||
branch = HttpUtils.get("https://api.github.com/repos/" + repo).<Repository>sendSerialized(Repository.class).default_branch;
|
JsonReader jr = LibJf.LENIENT_TRANSPORT.createReader(r)) {
|
||||||
|
branch = GC_Repository.deserialize(jr).default_branch;
|
||||||
} catch (IOException | URISyntaxException e) {
|
} catch (IOException | URISyntaxException e) {
|
||||||
Resclone.LOGGER.error("Failed to fetch branch for " + repo + ". Choosing \"main\"", e);
|
Resclone.LOGGER.error("Failed to fetch branch for " + repo + ". Choosing \"main\"", e);
|
||||||
branch = "main";
|
branch = "main";
|
||||||
|
@ -1,19 +1,21 @@
|
|||||||
package io.gitlab.jfronny.resclone.fetchers;
|
package io.gitlab.jfronny.resclone.fetchers;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import io.gitlab.jfronny.commons.http.client.HttpClient;
|
||||||
import io.gitlab.jfronny.commons.HttpUtils;
|
import io.gitlab.jfronny.commons.serialize.json.JsonReader;
|
||||||
|
import io.gitlab.jfronny.libjf.LibJf;
|
||||||
import io.gitlab.jfronny.resclone.Resclone;
|
import io.gitlab.jfronny.resclone.Resclone;
|
||||||
|
import io.gitlab.jfronny.resclone.data.modrinth.GC_Version;
|
||||||
import io.gitlab.jfronny.resclone.data.modrinth.Version;
|
import io.gitlab.jfronny.resclone.data.modrinth.Version;
|
||||||
|
import io.gitlab.jfronny.resclone.util.ListAdaptation;
|
||||||
import net.minecraft.MinecraftVersion;
|
import net.minecraft.MinecraftVersion;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Type;
|
import java.io.Reader;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ModrinthFetcher extends BasePackFetcher {
|
public class ModrinthFetcher extends BasePackFetcher {
|
||||||
private static final Type versionType = new TypeToken<List<Version>>() {}.getType();
|
|
||||||
@Override
|
@Override
|
||||||
public String getSourceTypeName() {
|
public String getSourceTypeName() {
|
||||||
return "modrinth";
|
return "modrinth";
|
||||||
@ -28,9 +30,14 @@ public class ModrinthFetcher extends BasePackFetcher {
|
|||||||
Date latestDate = null;
|
Date latestDate = null;
|
||||||
boolean foundMatchingVersion = false;
|
boolean foundMatchingVersion = false;
|
||||||
|
|
||||||
for (Version ver : HttpUtils.get("https://api.modrinth.com/v2/project/" + baseUrl + "/version")
|
List<Version> versions;
|
||||||
|
try (Reader r = HttpClient.get("https://api.modrinth.com/v2/project/" + baseUrl + "/version")
|
||||||
.userAgent(Resclone.USER_AGENT)
|
.userAgent(Resclone.USER_AGENT)
|
||||||
.<List<Version>>sendSerialized(versionType)) {
|
.sendReader();
|
||||||
|
JsonReader jr = LibJf.LENIENT_TRANSPORT.createReader(r)) {
|
||||||
|
versions = ListAdaptation.deserializeList(jr, GC_Version::deserialize);
|
||||||
|
}
|
||||||
|
for (Version ver : versions) {
|
||||||
if (foundMatchingVersion && !ver.game_versions.contains(version)) continue;
|
if (foundMatchingVersion && !ver.game_versions.contains(version)) continue;
|
||||||
if (ver.files.isEmpty()) continue;
|
if (ver.files.isEmpty()) continue;
|
||||||
if (!foundMatchingVersion && ver.game_versions.contains(version)) {
|
if (!foundMatchingVersion && ver.game_versions.contains(version)) {
|
||||||
@ -54,7 +61,7 @@ public class ModrinthFetcher extends BasePackFetcher {
|
|||||||
if (file.file_type == Version.File.Type.REQUIRED_RESOURCE_PACK) return file.url;
|
if (file.file_type == Version.File.Type.REQUIRED_RESOURCE_PACK) return file.url;
|
||||||
}
|
}
|
||||||
Resclone.LOGGER.error("Identification failed, using first file of " + baseUrl);
|
Resclone.LOGGER.error("Identification failed, using first file of " + baseUrl);
|
||||||
return latest.files.get(0).url;
|
return latest.files.getFirst().url;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new IOException("Could not get Modrinth download for " + baseUrl, e);
|
throw new IOException("Could not get Modrinth download for " + baseUrl, e);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
@Mixin(FileResourcePackProvider.class)
|
@Mixin(FileResourcePackProvider.class)
|
||||||
@ -20,14 +21,21 @@ public class FileResourcePackProviderMixin {
|
|||||||
@Inject(at = @At("TAIL"), method = "register(Ljava/util/function/Consumer;)V")
|
@Inject(at = @At("TAIL"), method = "register(Ljava/util/function/Consumer;)V")
|
||||||
public void registerExtra(Consumer<ResourcePackProfile> consumer, CallbackInfo info) {
|
public void registerExtra(Consumer<ResourcePackProfile> consumer, CallbackInfo info) {
|
||||||
for (PackMetaLoaded meta : Resclone.DOWNLOADED_PACKS) {
|
for (PackMetaLoaded meta : Resclone.DOWNLOADED_PACKS) {
|
||||||
ResourcePackProfile resourcePackProfile = ResourcePackProfile.create(
|
ResourcePackInfo ifo = new ResourcePackInfo(
|
||||||
"resclone/" + meta.name(),
|
"resclone/" + meta.name(),
|
||||||
Text.literal(meta.name()),
|
Text.literal(meta.name()),
|
||||||
meta.forceEnable(),
|
source,
|
||||||
name -> new RescloneResourcePack(meta.zipPath().toFile(), meta.name()),
|
Optional.empty()
|
||||||
|
);
|
||||||
|
ResourcePackProfile resourcePackProfile = ResourcePackProfile.create(
|
||||||
|
ifo,
|
||||||
|
new RescloneResourcePack.Factory(meta.zipPath().toFile(), ifo),
|
||||||
type,
|
type,
|
||||||
|
new ResourcePackPosition(
|
||||||
|
meta.forceEnable(),
|
||||||
ResourcePackProfile.InsertionPosition.TOP,
|
ResourcePackProfile.InsertionPosition.TOP,
|
||||||
source
|
false
|
||||||
|
)
|
||||||
);
|
);
|
||||||
if (resourcePackProfile != null) {
|
if (resourcePackProfile != null) {
|
||||||
consumer.accept(resourcePackProfile);
|
consumer.accept(resourcePackProfile);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.gitlab.jfronny.resclone.processors;
|
package io.gitlab.jfronny.resclone.processors;
|
||||||
|
|
||||||
import io.gitlab.jfronny.resclone.Resclone;
|
import io.gitlab.jfronny.resclone.Resclone;
|
||||||
|
import io.gitlab.jfronny.resclone.RescloneConfig;
|
||||||
import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor;
|
import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
@ -22,7 +23,10 @@ public class PruneVanillaProcessor implements PackProcessor {
|
|||||||
InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString());
|
InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString());
|
||||||
if (vn != null) {
|
if (vn != null) {
|
||||||
try (InputStream pk = Files.newInputStream(s, StandardOpenOption.READ)) {
|
try (InputStream pk = Files.newInputStream(s, StandardOpenOption.READ)) {
|
||||||
return IOUtils.contentEquals(vn, pk);
|
if (IOUtils.contentEquals(vn, pk)) {
|
||||||
|
if (RescloneConfig.logProcessing) Resclone.LOGGER.info("Pruning file unchanged from vanilla: {}", s);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package io.gitlab.jfronny.resclone.processors;
|
package io.gitlab.jfronny.resclone.processors;
|
||||||
|
|
||||||
import io.gitlab.jfronny.resclone.Resclone;
|
import io.gitlab.jfronny.resclone.Resclone;
|
||||||
|
import io.gitlab.jfronny.resclone.RescloneConfig;
|
||||||
import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor;
|
import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -14,7 +15,10 @@ public class RemoveEmptyProcessor implements PackProcessor {
|
|||||||
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
|
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
|
||||||
if (Files.isDirectory(s)) {
|
if (Files.isDirectory(s)) {
|
||||||
try (DirectoryStream<Path> paths = Files.newDirectoryStream(s)) {
|
try (DirectoryStream<Path> paths = Files.newDirectoryStream(s)) {
|
||||||
return !paths.iterator().hasNext();
|
if (!paths.iterator().hasNext()) {
|
||||||
|
if (RescloneConfig.logProcessing) Resclone.LOGGER.info("Pruning empty directory: {}", s);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Resclone.LOGGER.error("Could not check whether directory has entries", e);
|
Resclone.LOGGER.error("Could not check whether directory has entries", e);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package io.gitlab.jfronny.resclone.processors;
|
package io.gitlab.jfronny.resclone.processors;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.resclone.Resclone;
|
||||||
|
import io.gitlab.jfronny.resclone.RescloneConfig;
|
||||||
import io.gitlab.jfronny.resclone.util.io.MoveDirVisitor;
|
import io.gitlab.jfronny.resclone.util.io.MoveDirVisitor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -14,6 +16,7 @@ public class RootPathProcessor implements PackProcessor {
|
|||||||
try (DirectoryStream<Path> paths = Files.newDirectoryStream(root)) {
|
try (DirectoryStream<Path> paths = Files.newDirectoryStream(root)) {
|
||||||
for (Path path : paths) {
|
for (Path path : paths) {
|
||||||
if (Files.isDirectory(path) && Files.exists(path.resolve("pack.mcmeta"))) {
|
if (Files.isDirectory(path) && Files.exists(path.resolve("pack.mcmeta"))) {
|
||||||
|
if (RescloneConfig.logProcessing) Resclone.LOGGER.info("Moving discovered root out of: {}", path);
|
||||||
Files.walkFileTree(path, new MoveDirVisitor(path, root, StandardCopyOption.REPLACE_EXISTING));
|
Files.walkFileTree(path, new MoveDirVisitor(path, root, StandardCopyOption.REPLACE_EXISTING));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
package io.gitlab.jfronny.resclone.util;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.commons.serialize.SerializeReader;
|
||||||
|
import io.gitlab.jfronny.commons.throwable.ThrowingFunction;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class ListAdaptation {
|
||||||
|
public static <T, TEx extends Exception, Reader extends SerializeReader<TEx, Reader>> List<T> deserializeList(Reader reader, ThrowingFunction<Reader, T, TEx> deserializeOne) throws TEx {
|
||||||
|
List<T> result = new ArrayList<>();
|
||||||
|
reader.beginArray();
|
||||||
|
while (reader.hasNext()) {
|
||||||
|
result.add(deserializeOne.apply(reader));
|
||||||
|
}
|
||||||
|
reader.endArray();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, TEx extends Exception, Reader extends SerializeReader<TEx, Reader>> Set<T> deserializeSet(Reader reader, ThrowingFunction<Reader, T, TEx> serializeOne) throws TEx {
|
||||||
|
Set<T> result = new LinkedHashSet<>();
|
||||||
|
reader.beginArray();
|
||||||
|
while (reader.hasNext()) {
|
||||||
|
result.add(serializeOne.apply(reader));
|
||||||
|
}
|
||||||
|
reader.endArray();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
@ -3,5 +3,9 @@
|
|||||||
"resclone.jfconfig.packs": "Packs",
|
"resclone.jfconfig.packs": "Packs",
|
||||||
"resclone.jfconfig.packs.tooltip": "The packs to download and add",
|
"resclone.jfconfig.packs.tooltip": "The packs to download and add",
|
||||||
"resclone.jfconfig.pruneUnused": "Prune Unused",
|
"resclone.jfconfig.pruneUnused": "Prune Unused",
|
||||||
"resclone.jfconfig.pruneUnused.tooltip": "Automatically remove all downloaded packs that are not in the config to free up unneeded space"
|
"resclone.jfconfig.pruneUnused.tooltip": "Automatically remove all downloaded packs that are not in the config to free up unneeded space",
|
||||||
|
"resclone.jfconfig.filterPacks": "Filter Packs",
|
||||||
|
"resclone.jfconfig.filterPacks.tooltip": "Whether to filter packs to remove files unchanged from vanilla and empty directories",
|
||||||
|
"resclone.jfconfig.logProcessing": "Log Processing",
|
||||||
|
"resclone.jfconfig.logProcessing.tooltip": "Log automatic processing steps applied to downloaded packs"
|
||||||
}
|
}
|
@ -27,6 +27,7 @@
|
|||||||
"environment": "client"
|
"environment": "client"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"accessWidener": "resclone.accesswidener",
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=0.12.0",
|
"fabricloader": ">=0.12.0",
|
||||||
"minecraft": "*",
|
"minecraft": "*",
|
||||||
|
5
src/main/resources/resclone.accesswidener
Normal file
5
src/main/resources/resclone.accesswidener
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
accessWidener v2 named
|
||||||
|
|
||||||
|
accessible class net/minecraft/resource/ZipResourcePack$ZipFileWrapper
|
||||||
|
accessible method net/minecraft/resource/ZipResourcePack <init> (Lnet/minecraft/resource/ResourcePackInfo;Lnet/minecraft/resource/ZipResourcePack$ZipFileWrapper;Ljava/lang/String;)V
|
||||||
|
accessible method net/minecraft/resource/ZipResourcePack$ZipFileWrapper <init> (Ljava/io/File;)V
|
@ -2,7 +2,6 @@
|
|||||||
"required": true,
|
"required": true,
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "io.gitlab.jfronny.resclone.mixin",
|
"package": "io.gitlab.jfronny.resclone.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"FileResourcePackProviderMixin"
|
"FileResourcePackProviderMixin"
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user