Refactored the remote version check to check against the GitHub repo instead of my DropBox folder, added some colourized text to the result message on the client, and reformatted some of the localization.
This commit is contained in:
parent
e0783ef4b5
commit
01304fb4c4
7 changed files with 188 additions and 154 deletions
|
@ -4,7 +4,9 @@ import java.util.EnumSet;
|
||||||
|
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
import cpw.mods.fml.common.ITickHandler;
|
import cpw.mods.fml.common.ITickHandler;
|
||||||
|
import cpw.mods.fml.common.Loader;
|
||||||
import cpw.mods.fml.common.TickType;
|
import cpw.mods.fml.common.TickType;
|
||||||
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||||
import ee3.common.core.helper.VersionHelper;
|
import ee3.common.core.helper.VersionHelper;
|
||||||
import ee3.common.lib.Colours;
|
import ee3.common.lib.Colours;
|
||||||
import ee3.common.lib.ConfigurationSettings;
|
import ee3.common.lib.ConfigurationSettings;
|
||||||
|
@ -13,7 +15,8 @@ import ee3.common.lib.Reference;
|
||||||
/**
|
/**
|
||||||
* VersionCheckTickHandler
|
* VersionCheckTickHandler
|
||||||
*
|
*
|
||||||
* Class for notifying the player on their client when they get in game the outcome of the remote version check
|
* Class for notifying the player on their client when they get in game the
|
||||||
|
* outcome of the remote version check
|
||||||
*
|
*
|
||||||
* @author pahimar
|
* @author pahimar
|
||||||
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||||
|
@ -21,37 +24,42 @@ import ee3.common.lib.Reference;
|
||||||
*/
|
*/
|
||||||
public class VersionCheckTickHandler implements ITickHandler {
|
public class VersionCheckTickHandler implements ITickHandler {
|
||||||
|
|
||||||
private static boolean initialized = false;
|
private static boolean initialized = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tickStart(EnumSet<TickType> type, Object... tickData) { }
|
public void tickStart(EnumSet<TickType> type, Object... tickData) {
|
||||||
|
|
||||||
@Override
|
}
|
||||||
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
|
|
||||||
if (ConfigurationSettings.ENABLE_VERSION_CHECK) {
|
|
||||||
if (!initialized) {
|
|
||||||
for (TickType tickType : type) {
|
|
||||||
if (tickType == TickType.CLIENT) {
|
|
||||||
if (FMLClientHandler.instance().getClient().currentScreen == null) {
|
|
||||||
initialized = true;
|
|
||||||
if (VersionHelper.result != VersionHelper.CURRENT){
|
|
||||||
FMLClientHandler.instance().getClient().ingameGUI.getChatGUI().printChatMessage(Colours.VERSION_CHECK_PREFIX + "[" + Reference.MOD_NAME + "] " + VersionHelper.getResultMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EnumSet<TickType> ticks() {
|
public void tickEnd(EnumSet<TickType> type, Object... tickData) {
|
||||||
return EnumSet.of(TickType.CLIENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
if (ConfigurationSettings.ENABLE_VERSION_CHECK) {
|
||||||
public String getLabel() {
|
if (!initialized) {
|
||||||
return Reference.MOD_NAME + ": " + this.getClass().getSimpleName();
|
for (TickType tickType : type) {
|
||||||
}
|
if (tickType == TickType.CLIENT) {
|
||||||
|
if (FMLClientHandler.instance().getClient().currentScreen == null) {
|
||||||
|
initialized = true;
|
||||||
|
if (VersionHelper.result == VersionHelper.OUTDATED) {
|
||||||
|
FMLClientHandler.instance().getClient().ingameGUI.getChatGUI().printChatMessage(VersionHelper.getResultMessageForClient());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EnumSet<TickType> ticks() {
|
||||||
|
|
||||||
|
return EnumSet.of(TickType.CLIENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLabel() {
|
||||||
|
|
||||||
|
return Reference.MOD_NAME + ": " + this.getClass().getSimpleName();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,25 @@
|
||||||
package ee3.common.core.helper;
|
package ee3.common.core.helper;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import cpw.mods.fml.common.FMLCommonHandler;
|
import cpw.mods.fml.common.FMLCommonHandler;
|
||||||
import cpw.mods.fml.common.Loader;
|
import cpw.mods.fml.common.Loader;
|
||||||
import cpw.mods.fml.common.registry.LanguageRegistry;
|
import cpw.mods.fml.common.registry.LanguageRegistry;
|
||||||
|
import ee3.common.lib.Colours;
|
||||||
import ee3.common.lib.ConfigurationSettings;
|
import ee3.common.lib.ConfigurationSettings;
|
||||||
import ee3.common.lib.Reference;
|
import ee3.common.lib.Reference;
|
||||||
|
import ee3.common.lib.Strings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* VersionHelper
|
* VersionHelper
|
||||||
*
|
*
|
||||||
* Contains methods for checking the version of the currently running instance of the mod against a remote version number authority.
|
* Contains methods for checking the version of the currently running instance
|
||||||
* Meant to help users by notifying them if they are behind the latest published version of the mod
|
* of the mod against a remote version number authority. Meant to help users by
|
||||||
|
* notifying them if they are behind the latest published version of the mod
|
||||||
*
|
*
|
||||||
* @author pahimar
|
* @author pahimar
|
||||||
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
||||||
|
@ -23,109 +27,125 @@ import ee3.common.lib.Reference;
|
||||||
*/
|
*/
|
||||||
public class VersionHelper {
|
public class VersionHelper {
|
||||||
|
|
||||||
// The (publicly available) remote version number authority file
|
// The (publicly available) remote version number authority file
|
||||||
private static final String REMOTE_VERSION_FILE = "https://dl.dropbox.com/u/25591134/EE3/version.txt";
|
private static final String REMOTE_VERSION_XML_FILE = "https://raw.github.com/pahimar/Equivalent-Exchange-3/master/version.xml";
|
||||||
|
|
||||||
// All possible results of the remote version number check
|
public static Properties remoteVersionProperties = new Properties();
|
||||||
public static final byte UNINITIALIZED = 0;
|
|
||||||
public static final byte CURRENT = 1;
|
|
||||||
public static final byte OUTDATED = 2;
|
|
||||||
public static final byte CONNECTION_ERROR = 3;
|
|
||||||
|
|
||||||
// Localization keys
|
// All possible results of the remote version number check
|
||||||
private static final String VERSION_CHECK_DISABLED = "version.check_disabled";
|
public static final byte UNINITIALIZED = 0;
|
||||||
private static final String VERSION_CHECK_INIT_LOG_MESSAGE = "version.init_log_message";
|
public static final byte CURRENT = 1;
|
||||||
private static final String UNINITIALIZED_MESSAGE = "version.uninitialized";
|
public static final byte OUTDATED = 2;
|
||||||
private static final String CURRENT_MESSAGE = "version.current";
|
public static final byte GENERAL_ERROR = 3;
|
||||||
private static final String OUTDATED_MESSAGE = "version.outdated";
|
|
||||||
private static final String CONNECTION_ERROR_MESSAGE = "version.connection_error";
|
|
||||||
|
|
||||||
// Var to hold the result of the remote version check, initially set to uninitialized
|
// Var to hold the result of the remote version check, initially set to uninitialized
|
||||||
public static byte result = UNINITIALIZED;
|
public static byte result = UNINITIALIZED;
|
||||||
|
public static String remoteVersion = null;
|
||||||
|
public static String remoteUpdateLocation = null;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Checks the version of the currently running instance of the mod against the remote version authority, and sets the result of the check appropriately
|
* Checks the version of the currently running instance of the mod against
|
||||||
*/
|
* the remote version authority, and sets the result of the check
|
||||||
public static void checkVersion() {
|
* appropriately
|
||||||
try {
|
*/
|
||||||
URL url = new URL(REMOTE_VERSION_FILE);
|
public static void checkVersion() {
|
||||||
|
|
||||||
InputStreamReader isr = new InputStreamReader(url.openStream());
|
InputStream remoteVersionRepoStream = null;
|
||||||
BufferedReader reader = new BufferedReader(isr);
|
|
||||||
|
|
||||||
String line = null;
|
try {
|
||||||
|
URL remoteVersionURL = new URL(REMOTE_VERSION_XML_FILE);
|
||||||
|
remoteVersionRepoStream = remoteVersionURL.openStream();
|
||||||
|
remoteVersionProperties.loadFromXML(remoteVersionRepoStream);
|
||||||
|
|
||||||
// While we are not at the end of the file, fetch the next line in the file
|
String remoteVersionProperty = remoteVersionProperties.getProperty(Loader.instance().getMCVersionString());
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
// If the current line is for this version of Minecraft, read further
|
|
||||||
if (line.startsWith(Loader.instance().getMCVersionString())) {
|
|
||||||
// If the current line is also for this mod, read further
|
|
||||||
if (line.contains(Reference.CHANNEL_NAME)) {
|
|
||||||
// If the current line is also the same as the running version of the mod, set the result appropriately
|
|
||||||
if (line.endsWith(Reference.VERSION)) {
|
|
||||||
// Set the version check result to CURRENT
|
|
||||||
result = CURRENT;
|
|
||||||
|
|
||||||
// Close the associated network resources
|
if (remoteVersionProperty != null) {
|
||||||
reader.close();
|
remoteVersion = remoteVersionProperty.substring(0, remoteVersionProperty.indexOf("|"));
|
||||||
isr.close();
|
remoteUpdateLocation = remoteVersionProperty.substring(remoteVersionProperty.indexOf("|") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
if ((remoteVersion != null) && (remoteVersion.equals(Reference.VERSION))) {
|
||||||
}
|
result = CURRENT;
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Since this mod version is not the current version, set the version check appropriately
|
result = OUTDATED;
|
||||||
result = OUTDATED;
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if (result == UNINITIALIZED) {
|
||||||
|
result = GENERAL_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
// Close the associated network resources
|
try {
|
||||||
reader.close();
|
if (remoteVersionRepoStream != null) {
|
||||||
isr.close();
|
remoteVersionRepoStream.close();
|
||||||
} catch (Exception e) {
|
}
|
||||||
// If we cannot connect to the remote version number authority, set the version check appropriately
|
}
|
||||||
e.printStackTrace(System.err);
|
catch (IOException ex) {
|
||||||
result = CONNECTION_ERROR;
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public static void logResult() {
|
||||||
|
|
||||||
public static void logResult() {
|
if (ConfigurationSettings.ENABLE_VERSION_CHECK) {
|
||||||
if (ConfigurationSettings.ENABLE_VERSION_CHECK) {
|
LogHelper.log(Level.INFO, LanguageRegistry.instance().getStringLocalization(Strings.VERSION_CHECK_INIT_LOG_MESSAGE) + " " + REMOTE_VERSION_XML_FILE);
|
||||||
LogHelper.log(Level.INFO, LanguageRegistry.instance().getStringLocalization(VERSION_CHECK_INIT_LOG_MESSAGE) + " " + REMOTE_VERSION_FILE);
|
if ((result == CURRENT) || (result == OUTDATED)) {
|
||||||
if ((result == CURRENT) || (result == OUTDATED)) {
|
LogHelper.log(Level.INFO, getResultMessage());
|
||||||
LogHelper.log(Level.INFO, getResultMessage());
|
}
|
||||||
}
|
else {
|
||||||
else {
|
LogHelper.log(Level.WARNING, getResultMessage());
|
||||||
LogHelper.log(Level.WARNING, getResultMessage());
|
}
|
||||||
}
|
}
|
||||||
}
|
else {
|
||||||
else {
|
LogHelper.log(Level.INFO, getResultMessage());
|
||||||
LogHelper.log(Level.INFO, getResultMessage());
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static String getResultMessage() {
|
public static String getResultMessage() {
|
||||||
if (ConfigurationSettings.ENABLE_VERSION_CHECK) {
|
|
||||||
if (result == UNINITIALIZED) {
|
if (ConfigurationSettings.ENABLE_VERSION_CHECK) {
|
||||||
return LanguageRegistry.instance().getStringLocalization(UNINITIALIZED_MESSAGE);
|
if (result == UNINITIALIZED) {
|
||||||
}
|
return LanguageRegistry.instance().getStringLocalization(Strings.UNINITIALIZED_MESSAGE);
|
||||||
else if (result == CURRENT) {
|
}
|
||||||
return LanguageRegistry.instance().getStringLocalization(CURRENT_MESSAGE);
|
else if (result == CURRENT) {
|
||||||
}
|
String returnString = LanguageRegistry.instance().getStringLocalization(Strings.CURRENT_MESSAGE);
|
||||||
else if (result == OUTDATED) {
|
returnString = returnString.replace("@REMOTE_MOD_VERSION@", remoteVersion);
|
||||||
return LanguageRegistry.instance().getStringLocalization(OUTDATED_MESSAGE);
|
returnString = returnString.replace("@MINECRAFT_VERSION@", Loader.instance().getMCVersionString());
|
||||||
}
|
return returnString;
|
||||||
else if (result == CONNECTION_ERROR) {
|
}
|
||||||
return LanguageRegistry.instance().getStringLocalization(CONNECTION_ERROR_MESSAGE);
|
else if (result == OUTDATED) {
|
||||||
}
|
String returnString = LanguageRegistry.instance().getStringLocalization(Strings.OUTDATED_MESSAGE);
|
||||||
else {
|
returnString = returnString.replace("@MOD_NAME@", Reference.MOD_NAME);
|
||||||
return null;
|
returnString = returnString.replace("@REMOTE_MOD_VERSION@", remoteVersion);
|
||||||
}
|
returnString = returnString.replace("@MINECRAFT_VERSION@", Loader.instance().getMCVersionString());
|
||||||
}
|
returnString = returnString.replace("@MOD_UPDATE_LOCATION@", remoteUpdateLocation);
|
||||||
else {
|
return returnString;
|
||||||
return LanguageRegistry.instance().getStringLocalization(VERSION_CHECK_DISABLED);
|
}
|
||||||
}
|
else if (result == GENERAL_ERROR) {
|
||||||
}
|
return LanguageRegistry.instance().getStringLocalization(Strings.GENERAL_ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return LanguageRegistry.instance().getStringLocalization(Strings.VERSION_CHECK_DISABLED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getResultMessageForClient() {
|
||||||
|
|
||||||
|
String returnString = LanguageRegistry.instance().getStringLocalization(Strings.OUTDATED_MESSAGE);
|
||||||
|
returnString = returnString.replace("@MOD_NAME@", Colours.TEXT_COLOUR_PREFIX_YELLOW + Reference.MOD_NAME + Colours.TEXT_COLOUR_PREFIX_WHITE);
|
||||||
|
returnString = returnString.replace("@REMOTE_MOD_VERSION@", Colours.TEXT_COLOUR_PREFIX_YELLOW + VersionHelper.remoteVersion + Colours.TEXT_COLOUR_PREFIX_WHITE);
|
||||||
|
returnString = returnString.replace("@MINECRAFT_VERSION@", Colours.TEXT_COLOUR_PREFIX_YELLOW + Loader.instance().getMCVersionString() + Colours.TEXT_COLOUR_PREFIX_WHITE);
|
||||||
|
returnString = returnString.replace("@MOD_UPDATE_LOCATION@", Colours.TEXT_COLOUR_PREFIX_YELLOW + VersionHelper.remoteUpdateLocation + Colours.TEXT_COLOUR_PREFIX_WHITE);
|
||||||
|
return returnString;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ public class Colours {
|
||||||
public static final String PURE_RED = "ff0000";
|
public static final String PURE_RED = "ff0000";
|
||||||
|
|
||||||
/* Text colour related constants */
|
/* Text colour related constants */
|
||||||
public static final String VERSION_CHECK_PREFIX = "\u00a7e";
|
public static final String TEXT_COLOUR_PREFIX_YELLOW = "\u00a7e";
|
||||||
|
|
||||||
|
public static final String TEXT_COLOUR_PREFIX_WHITE = "\u00a7f";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,14 @@ package ee3.common.lib;
|
||||||
public class Strings {
|
public class Strings {
|
||||||
|
|
||||||
/* General text keys */
|
/* General text keys */
|
||||||
public static final String TEXT_IMPURE = "text.impure";
|
|
||||||
public static final String TEXT_PURE = "text.pure";
|
/* Version check related constants */
|
||||||
|
public static final String VERSION_CHECK_DISABLED = "version.check_disabled";
|
||||||
|
public static final String VERSION_CHECK_INIT_LOG_MESSAGE = "version.init_log_message";
|
||||||
|
public static final String UNINITIALIZED_MESSAGE = "version.uninitialized";
|
||||||
|
public static final String CURRENT_MESSAGE = "version.current";
|
||||||
|
public static final String OUTDATED_MESSAGE = "version.outdated";
|
||||||
|
public static final String GENERAL_ERROR_MESSAGE = "version.general_error";
|
||||||
|
|
||||||
/* Gui related constants */
|
/* Gui related constants */
|
||||||
public static final String GUI_CALCINATOR_NAME = "gui.calcinator.name";
|
public static final String GUI_CALCINATOR_NAME = "gui.calcinator.name";
|
||||||
|
|
|
@ -21,12 +21,10 @@
|
||||||
<entry key="tile.calcinator.name">Calcinator</entry>
|
<entry key="tile.calcinator.name">Calcinator</entry>
|
||||||
<entry key="gui.calcinator.name">Calcinator</entry>
|
<entry key="gui.calcinator.name">Calcinator</entry>
|
||||||
<entry key="itemGroup.EE3">Equivalent Exchange 3</entry>
|
<entry key="itemGroup.EE3">Equivalent Exchange 3</entry>
|
||||||
<entry key="text.impure">Impure</entry>
|
<entry key="version.init_log_message">Initializing remote version check against remote version authority, located at</entry>
|
||||||
<entry key="text.pure">Pure</entry>
|
<entry key="version.uninitialized">Remote version check failed to initialize properly</entry>
|
||||||
<entry key="version.init_log_message">Initializing version check against the remote version authority file, located at</entry>
|
<entry key="version.current">Currently using the most up to date version (@REMOTE_MOD_VERSION@) of Equivalent Exchange 3 for @MINECRAFT_VERSION@</entry>
|
||||||
<entry key="version.uninitialized">The version check did not complete successfully (version check did not initialize properly)</entry>
|
<entry key="version.outdated">A new @MOD_NAME@ version exists (@REMOTE_MOD_VERSION@) for @MINECRAFT_VERSION@. Get it here: @MOD_UPDATE_LOCATION@</entry>
|
||||||
<entry key="version.current">You are currently using the most up to date version for your version of Minecraft</entry>
|
<entry key="version.general_error">Error checking the remote version authority file</entry>
|
||||||
<entry key="version.outdated">You are currently using an out of date version; consider updating here - http://goo.gl/Ria2V</entry>
|
|
||||||
<entry key="version.connection_error">Error connecting to the remote version authority file (check your Internet connection?)</entry>
|
|
||||||
<entry key="version.check_disabled">Remote version check disabled, skipping</entry>
|
<entry key="version.check_disabled">Remote version check disabled, skipping</entry>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
Loading…
Reference in a new issue