mirror of
https://github.com/ViaVersion/ViaFabric.git
synced 2024-12-21 16:17:37 +01:00
Cache for only one day
This commit is contained in:
parent
0cd14768c7
commit
ac12697794
@ -33,6 +33,7 @@ import io.netty.channel.EventLoop;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.loader.FabricLoader;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
@ -76,15 +77,19 @@ public class ViaFabric implements ClientModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
int timeDivisor = 1000 * 60 * 60 * 24;
|
||||
long cachedTime = System.currentTimeMillis() / timeDivisor;
|
||||
File viaVersionJar = FabricLoader.INSTANCE.getConfigDirectory().toPath().resolve("ViaFabric").resolve("viaversion.jar").toFile();
|
||||
if (!(viaVersionJar.exists() && viaVersionJar.lastModified() / timeDivisor == cachedTime)) {
|
||||
String localMd5 = null;
|
||||
try {
|
||||
if (viaVersionJar.exists()) {
|
||||
try (InputStream is = Files.newInputStream(viaVersionJar.toPath())) {
|
||||
localMd5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(is);
|
||||
localMd5 = DigestUtils.md5Hex(is);
|
||||
}
|
||||
}
|
||||
HttpURLConnection con = (HttpURLConnection) new URL("https://repo.viaversion.com/us/myles/viaversion/").openConnection();
|
||||
HttpURLConnection con = (HttpURLConnection) new URL("https://repo.viaversion.com/us/myles/viaversion/?" + cachedTime).openConnection();
|
||||
JLOGGER.info("Checking for ViaVersion updates " + con);
|
||||
con.setRequestProperty("User-Agent", "ViaFabric/" + ViaFabric.getVersion());
|
||||
String rawOutput = CharStreams.toString(new InputStreamReader(con.getInputStream()));
|
||||
con.getInputStream().close();
|
||||
@ -120,10 +125,14 @@ public class ViaFabric implements ClientModInitializer {
|
||||
HttpURLConnection jarCon = (HttpURLConnection) url.openConnection();
|
||||
jarCon.setRequestProperty("User-Agent", "ViaFabric/" + ViaFabric.getVersion());
|
||||
FileUtils.copyInputStreamToFile(jarCon.getInputStream(), viaVersionJar);
|
||||
} else {
|
||||
JLOGGER.info("No updates found");
|
||||
viaVersionJar.setLastModified(System.currentTimeMillis());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
try {
|
||||
Method addUrl = ViaFabric.class.getClassLoader().getClass().getMethod("addURL", URL.class);
|
||||
addUrl.setAccessible(true);
|
||||
|
Loading…
Reference in New Issue
Block a user