aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/update
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-02-17 14:45:05 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-02-17 14:45:05 +0800
commitb6165b916b5a14ef07ada0b5c44db814d7a7865d (patch)
tree27d518cf3f8f0a412a46569c786548f33344a065 /src/main/java/me/shedaniel/rei/update
parent19ea772f65e0f58ad43dc5c65f2e79203f719e0b (diff)
downloadRoughlyEnoughItems-2.3.0.18.tar.gz
RoughlyEnoughItems-2.3.0.18.tar.bz2
RoughlyEnoughItems-2.3.0.18.zip
wtf i am stupidv2.3.0.18
Diffstat (limited to 'src/main/java/me/shedaniel/rei/update')
-rw-r--r--src/main/java/me/shedaniel/rei/update/UpdateChecker.java32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/main/java/me/shedaniel/rei/update/UpdateChecker.java b/src/main/java/me/shedaniel/rei/update/UpdateChecker.java
index edbc87b1d..781d1298b 100644
--- a/src/main/java/me/shedaniel/rei/update/UpdateChecker.java
+++ b/src/main/java/me/shedaniel/rei/update/UpdateChecker.java
@@ -5,21 +5,21 @@ import com.google.gson.*;
import com.google.gson.annotations.SerializedName;
import me.shedaniel.rei.client.ConfigHelper;
import org.apache.commons.io.IOUtils;
+import org.dimdev.riftloader.RiftLoader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringBufferInputStream;
+import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import java.util.stream.Collectors;
public class UpdateChecker {
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
- private static final String CURRENT_VERSION_STRING = "@VERSION@";
private static final String CURRENT_GAME_VERSION = "1.13.2";
private static Version CURRENT_VERSION;
private static Version latestForGame = null;
@@ -95,10 +95,11 @@ public class UpdateChecker {
public static void onInitialization() {
try {
- CURRENT_VERSION = new Version(CURRENT_VERSION_STRING);
- } catch (Exception e) {
- CURRENT_VERSION = new Version("10000.0");
+ RiftLoader.instance.getMods().stream().filter(modInfo -> modInfo.id.equalsIgnoreCase("roughlyenoughitems")).findFirst().ifPresent(modInfo -> CURRENT_VERSION = new Version(getVersionFromSource(modInfo.source)));
+ } catch (Exception e1) {
}
+ if (CURRENT_VERSION == null)
+ CURRENT_VERSION = new Version("10000.0");
if (!checkUpdates())
return;
InputStream downloadedStream = downloadVersionString();
@@ -115,6 +116,23 @@ public class UpdateChecker {
latestForGame = new Version("0.0.0");
}
+ private static String getVersionFromSource(File source) {
+ if (!source.isFile())
+ return null;
+ try (JarFile jar = new JarFile(source)) {
+ JarEntry entry = jar.getJarEntry("riftmod.json");
+ if (entry != null) {
+ InputStream inputStream = jar.getInputStream(entry);
+ JsonElement element = new JsonParser().parse(new InputStreamReader(inputStream));
+ JsonObject object = element.getAsJsonObject();
+ if (object.has("version"))
+ return object.getAsJsonPrimitive("version").getAsString();
+ }
+ } catch (Exception e) {
+ }
+ return null;
+ }
+
static class JsonVersionElement {
@SerializedName("latest")
private List<LatestVersionObject> latestVersions;