Search in sources :

Example 1 with Status

use of net.minecraftforge.common.ForgeVersion.Status in project MinecraftForge by MinecraftForge.

the class ForgeVersion method startVersionCheck.

public static void startVersionCheck() {
    new Thread("Forge Version Check") {

        @Override
        public void run() {
            if (!ForgeModContainer.getConfig().get(ForgeModContainer.VERSION_CHECK_CAT, "Global", true).getBoolean()) {
                FMLLog.log("ForgeVersionCheck", Level.INFO, "Global Forge version check system disabled, no further processing.");
                return;
            }
            for (Entry<ModContainer, URL> entry : gatherMods().entrySet()) {
                ModContainer mod = entry.getKey();
                if (ForgeModContainer.getConfig().get(ForgeModContainer.VERSION_CHECK_CAT, mod.getModId(), true).getBoolean()) {
                    process(mod, entry.getValue());
                } else {
                    FMLLog.log("ForgeVersionCheck", Level.INFO, "[%s] Skipped version check", mod.getModId());
                }
            }
        }

        private void process(ModContainer mod, URL url) {
            try {
                FMLLog.log("ForgeVersionCheck", Level.INFO, "[%s] Starting version check at %s", mod.getModId(), url.toString());
                Status status = PENDING;
                ComparableVersion target = null;
                InputStream con = url.openStream();
                String data = new String(ByteStreams.toByteArray(con), "UTF-8");
                con.close();
                FMLLog.log("ForgeVersionCheck", Level.DEBUG, "[%s] Received version check data:\n%s", mod.getModId(), data);
                @SuppressWarnings("unchecked") Map<String, Object> json = new Gson().fromJson(data, Map.class);
                @SuppressWarnings("unchecked") Map<String, String> promos = (Map<String, String>) json.get("promos");
                String display_url = (String) json.get("homepage");
                String rec = promos.get(MinecraftForge.MC_VERSION + "-recommended");
                String lat = promos.get(MinecraftForge.MC_VERSION + "-latest");
                ComparableVersion current = new ComparableVersion(mod.getVersion());
                if (rec != null) {
                    ComparableVersion recommended = new ComparableVersion(rec);
                    int diff = recommended.compareTo(current);
                    if (diff == 0)
                        status = UP_TO_DATE;
                    else if (diff < 0) {
                        status = AHEAD;
                        if (lat != null) {
                            ComparableVersion latest = new ComparableVersion(lat);
                            if (current.compareTo(latest) < 0) {
                                status = OUTDATED;
                                target = latest;
                            }
                        }
                    } else {
                        status = OUTDATED;
                        target = recommended;
                    }
                } else if (lat != null) {
                    ComparableVersion latest = new ComparableVersion(lat);
                    if (current.compareTo(latest) < 0) {
                        status = BETA_OUTDATED;
                        target = latest;
                    } else
                        status = BETA;
                } else
                    status = BETA;
                FMLLog.log("ForgeVersionCheck", Level.INFO, "[%s] Found status: %s Target: %s", mod.getModId(), status, target);
                Map<ComparableVersion, String> changes = new LinkedHashMap<ComparableVersion, String>();
                @SuppressWarnings("unchecked") Map<String, String> tmp = (Map<String, String>) json.get(MinecraftForge.MC_VERSION);
                if (tmp != null) {
                    List<ComparableVersion> ordered = new ArrayList<ComparableVersion>();
                    for (String key : tmp.keySet()) {
                        ComparableVersion ver = new ComparableVersion(key);
                        if (ver.compareTo(current) > 0 && (target == null || ver.compareTo(target) < 1)) {
                            ordered.add(ver);
                        }
                    }
                    Collections.sort(ordered);
                    for (ComparableVersion ver : ordered) {
                        changes.put(ver, tmp.get(ver.toString()));
                    }
                }
                if (mod instanceof InjectedModContainer)
                    mod = ((InjectedModContainer) mod).wrappedContainer;
                results.put(mod, new CheckResult(status, target, changes, display_url));
            } catch (Exception e) {
                FMLLog.log("ForgeVersionCheck", Level.DEBUG, e, "Failed to process update information");
                status = FAILED;
            }
        }
    }.start();
}
Also used : Status(net.minecraftforge.common.ForgeVersion.Status) InjectedModContainer(net.minecraftforge.fml.common.InjectedModContainer) ModContainer(net.minecraftforge.fml.common.ModContainer) InputStream(java.io.InputStream) InjectedModContainer(net.minecraftforge.fml.common.InjectedModContainer) Gson(com.google.gson.Gson) ComparableVersion(net.minecraftforge.fml.common.versioning.ComparableVersion) URL(java.net.URL) Entry(java.util.Map.Entry) ArrayList(java.util.ArrayList) List(java.util.List) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with Status

use of net.minecraftforge.common.ForgeVersion.Status in project MinecraftForge by MinecraftForge.

the class ForgeHooksClient method renderMainMenu.

public static String renderMainMenu(GuiMainMenu gui, FontRenderer font, int width, int height, String splashText) {
    Status status = ForgeVersion.getStatus();
    if (status == BETA || status == BETA_OUTDATED) {
        // render a warning at the top of the screen,
        String line = I18n.format("forge.update.beta.1", TextFormatting.RED, TextFormatting.RESET);
        gui.drawString(font, line, (width - font.getStringWidth(line)) / 2, 4 + (0 * (font.FONT_HEIGHT + 1)), -1);
        line = I18n.format("forge.update.beta.2");
        gui.drawString(font, line, (width - font.getStringWidth(line)) / 2, 4 + (1 * (font.FONT_HEIGHT + 1)), -1);
    }
    if (!Loader.instance().java8) {
        String line = I18n.format("fml.messages.java8warning.1", TextFormatting.RED, TextFormatting.RESET);
        gui.drawString(font, line, (width - font.getStringWidth(line)) / 2, 4 + (8 * (font.FONT_HEIGHT + 1)), -1);
        line = I18n.format("fml.messages.java8warning.2");
        gui.drawString(font, line, (width - font.getStringWidth(line)) / 2, 4 + (9 * (font.FONT_HEIGHT + 1)), -1);
        splashText = updatescrollcounter < 50 ? "UPDATE!" : "JAVA!";
        updatescrollcounter += 1;
        updatescrollcounter %= 100;
    }
    String line = null;
    switch(status) {
        //case AHEAD:         line = "Using non-recommended Forge build, issues may arise."}; break;
        case OUTDATED:
        case BETA_OUTDATED:
            line = I18n.format("forge.update.newversion", ForgeVersion.getTarget());
            break;
        default:
            break;
    }
    if (line != null) {
        // if we have a line, render it in the bottom right, above Mojang's copyright line
        gui.drawString(font, line, width - font.getStringWidth(line) - 2, height - (2 * (font.FONT_HEIGHT + 1)), -1);
    }
    return splashText;
}
Also used : Status(net.minecraftforge.common.ForgeVersion.Status)

Aggregations

Status (net.minecraftforge.common.ForgeVersion.Status)2 Gson (com.google.gson.Gson)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 InjectedModContainer (net.minecraftforge.fml.common.InjectedModContainer)1 ModContainer (net.minecraftforge.fml.common.ModContainer)1 ComparableVersion (net.minecraftforge.fml.common.versioning.ComparableVersion)1