Allow force-disabling and enable packs by default
This commit is contained in:
parent
e9c5038010
commit
b4c3b791c5
|
@ -6,7 +6,7 @@ minecraft_version=1.16.5
|
|||
yarn_mappings=1.16.5+build.8
|
||||
loader_version=0.11.3
|
||||
# Mod Properties
|
||||
mod_version=1.6.0
|
||||
mod_version=1.7.0
|
||||
maven_group=io.gitlab.jfronny
|
||||
archives_base_name=resclone
|
||||
# Dependencies
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package io.gitlab.jfronny.resclone;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import io.gitlab.jfronny.resclone.api.PackFetcher;
|
||||
import io.gitlab.jfronny.resclone.api.RescloneApi;
|
||||
import io.gitlab.jfronny.resclone.api.RescloneEntry;
|
||||
import io.gitlab.jfronny.resclone.data.PackMetaLoaded;
|
||||
import io.gitlab.jfronny.resclone.data.PackMetaUnloaded;
|
||||
import io.gitlab.jfronny.resclone.fetchers.PackFetcher;
|
||||
import io.gitlab.jfronny.resclone.processors.PackProcessor;
|
||||
import io.gitlab.jfronny.resclone.api.PackProcessor;
|
||||
import io.gitlab.jfronny.resclone.processors.RemoveEmptyProcessor;
|
||||
import io.gitlab.jfronny.resclone.processors.RootPathProcessor;
|
||||
import io.gitlab.jfronny.resclone.util.PackUrlCache;
|
||||
|
@ -28,11 +28,11 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Resclone implements ModInitializer, RescloneApi {
|
||||
|
||||
public static final Set<PackMetaUnloaded> conf = new LinkedHashSet<>();
|
||||
public static final Map<String, PackFetcher> fetcherInstances = new LinkedHashMap<>();
|
||||
public static final Set<PackProcessor> processors = new LinkedHashSet<>();
|
||||
public static final Set<PackMetaLoaded> downloadedPacks = new LinkedHashSet<>();
|
||||
public static final Set<PackMetaLoaded> newPacks = new LinkedHashSet<>();
|
||||
public static final Gson gson = new Gson();
|
||||
|
||||
public static final String MOD_ID = "resclone";
|
||||
|
@ -83,7 +83,12 @@ public class Resclone implements ModInitializer, RescloneApi {
|
|||
|
||||
@Override
|
||||
public void addPack(String fetcher, String pack, String name, boolean forceRedownload) {
|
||||
conf.add(new PackMetaUnloaded(fetcher, pack, name, forceRedownload));
|
||||
addPack(fetcher, pack, name, forceRedownload, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPack(String fetcher, String pack, String name, boolean forceRedownload, boolean forceEnable) {
|
||||
conf.add(new PackMetaUnloaded(fetcher, pack, name, forceRedownload, forceEnable));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -114,10 +119,13 @@ public class Resclone implements ModInitializer, RescloneApi {
|
|||
Path cacheDir = getConfigPath().resolve("cache");
|
||||
PackMetaLoaded p;
|
||||
try {
|
||||
boolean isNew = !urlCache.containsKey(meta.source);
|
||||
//Download
|
||||
Result fr = fetcherInstances.get(meta.fetcher).get(meta.source, cacheDir, meta.forceDownload);
|
||||
p = new PackMetaLoaded(fr.downloadPath, meta.name);
|
||||
p = new PackMetaLoaded(fr.downloadPath, meta.name, meta.forceEnable);
|
||||
metas.add(p);
|
||||
if (isNew)
|
||||
newPacks.add(p);
|
||||
if (fr.freshDownload) {
|
||||
//Process
|
||||
Map<String, String> props = new HashMap<>();
|
||||
|
@ -153,5 +161,4 @@ public class Resclone implements ModInitializer, RescloneApi {
|
|||
}
|
||||
return configPath;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package io.gitlab.jfronny.resclone.api;
|
||||
|
||||
import io.gitlab.jfronny.resclone.util.Result;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface PackFetcher {
|
||||
Result get(String baseUrl, Path targetDir, boolean forceDownload) throws Exception;
|
||||
String getSourceTypeName(); // The name for users to specify in the config
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package io.gitlab.jfronny.resclone.api;
|
||||
|
||||
import java.nio.file.FileSystem;
|
||||
|
||||
public interface PackProcessor {
|
||||
void process(FileSystem p) throws Exception;
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package io.gitlab.jfronny.resclone.api;
|
||||
|
||||
import io.gitlab.jfronny.resclone.fetchers.PackFetcher;
|
||||
import io.gitlab.jfronny.resclone.processors.PackProcessor;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface RescloneApi {
|
||||
|
@ -15,6 +12,8 @@ public interface RescloneApi {
|
|||
|
||||
void addPack(String fetcher, String pack, String name, boolean forceRedownload);
|
||||
|
||||
void addPack(String fetcher, String pack, String name, boolean forceRedownload, boolean forceEnable);
|
||||
|
||||
void reload();
|
||||
|
||||
Path getConfigPath();
|
||||
|
|
|
@ -3,13 +3,13 @@ package io.gitlab.jfronny.resclone.data;
|
|||
import java.nio.file.Path;
|
||||
|
||||
public class PackMetaLoaded {
|
||||
public final Path zipPath;
|
||||
public final String name;
|
||||
public final boolean forceEnable;
|
||||
|
||||
public Path zipPath;
|
||||
public String name;
|
||||
|
||||
public PackMetaLoaded(Path zipPath, String name) {
|
||||
public PackMetaLoaded(Path zipPath, String name, boolean forceEnable) {
|
||||
this.zipPath = zipPath;
|
||||
this.name = name;
|
||||
this.forceEnable = forceEnable;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +1,17 @@
|
|||
package io.gitlab.jfronny.resclone.data;
|
||||
|
||||
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) {
|
||||
public PackMetaUnloaded(String fetcher, String source, String name, boolean forceDownload, boolean forceEnable) {
|
||||
this.fetcher = fetcher;
|
||||
this.source = source;
|
||||
this.name = name;
|
||||
this.forceDownload = forceDownload;
|
||||
this.forceEnable = forceEnable;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.gitlab.jfronny.resclone.fetchers;
|
||||
|
||||
import io.gitlab.jfronny.resclone.Resclone;
|
||||
import io.gitlab.jfronny.resclone.api.PackFetcher;
|
||||
import io.gitlab.jfronny.resclone.util.Result;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -9,10 +10,7 @@ import java.net.URL;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public abstract class PackFetcher {
|
||||
|
||||
abstract public String getSourceTypeName(); // The name for users to specify in the config
|
||||
|
||||
public abstract class BasePackFetcher implements PackFetcher {
|
||||
abstract String getDownloadUrl(String baseUrl) throws Exception; // Return the actual download URL for the file based on the provided string
|
||||
|
||||
public Result get(String baseUrl, Path targetDir, boolean forceDownload) throws Exception {
|
||||
|
@ -51,5 +49,4 @@ public abstract class PackFetcher {
|
|||
Resclone.COUNT++;
|
||||
return new Result(p, true);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package io.gitlab.jfronny.resclone.fetchers;
|
||||
|
||||
public class BasicFileFetcher extends PackFetcher {
|
||||
public class BasicFileFetcher extends BasePackFetcher {
|
||||
|
||||
@Override
|
||||
public String getSourceTypeName() {
|
||||
|
|
|
@ -8,7 +8,7 @@ import net.minecraft.MinecraftVersion;
|
|||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class CurseforgeFetcher extends PackFetcher {
|
||||
public class CurseforgeFetcher extends BasePackFetcher {
|
||||
|
||||
@Override
|
||||
public String getSourceTypeName() {
|
||||
|
|
|
@ -8,7 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GitHubFetcher extends PackFetcher {
|
||||
public class GitHubFetcher extends BasePackFetcher {
|
||||
@Override
|
||||
public String getSourceTypeName() {
|
||||
return "github";
|
||||
|
|
|
@ -17,7 +17,6 @@ import java.util.function.Consumer;
|
|||
|
||||
@Mixin(FileResourcePackProvider.class)
|
||||
public class FileResourcePackProviderMixin {
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private ResourcePackSource field_25345;
|
||||
|
@ -27,7 +26,7 @@ public class FileResourcePackProviderMixin {
|
|||
for (PackMetaLoaded meta : Resclone.downloadedPacks) {
|
||||
ResourcePackProfile resourcePackProfile = ResourcePackProfile.of(
|
||||
"resclone/" + meta.name,
|
||||
false,
|
||||
meta.forceEnable,
|
||||
() -> new RescloneResourcePack(meta.zipPath.toFile(), meta.name),
|
||||
factory,
|
||||
ResourcePackProfile.InsertionPosition.TOP,
|
||||
|
@ -38,5 +37,4 @@ public class FileResourcePackProviderMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package io.gitlab.jfronny.resclone.mixin;
|
||||
|
||||
import io.gitlab.jfronny.resclone.Resclone;
|
||||
import io.gitlab.jfronny.resclone.data.PackMetaLoaded;
|
||||
import net.minecraft.client.options.GameOptions;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(GameOptions.class)
|
||||
public abstract class GameOptionsMixin {
|
||||
@Shadow public List<String> resourcePacks;
|
||||
|
||||
@Shadow public abstract void write();
|
||||
|
||||
@Inject(at = @At("TAIL"), method = "load()V")
|
||||
public void load(CallbackInfo ci) {
|
||||
for (PackMetaLoaded meta : Resclone.newPacks) {
|
||||
Resclone.LOGGER.info(Resclone.MOD_ID + "/" + meta.name);
|
||||
resourcePacks.add(Resclone.MOD_ID + "/" + meta.name);
|
||||
}
|
||||
if (!Resclone.newPacks.isEmpty())
|
||||
write();
|
||||
Resclone.newPacks.clear();
|
||||
}
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package io.gitlab.jfronny.resclone.processors;
|
||||
|
||||
import java.nio.file.FileSystem;
|
||||
|
||||
public abstract class PackProcessor {
|
||||
public abstract void process(FileSystem p) throws Exception;
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package io.gitlab.jfronny.resclone.processors;
|
||||
|
||||
import io.gitlab.jfronny.resclone.api.PackProcessor;
|
||||
import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
@ -10,7 +11,7 @@ import java.nio.file.FileSystem;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
|
||||
public class PruneVanillaProcessor extends PackProcessor {
|
||||
public class PruneVanillaProcessor implements PackProcessor {
|
||||
|
||||
@Override
|
||||
public void process(FileSystem p) throws Exception {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package io.gitlab.jfronny.resclone.processors;
|
||||
|
||||
import io.gitlab.jfronny.resclone.api.PackProcessor;
|
||||
import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -8,7 +9,7 @@ import java.nio.file.FileSystem;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class RemoveEmptyProcessor extends PackProcessor {
|
||||
public class RemoveEmptyProcessor implements PackProcessor {
|
||||
|
||||
@Override
|
||||
public void process(FileSystem p) throws Exception {
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package io.gitlab.jfronny.resclone.processors;
|
||||
|
||||
import io.gitlab.jfronny.resclone.api.PackProcessor;
|
||||
import io.gitlab.jfronny.resclone.util.io.MoveDirVisitor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
|
||||
public class RootPathProcessor extends PackProcessor {
|
||||
public class RootPathProcessor implements PackProcessor {
|
||||
|
||||
@Override
|
||||
public void process(FileSystem p) throws Exception {
|
||||
|
|
|
@ -26,7 +26,7 @@ public class ConfigLoader {
|
|||
}
|
||||
Set<PackMetaUnloaded> data = Resclone.gson.fromJson(text.toString(), new TypeToken<Set<PackMetaUnloaded>>(){}.getType());
|
||||
for (PackMetaUnloaded meta : data) {
|
||||
api.addPack(meta.fetcher, meta.source, meta.name, meta.forceDownload);
|
||||
api.addPack(meta.fetcher, meta.source, meta.name, meta.forceDownload, meta.forceEnable);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
"package": "io.gitlab.jfronny.resclone.mixin",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"FileResourcePackProviderMixin"
|
||||
"FileResourcePackProviderMixin",
|
||||
"GameOptionsMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in New Issue