Search in sources :

Example 1 with CheckResult

use of net.minecraftforge.common.ForgeVersion.CheckResult in project MC-Prefab by Brian-Wuest.

the class UpdateChecker method checkVersion.

/**
 * Checks the current version against the git-hub version.
 */
public static void checkVersion() {
    // Pull the repository information.
    ModContainer prefabMod = null;
    for (ModContainer modContainer : Loader.instance().getModList()) {
        if (modContainer.getName().toLowerCase().equals(Prefab.MODID.toLowerCase())) {
            prefabMod = modContainer;
            break;
        }
    }
    if (prefabMod != null) {
        CheckResult result = ForgeVersion.getResult(prefabMod);
        if (result != null && result.status == Status.OUTDATED) {
            // Current version is out dated, show the message when the user is logged in.
            UpdateChecker.messageToShow = "[Prefab] There is a new version available! New Version: [" + result.target.toString() + "] Your Version: [" + Prefab.VERSION + "]";
            UpdateChecker.showMessage = true;
        }
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) CheckResult(net.minecraftforge.common.ForgeVersion.CheckResult)

Example 2 with CheckResult

use of net.minecraftforge.common.ForgeVersion.CheckResult in project DynamicSurroundings by OreCruncher.

the class VersionChecker method getUpdateMessage.

@Nullable
private String getUpdateMessage(@Nonnull final String modId) {
    final ModContainer mod = ForgeUtils.findModContainer(modId);
    if (mod == null)
        return null;
    final CheckResult result = ForgeVersion.getResult(mod);
    if (dontPrintMessage(result))
        return null;
    final String t = result.target.toString();
    final String u = result.url.toString();
    return Localization.format(this.messageId, mod.getName(), t, u);
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) CheckResult(net.minecraftforge.common.ForgeVersion.CheckResult) Nullable(javax.annotation.Nullable)

Example 3 with CheckResult

use of net.minecraftforge.common.ForgeVersion.CheckResult in project ImmersiveEngineering by BluSunrize.

the class ClientProxy method addChangelogToManual.

public void addChangelogToManual() {
    FontRenderer fr = ManualHelper.getManual().fontRenderer;
    boolean isUnicode = fr.getUnicodeFlag();
    fr.setUnicodeFlag(true);
    SortedMap<ComparableVersion, Pair<String, IManualPage[]>> allChanges = new TreeMap<>(Comparator.reverseOrder());
    ComparableVersion currIEVer = new ComparableVersion(ImmersiveEngineering.VERSION);
    // Included changelog
    try (InputStream in = Minecraft.getMinecraft().getResourceManager().getResource(new ResourceLocation(ImmersiveEngineering.MODID, "changelog.json")).getInputStream()) {
        JsonElement ele = new JsonParser().parse(new InputStreamReader(in));
        JsonObject upToCurrent = ele.getAsJsonObject();
        for (Entry<String, JsonElement> entry : upToCurrent.entrySet()) {
            ComparableVersion version = new ComparableVersion(entry.getKey());
            Pair<String, IManualPage[]> manualEntry = addVersionToManual(currIEVer, version, entry.getValue().getAsString(), false);
            if (manualEntry != null)
                allChanges.put(version, manualEntry);
        }
    } catch (IOException x) {
        x.printStackTrace();
    }
    // Changelog from update JSON
    CheckResult result = ForgeVersion.getResult(Loader.instance().activeModContainer());
    if (result.status != Status.PENDING && result.status != Status.FAILED)
        for (Entry<ComparableVersion, String> e : result.changes.entrySet()) allChanges.put(e.getKey(), addVersionToManual(currIEVer, e.getKey(), e.getValue(), true));
    for (Pair<String, IManualPage[]> entry : allChanges.values()) ManualHelper.addEntry(entry.getLeft(), ManualHelper.CAT_UPDATE, entry.getRight());
    fr.setUnicodeFlag(isUnicode);
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) JsonObject(com.google.gson.JsonObject) IManualPage(blusunrize.lib.manual.IManualPage) IOException(java.io.IOException) ComparableVersion(net.minecraftforge.fml.common.versioning.ComparableVersion) ManualEntry(blusunrize.lib.manual.ManualInstance.ManualEntry) Entry(java.util.Map.Entry) JsonElement(com.google.gson.JsonElement) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) CheckResult(net.minecraftforge.common.ForgeVersion.CheckResult) FontRenderer(net.minecraft.client.gui.FontRenderer) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) JsonParser(com.google.gson.JsonParser)

Example 4 with CheckResult

use of net.minecraftforge.common.ForgeVersion.CheckResult 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)

Example 5 with CheckResult

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

the class GuiSlotModList method drawSlot.

@Override
protected void drawSlot(int idx, int right, int top, int height, Tessellator tess) {
    ModContainer mc = mods.get(idx);
    String name = StringUtils.stripControlCodes(mc.getName());
    String version = StringUtils.stripControlCodes(mc.getDisplayVersion());
    FontRenderer font = this.parent.getFontRenderer();
    CheckResult vercheck = ForgeVersion.getResult(mc);
    if (Loader.instance().getModState(mc) == ModState.DISABLED) {
        font.drawString(font.trimStringToWidth(name, listWidth - 10), this.left + 3, top + 2, 0xFF2222);
        font.drawString(font.trimStringToWidth(version, listWidth - (5 + height)), this.left + 3, top + 12, 0xFF2222);
        font.drawString(font.trimStringToWidth("DISABLED", listWidth - 10), this.left + 3, top + 22, 0xFF2222);
    } else {
        font.drawString(font.trimStringToWidth(name, listWidth - 10), this.left + 3, top + 2, 0xFFFFFF);
        font.drawString(font.trimStringToWidth(version, listWidth - (5 + height)), this.left + 3, top + 12, 0xCCCCCC);
        font.drawString(font.trimStringToWidth(mc.getMetadata() != null ? mc.getMetadata().getChildModCountString() : "Metadata not found", listWidth - 10), this.left + 3, top + 22, 0xCCCCCC);
        if (vercheck.status.shouldDraw()) {
            //TODO: Consider adding more icons for visualization
            Minecraft.getMinecraft().getTextureManager().bindTexture(VERSION_CHECK_ICONS);
            GlStateManager.color(1, 1, 1, 1);
            GlStateManager.pushMatrix();
            Gui.drawModalRectWithCustomSizedTexture(right - (height / 2 + 4), top + (height / 2 - 4), vercheck.status.getSheetOffset() * 8, (vercheck.status.isAnimated() && ((System.currentTimeMillis() / 800 & 1)) == 1) ? 8 : 0, 8, 8, 64, 16);
            GlStateManager.popMatrix();
        }
    }
}
Also used : ModContainer(net.minecraftforge.fml.common.ModContainer) CheckResult(net.minecraftforge.common.ForgeVersion.CheckResult) FontRenderer(net.minecraft.client.gui.FontRenderer)

Aggregations

CheckResult (net.minecraftforge.common.ForgeVersion.CheckResult)5 ModContainer (net.minecraftforge.fml.common.ModContainer)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 ComparableVersion (net.minecraftforge.fml.common.versioning.ComparableVersion)2 IManualPage (blusunrize.lib.manual.IManualPage)1 ManualEntry (blusunrize.lib.manual.ManualInstance.ManualEntry)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 Dimension (java.awt.Dimension)1 BufferedImage (java.awt.image.BufferedImage)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Entry (java.util.Map.Entry)1 Nullable (javax.annotation.Nullable)1 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)1 DynamicTexture (net.minecraft.client.renderer.texture.DynamicTexture)1 TextureManager (net.minecraft.client.renderer.texture.TextureManager)1