aboutsummaryrefslogtreecommitdiff
path: root/mod/src
diff options
context:
space:
mode:
Diffstat (limited to 'mod/src')
-rwxr-xr-xmod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java1
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java59
-rw-r--r--mod/src/main/java/kr/syeyoung/dungeonsguide/mod/YoMamaOutdated.java110
3 files changed, 58 insertions, 112 deletions
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java
index 4864fa53..0bdcacfc 100755
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/DungeonsGuide.java
@@ -261,6 +261,7 @@ public class DungeonsGuide implements DGInterface {
ProgressManager.pop(progressbar);
+ VersionInfo.checkAndOpen();
}
// hotswap fails in dev env due to intellij auto log collection or smth. it holds ref to stacktrace.
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java
index 5f5b6dd5..de67651f 100644
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java
+++ b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/VersionInfo.java
@@ -1,10 +1,18 @@
package kr.syeyoung.dungeonsguide.mod;
import kr.syeyoung.dungeonsguide.launcher.Main;
-import kr.syeyoung.dungeonsguide.launcher.loader.IDGLoader;
+import kr.syeyoung.dungeonsguide.launcher.branch.Update;
+import kr.syeyoung.dungeonsguide.launcher.branch.UpdateBranch;
+import kr.syeyoung.dungeonsguide.launcher.branch.UpdateRetrieverUtil;
+import kr.syeyoung.dungeonsguide.launcher.loader.*;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.io.IOException;
+import java.util.Optional;
public class VersionInfo {
- public static final String VERSION = "4.0.0-beta-1.0.0";
+ public static final String VERSION = "4.0.0-beta.1";
public static IDGLoader getCurrentLoader() {
return Main.getMain().getCurrentLoader();
@@ -13,4 +21,51 @@ public class VersionInfo {
public static String getLoaderInfo() {
return getCurrentLoader().loaderName();
}
+
+
+ private static final Logger logger = LogManager.getLogger("OutdatedVersionWarning");
+ public static void checkAndOpen() {
+ try {
+ if (VersionInfo.getCurrentLoader() instanceof DevEnvLoader) return;
+
+ if (VersionInfo.getCurrentLoader() instanceof RemoteLoader) {
+ RemoteLoader loader = (RemoteLoader) VersionInfo.getCurrentLoader();
+ Update latestUpdate = UpdateRetrieverUtil.getLatestUpdates(loader.getBranchId(), 0).get(0);
+ if (latestUpdate.getId() == loader.getUpdateId()) return;
+
+ // update alarm gui
+ // show newVersion name
+ // show update logs
+ // a button to try updating
+
+ logger.info("Update Required!!");
+ // TODO: after new gui framework.
+ } else if (VersionInfo.getCurrentLoader() instanceof JarLoader || VersionInfo.getCurrentLoader() instanceof LocalLoader) {
+ UpdateBranch requiredUpdateBranch = UpdateRetrieverUtil.getUpdateBranches().stream().filter(a ->
+ Optional.ofNullable(a.getMetadata())
+ .filter(b -> b.has("type"))
+ .map(b -> b.getString("type"))
+ .filter(b -> b.equals("update-alarm-github"))
+ .isPresent()).findFirst().orElse(null);
+ if (requiredUpdateBranch == null) {
+ logger.error("No update branch found: ???");
+ return;
+ }
+ Update latestUpdate = UpdateRetrieverUtil.getLatestUpdates(requiredUpdateBranch.getId(), 0).get(0);
+
+ if (latestUpdate.getName().equals(VersionInfo.VERSION)) return;
+ logger.info("Update Required!!");
+ // update alarm gui
+ // show newVersion name
+ // link to github url
+ // show update logs
+ // TODO: after new gui framework.
+ } else {
+ logger.error("Failed to check version: Unknown Loader: " + VersionInfo.getLoaderInfo() + " / " + VersionInfo.getCurrentLoader().getClass().getName());
+ }
+ } catch (Exception e) {
+ logger.error("Error while checking for updates: ",e);
+ }
+ }
+
}
diff --git a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/YoMamaOutdated.java b/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/YoMamaOutdated.java
deleted file mode 100644
index 88bc10f0..00000000
--- a/mod/src/main/java/kr/syeyoung/dungeonsguide/mod/YoMamaOutdated.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package kr.syeyoung.dungeonsguide.mod;
-
-import net.minecraft.client.Minecraft;
-import net.minecraft.client.gui.*;
-import net.minecraftforge.client.event.GuiOpenEvent;
-import net.minecraftforge.common.MinecraftForge;
-import net.minecraftforge.fml.common.FMLCommonHandler;
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-import org.lwjgl.opengl.GL11;
-
-import java.io.IOException;
-
-public class YoMamaOutdated {
-
- Logger logger = LogManager.getLogger("YoMamaOutdated");
-
- public boolean isUsingOutdatedDg = true;
- String outdatedMessage;
-
- public YoMamaOutdated() {
- MinecraftForge.EVENT_BUS.register(this);
- this.check();
- }
-
- void check() {
-
- isUsingOutdatedDg = false;
-
-// try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
-// HttpGet httpget = new HttpGet( "https://dungeonsguide.kingstefan26.workers.dev/outdated");
-// Header[] haeders = {new BasicHeader("User-Agent", "DungeonsGuide/" + Main.VERSION)};
-// httpget.setHeaders(haeders);
-// HttpResponse httpresponse = httpclient.execute(httpget);
-//
-// if (httpresponse.getStatusLine().getStatusCode() != 200) {
-// outdatedMessage = IOUtils.toString(httpresponse.getEntity().getContent(), StandardCharsets.UTF_8);
-// }else {
-// isUsingOutdatedDg = false;
-// }
-//
-// } catch (Exception ignored) {
-// }
-
- }
-
- private boolean showedError = false;
-
- @SubscribeEvent
- public void onGuiOpen(GuiOpenEvent event) {
- if (!showedError && isUsingOutdatedDg) {
- showedError = true;
-
- GuiScreen ogGui = event.gui;
-
- event.gui = new GuiScreen() {
- @Override
- public void initGui() {
- ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
- this.buttonList.add(new GuiButton(0, sr.getScaledWidth()/2-100,sr.getScaledHeight()-70 ,"Close Minecraft"));
- this.buttonList.add(new GuiButton(1, sr.getScaledWidth()/2-100,sr.getScaledHeight()-40 ,"Ignore"));
- }
-
- @Override
- protected void actionPerformed(GuiButton button) throws IOException {
- super.actionPerformed(button);
- if (button.id == 0) {
- FMLCommonHandler.instance().exitJava(-1,true);
- } else if (button.id == 1) {
- Minecraft.getMinecraft().displayGuiScreen(ogGui);
- }
- }
-
- @Override
- public void drawScreen(int mouseX, int mouseY, float partialTicks) {
- super.drawBackground(1);
-
- ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
- FontRenderer fontRenderer = Minecraft.getMinecraft().fontRendererObj;
- String text = "This DungeonsGuide installation seems to be invalid";
- fontRenderer.drawString(text, (sr.getScaledWidth()-fontRenderer.getStringWidth(text))/2,40,0xFFFF0000);
- String text1 = "Message from our server:";
- fontRenderer.drawString(text1, (sr.getScaledWidth()-fontRenderer.getStringWidth(text1))/2, (int) (40+fontRenderer.FONT_HEIGHT*1.5),0xFFFF0000);
-
- int tenth = sr.getScaledWidth() / 10;
-
- Gui.drawRect(tenth, 70,sr.getScaledWidth()-tenth, sr.getScaledHeight()-80, 0xFF5B5B5B);
- clip(sr, tenth, 70,sr.getScaledWidth()-2*tenth, sr.getScaledHeight()-150);
- GL11.glEnable(GL11.GL_SCISSOR_TEST);
-
-
- fontRenderer.drawString(outdatedMessage, tenth+2,fontRenderer.FONT_HEIGHT + 72, 0xFFFFFFFF);
-
- GL11.glDisable(GL11.GL_SCISSOR_TEST);
-
- super.drawScreen(mouseX, mouseY, partialTicks);
- }
-
- public void clip(ScaledResolution resolution, int x, int y, int width, int height) {
- if (width < 0 || height < 0) return;
-
- int scale = resolution.getScaleFactor();
- GL11.glScissor((x ) * scale, Minecraft.getMinecraft().displayHeight - (y + height) * scale, (width) * scale, height * scale);
- }
- };
- }
- }
-
-}