Search in sources :

Example 1 with InjectedModContainer

use of net.minecraftforge.fml.common.InjectedModContainer 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)

Aggregations

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 Status (net.minecraftforge.common.ForgeVersion.Status)1 InjectedModContainer (net.minecraftforge.fml.common.InjectedModContainer)1 ModContainer (net.minecraftforge.fml.common.ModContainer)1 ComparableVersion (net.minecraftforge.fml.common.versioning.ComparableVersion)1