Introduce a new centralized version checking system.

Using the @Mod annotation mods can opt-in to a centrally controlled update system.
This is PURELY a notification system and will NOT automatically download any updates.
The End User can control which mods check for updates and disabel the system entirely using the Forge Config and GUI.
Format for the json the URL must point to is described here: https://gist.github.com/LexManos/7aacb9aa991330523884
This commit is contained in:
Lex Manos committed 2015-11-04 14:37:15 -08:00
1 parent 479c7f8b54
commit d790008353
11 files changed
+291 -41

No files matched your search

@@ -22,6 +22,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map.Entry;
import javax.imageio.ImageIO;
@@ -43,10 +44,14 @@ import net.minecraft.util.IChatComponent;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StringUtils;
import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.common.ForgeVersion.CheckResult;
import net.minecraftforge.common.ForgeVersion.Status;
import net.minecraftforge.fml.common.FMLLog;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.ModContainer.Disableable;
import net.minecraftforge.fml.common.versioning.ComparableVersion;
import static net.minecraft.util.EnumChatFormatting.*;
import org.apache.logging.log4j.Level;
@@ -343,7 +348,7 @@ public class GuiModList extends GuiScreen
ResourceLocation logoPath = null;
Dimension logoDims = new Dimension(0, 0);
List<String> lines = new ArrayList<String>();
//CheckResult vercheck = ForgeVersion.getResult(selectedMod);
CheckResult vercheck = ForgeVersion.getResult(selectedMod);
String logoFile = selectedMod.getMetadata().logoFile;
if (!logoFile.isEmpty())
@@ -408,8 +413,8 @@ public class GuiModList extends GuiScreen
else
lines.add("Child mods: " + selectedMod.getMetadata().getChildModList());
//if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
// lines.add("Update Avalible: " + (vercheck.url == null ? "" : vercheck.url));
if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
lines.add("Update Avalible: " + (vercheck.url == null ? "" : vercheck.url));
lines.add(null);
lines.add(selectedMod.getMetadata().description);
@@ -419,15 +424,15 @@ public class GuiModList extends GuiScreen
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 Avalible: " + (vercheck.url == null ? "" : vercheck.url));
if (vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED)
lines.add("Update Avalible: " + (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)
if ((vercheck.status == Status.OUTDATED || vercheck.status == Status.BETA_OUTDATED) && vercheck.changes.size() > 0)
{
lines.add(null);
lines.add("Changes:");
@@ -437,7 +442,7 @@ public class GuiModList extends GuiScreen
lines.add(entry.getValue());
lines.add(null);
}
}*/
}
modInfo = new Info(this.width - this.listWidth - 30, lines, logoPath, logoDims);
}
@@ -17,6 +17,8 @@ import java.util.ArrayList;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.StringUtils;
import net.minecraftforge.common.ForgeVersion;
import net.minecraftforge.common.ForgeVersion.CheckResult;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.LoaderState.ModState;
import net.minecraftforge.fml.common.ModContainer;
@@ -79,7 +81,7 @@ public class GuiSlotModList extends GuiScrollingList
String name = StringUtils.stripControlCodes(mc.getName());
String version = StringUtils.stripControlCodes(mc.getDisplayVersion());
FontRenderer font = this.parent.getFontRenderer();
//CheckResult vercheck = ForgeVersion.getResult(mc);
CheckResult vercheck = ForgeVersion.getResult(mc);
if (Loader.instance().getModState(mc) == ModState.DISABLED)
{
@@ -93,7 +95,7 @@ public class GuiSlotModList extends GuiScrollingList
font.drawString(font.trimStringToWidth(version, listWidth - 10), 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);
/*switch(vercheck.status) //TODO: Change to icons?
switch(vercheck.status) //TODO: Change to icons?
{
case BETA_OUTDATED:
case OUTDATED:
@@ -105,8 +107,7 @@ public class GuiSlotModList extends GuiScrollingList
case PENDING:
case UP_TO_DATE:
break;
}*/
}
}
}
}
@@ -13,6 +13,7 @@
package net.minecraftforge.fml.common;
import java.io.File;
import java.net.URL;
import java.security.cert.Certificate;
import java.util.Collections;
import java.util.List;
@@ -206,4 +207,10 @@ public class DummyModContainer implements ModContainer
{
return true;
}
@Override
public URL getUpdateUrl()
{
return null;
}
}
@@ -18,6 +18,8 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.cert.Certificate;
import java.util.Arrays;
import java.util.List;
@@ -87,6 +89,7 @@ public class FMLModContainer implements ModContainer
private ListMultimap<Class<? extends FMLEvent>,Method> eventMethods;
private Map<String, String> customModProperties;
private ModCandidate candidate;
private URL updateJSONUrl;
public FMLModContainer(String className, ModCandidate container, Map<String,Object> modDescriptor)
{
@@ -215,6 +218,19 @@ public class FMLModContainer implements ModContainer
{
minecraftAccepted = Loader.instance().getMinecraftModContainer().getStaticVersionRange();
}
String jsonURL = (String)descriptor.get("updateJSON");
if (!Strings.isNullOrEmpty(jsonURL))
{
try
{
this.updateJSONUrl = new URL(jsonURL);
}
catch (MalformedURLException e)
{
FMLLog.log(getModId(), Level.DEBUG, "Specified json URL invalid: %s", jsonURL);
}
}
}
public Properties searchForVersionProperties()
@@ -663,4 +679,10 @@ public class FMLModContainer implements ModContainer
return true;
}
@Override
public URL getUpdateUrl()
{
return updateJSONUrl;
}
}
@@ -13,6 +13,7 @@
package net.minecraftforge.fml.common;
import java.io.File;
import java.net.URL;
import java.security.cert.Certificate;
import java.util.List;
import java.util.Map;
@@ -207,4 +208,10 @@ public class InjectedModContainer implements ModContainer
{
return true;
}
@Override
public URL getUpdateUrl()
{
return wrappedContainer.getUpdateUrl();
}
}
@@ -157,18 +157,18 @@ public @interface Mod
* @return The language the mod is authored in
*/
String modLanguage() default "java";
/**
* The language adapter to be used to load this mod. This overrides the value of modLanguage. The class must have a
* public zero variable constructor and implement {@link ILanguageAdapter} just like the Java and Scala adapters.
*
*
* A class with an invalid constructor or that doesn't implement {@link ILanguageAdapter} will throw an exception and
* halt loading.
*
*
* @return The full class name of the language adapter
*/
String modLanguageAdapter() default "";
/**
* NOT YET IMPLEMENTED. </br>
* An optional ASM hook class, that can be used to apply ASM to classes loaded from this mod. It is also given
@@ -198,6 +198,14 @@ public @interface Mod
* @return The name of a class implementing {@link IModGuiFactory}
*/
String guiFactory() default "";
/**
* An optional URL to a JSON file that will be checked once per launch to determine if there is an updated
* version of this mod and notify the end user. For more information see ForgeVersion.
* @return URL to update metadata json
*/
String updateJSON() default "";
/**
* A list of custom properties for this mod. Completely up to the mod author if/when they
* want to put anything in here.
@@ -13,6 +13,7 @@
package net.minecraftforge.fml.common;
import java.io.File;
import java.net.URL;
import java.security.cert.Certificate;
import java.util.List;
import java.util.Map;
@@ -149,4 +150,6 @@ public interface ModContainer
List<String> getOwnedPackages();
boolean shouldLoadInEnvironment();
URL getUpdateUrl();
}
@@ -35,7 +35,12 @@ public class ModMetadata
public String description = "";
public String url = "";
@Deprecated //Never really used for anything and format is undefined. See updateJSON for replacement.
public String updateUrl = "";
/**
* URL to update json file. Format is defined here: https://gist.github.com/LexManos/7aacb9aa991330523884
*/
public String updateJSON = "";
public String logoFile = "";
public String version = "";