Search in sources :

Example 1 with ComparableVersion

use of net.minecraftforge.fml.common.versioning.ComparableVersion 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 ComparableVersion

use of net.minecraftforge.fml.common.versioning.ComparableVersion in project MinecraftForge by MinecraftForge.

the class GuiModList method updateCache.

private void updateCache() {
    configModButton.visible = false;
    disableModButton.visible = false;
    modInfo = null;
    if (selectedMod == null)
        return;
    ResourceLocation logoPath = null;
    Dimension logoDims = new Dimension(0, 0);
    List<String> lines = new ArrayList<String>();
    CheckResult vercheck = ForgeVersion.getResult(selectedMod);
    String logoFile = selectedMod.getMetadata().logoFile;
    if (!logoFile.isEmpty()) {
        TextureManager tm = mc.getTextureManager();
        IResourcePack pack = FMLClientHandler.instance().getResourcePackFor(selectedMod.getModId());
        try {
            BufferedImage logo = null;
            if (pack != null) {
                logo = pack.getPackImage();
            } else {
                InputStream logoResource = getClass().getResourceAsStream(logoFile);
                if (logoResource != null)
                    logo = ImageIO.read(logoResource);
            }
            if (logo != null) {
                logoPath = tm.getDynamicTextureLocation("modlogo", new DynamicTexture(logo));
                logoDims = new Dimension(logo.getWidth(), logo.getHeight());
            }
        } catch (IOException e) {
        }
    }
    if (!selectedMod.getMetadata().autogenerated) {
        disableModButton.visible = true;
        disableModButton.enabled = true;
        disableModButton.packedFGColour = 0;
        Disableable disableable = selectedMod.canBeDisabled();
        if (disableable == Disableable.RESTART) {
            disableModButton.packedFGColour = 0xFF3377;
        } else if (disableable != Disableable.YES) {
            disableModButton.enabled = false;
        }
        IModGuiFactory guiFactory = FMLClientHandler.instance().getGuiFactoryFor(selectedMod);
        configModButton.visible = true;
        configModButton.enabled = guiFactory != null && guiFactory.mainConfigGuiClass() != null;
        lines.add(selectedMod.getMetadata().name);
        lines.add(String.format("Version: %s (%s)", selectedMod.getDisplayVersion(), selectedMod.getVersion()));
        lines.add(String.format("Mod ID: '%s' Mod State: %s", selectedMod.getModId(), Loader.instance().getModState(selectedMod)));
        if (!selectedMod.getMetadata().credits.isEmpty()) {
            lines.add("Credits: " + selectedMod.getMetadata().credits);
        }
        lines.add("Authors: " + selectedMod.getMetadata().getAuthorList());
        lines.add("URL: " + selectedMod.getMetadata().url);
        if (selectedMod.getMetadata().childMods.isEmpty())
            lines.add("No child mods for this mod");
        else
            lines.add("Child mods: " + selectedMod.getMetadata().getChildModList());
        if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
            lines.add("Update Available: " + (vercheck.url == null ? "" : vercheck.url));
        lines.add(null);
        lines.add(selectedMod.getMetadata().description);
    } else {
        lines.add(WHITE + selectedMod.getName());
        lines.add(WHITE + "Version: " + selectedMod.getVersion());
        lines.add(WHITE + "Mod State: " + Loader.instance().getModState(selectedMod));
        if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
            lines.add("Update Available: " + (vercheck.url == null ? "" : vercheck.url));
        lines.add(null);
        lines.add(RED + "No mod information found");
        lines.add(RED + "Ask your mod author to provide a mod mcmod.info file");
    }
    if ((vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED) && vercheck.changes.size() > 0) {
        lines.add(null);
        lines.add("Changes:");
        for (Entry<ComparableVersion, String> entry : vercheck.changes.entrySet()) {
            lines.add("  " + entry.getKey() + ":");
            lines.add(entry.getValue());
            lines.add(null);
        }
    }
    modInfo = new Info(this.width - this.listWidth - 30, lines, logoPath, logoDims);
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) DynamicTexture(net.minecraft.client.renderer.texture.DynamicTexture) Dimension(java.awt.Dimension) TextComponentString(net.minecraft.util.text.TextComponentString) IOException(java.io.IOException) ComparableVersion(net.minecraftforge.fml.common.versioning.ComparableVersion) IResourcePack(net.minecraft.client.resources.IResourcePack) BufferedImage(java.awt.image.BufferedImage) TextureManager(net.minecraft.client.renderer.texture.TextureManager) ResourceLocation(net.minecraft.util.ResourceLocation) CheckResult(net.minecraftforge.common.ForgeVersion.CheckResult) Disableable(net.minecraftforge.fml.common.ModContainer.Disableable)

Aggregations

InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 ComparableVersion (net.minecraftforge.fml.common.versioning.ComparableVersion)2 Gson (com.google.gson.Gson)1 Dimension (java.awt.Dimension)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 URL (java.net.URL)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 DynamicTexture (net.minecraft.client.renderer.texture.DynamicTexture)1 TextureManager (net.minecraft.client.renderer.texture.TextureManager)1 IResourcePack (net.minecraft.client.resources.IResourcePack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 CheckResult (net.minecraftforge.common.ForgeVersion.CheckResult)1