Add forceDownload key in PackMetaUnloaded (allows using it in configs) which allows bypassing the caching behaviour
This commit is contained in:
parent
239a8ff856
commit
a0207bb153
|
@ -6,7 +6,7 @@ minecraft_version=1.16.5
|
|||
yarn_mappings=1.16.5+build.4
|
||||
loader_version=0.11.1
|
||||
# Mod Properties
|
||||
mod_version=1.3.0
|
||||
mod_version=1.4.0
|
||||
maven_group=io.gitlab.jfronny
|
||||
archives_base_name=resclone
|
||||
# Dependencies
|
||||
|
|
|
@ -63,7 +63,12 @@ public class Resclone implements ModInitializer, RescloneApi {
|
|||
|
||||
@Override
|
||||
public void addPack(String fetcher, String pack, String name) {
|
||||
conf.add(new PackMetaUnloaded(fetcher, pack, name));
|
||||
addPack(fetcher, pack, name, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPack(String fetcher, String pack, String name, boolean forceRedownload) {
|
||||
conf.add(new PackMetaUnloaded(fetcher, pack, name, forceRedownload));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -79,7 +84,7 @@ public class Resclone implements ModInitializer, RescloneApi {
|
|||
PackMetaLoaded p;
|
||||
try {
|
||||
//Download
|
||||
PackFetcher.FetcherResult fr = fetcherInstances.get(s.fetcher).get(s.source, cacheDir);
|
||||
PackFetcher.Result fr = fetcherInstances.get(s.fetcher).get(s.source, cacheDir, s.forceDownload);
|
||||
p = new PackMetaLoaded(fr.downloadPath, s.name);
|
||||
metas.add(p);
|
||||
if (fr.freshDownload) {
|
||||
|
|
|
@ -9,6 +9,7 @@ public interface RescloneApi {
|
|||
void addFetcher(PackFetcher fetcher);
|
||||
void addProcessor(PackProcessor processor);
|
||||
void addPack(String fetcher, String pack, String name);
|
||||
void addPack(String fetcher, String pack, String name, boolean forceRedownload);
|
||||
void reload();
|
||||
Path getConfigPath();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,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);
|
||||
api.addPack(meta.fetcher, meta.source, meta.name, meta.forceDownload);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
package io.gitlab.jfronny.resclone.data;
|
||||
|
||||
public class PackMetaUnloaded {
|
||||
public String fetcher;
|
||||
public String source;
|
||||
public String name;
|
||||
public final String fetcher;
|
||||
public final String source;
|
||||
public final String name;
|
||||
public final boolean forceDownload;
|
||||
|
||||
public PackMetaUnloaded(String fetcher, String source, String name) {
|
||||
public PackMetaUnloaded(String fetcher, String source, String name, boolean forceDownload) {
|
||||
this.fetcher = fetcher;
|
||||
this.source = source;
|
||||
this.name = name;
|
||||
this.forceDownload = forceDownload;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ public abstract class PackFetcher {
|
|||
return gson.fromJson(readStringFromURL(requestUrl), TypeToken.getParameterized(Set.class, classOfT).getType());
|
||||
}
|
||||
|
||||
public FetcherResult get(String baseUrl, Path targetDir) throws RescloneException {
|
||||
public Result get(String baseUrl, Path targetDir, boolean forceDownload) throws RescloneException {
|
||||
String url;
|
||||
try {
|
||||
url = getDownloadUrl(baseUrl);
|
||||
|
@ -64,8 +64,8 @@ public abstract class PackFetcher {
|
|||
}
|
||||
}
|
||||
Path p = targetDir.resolve(Integer.toHexString(url.hashCode()));
|
||||
if (Files.exists(p))
|
||||
return new FetcherResult(p, false);
|
||||
if (!forceDownload && Files.exists(p))
|
||||
return new Result(p, false);
|
||||
System.out.println("Downloading pack " + url);
|
||||
try (InputStream is = new URL(url).openStream()) {
|
||||
FileOutputStream os = new FileOutputStream(p.toFile());
|
||||
|
@ -79,14 +79,14 @@ public abstract class PackFetcher {
|
|||
catch (Throwable e) {
|
||||
throw new RescloneException("Could not download pack", e);
|
||||
}
|
||||
return new FetcherResult(p, true);
|
||||
return new Result(p, true);
|
||||
}
|
||||
|
||||
public class FetcherResult {
|
||||
public class Result {
|
||||
public final Path downloadPath;
|
||||
public final boolean freshDownload;
|
||||
|
||||
public FetcherResult(Path downloadPath, boolean freshDownload) {
|
||||
public Result(Path downloadPath, boolean freshDownload) {
|
||||
this.downloadPath = downloadPath;
|
||||
this.freshDownload = freshDownload;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue