mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 12:09:39 +00:00
Remove VersionChecker
This commit is contained in:
1 parent
bf23ca2317
commit
9140f84d57
12 files changed
+33
-171
No files matched your search
@@ -26,24 +26,11 @@ public class CommandVersion extends SubCommand {
|
||||
|
||||
@Override
|
||||
public void processSubCommand(ICommandSender sender, String[] args) {
|
||||
ChatStyle style = new ChatStyle();
|
||||
if (Version.isOutdated()) {
|
||||
style.setColor(EnumChatFormatting.RED);
|
||||
} else {
|
||||
style.setColor(EnumChatFormatting.GREEN);
|
||||
}
|
||||
|
||||
CommandHelpers.sendLocalizedChatMessage(
|
||||
sender,
|
||||
style,
|
||||
new ChatStyle().setColor(EnumChatFormatting.GREEN),
|
||||
"for.chat.version",
|
||||
Version.getVersion(),
|
||||
Proxies.common.getMinecraftVersion(),
|
||||
Version.getRecommendedVersion());
|
||||
if (Version.isOutdated()) {
|
||||
for (String updateLine : Version.getChangelog()) {
|
||||
CommandHelpers.sendChatMessage(sender, EnumChatFormatting.BLUE + updateLine);
|
||||
}
|
||||
}
|
||||
Proxies.common.getMinecraftVersion());
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.config;
|
||||
|
||||
import forestry.Tags;
|
||||
import forestry.api.core.IForestryConstants;
|
||||
|
||||
public class Constants implements IForestryConstants {
|
||||
@@ -15,7 +16,7 @@ public class Constants implements IForestryConstants {
|
||||
// System
|
||||
public static final String MOD = "Forestry";
|
||||
public static final String ID = "forestry";
|
||||
public static final String VERSION = "GRADLETOKEN_VERSION";
|
||||
public static final String VERSION = Tags.VERSION;
|
||||
public static final String URL = "http://forestry.sengir.net/";
|
||||
|
||||
public static final int FLAG_BLOCK_UPDATE = 1;
|
||||
|
||||
@@ -8,21 +8,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.config;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.versioning.DefaultArtifactVersion;
|
||||
import forestry.Forestry;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.Tags;
|
||||
|
||||
/**
|
||||
* With permission from pahimar.
|
||||
@@ -31,163 +17,51 @@ import forestry.core.utils.Log;
|
||||
*/
|
||||
public class Version {
|
||||
|
||||
@Deprecated
|
||||
public enum EnumUpdateState {
|
||||
CURRENT,
|
||||
OUTDATED,
|
||||
CONNECTION_ERROR
|
||||
}
|
||||
|
||||
public static final String VERSION = "@VERSION@";
|
||||
public static final String BUILD_NUMBER = "@BUILD_NUMBER@";
|
||||
public static final String VERSION = Tags.VERSION;
|
||||
@Deprecated
|
||||
public static final String BUILD_NUMBER = "";
|
||||
@Deprecated
|
||||
public static final String[] FAILED_CHANGELOG = new String[] {
|
||||
String.format("Unable to retrieve changelog for %s", Constants.MOD) };
|
||||
private static final String REMOTE_VERSION_FILE = "http://bit.ly/forestryver";
|
||||
private static final String REMOTE_CHANGELOG_ROOT = "https://dl.dropbox.com/u/44760587/forestry/changelog/";
|
||||
@Deprecated
|
||||
public static EnumUpdateState currentVersion = EnumUpdateState.CURRENT;
|
||||
private static String recommendedVersion;
|
||||
private static String[] cachedChangelog = FAILED_CHANGELOG;
|
||||
|
||||
public static String getVersion() {
|
||||
return VERSION + " (" + BUILD_NUMBER + ")";
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean isOutdated() {
|
||||
return currentVersion == EnumUpdateState.OUTDATED;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static boolean needsUpdateNoticeAndMarkAsSeen() {
|
||||
if (!isOutdated()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
File versionFile = new File(Forestry.instance.getConfigFolder(), Config.CATEGORY_COMMON + ".cfg");
|
||||
Configuration config = new Configuration(versionFile);
|
||||
Property property = config.get("version", "seen", VERSION);
|
||||
property.comment = "indicates the last version the user has been informed about and will suppress further notices on it.";
|
||||
String seenVersion = property.getString();
|
||||
|
||||
if (recommendedVersion == null || recommendedVersion.equals(seenVersion)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
property.set(recommendedVersion);
|
||||
config.save();
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String getRecommendedVersion() {
|
||||
return recommendedVersion;
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
private static class VersionChecker extends Thread {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String location = REMOTE_VERSION_FILE;
|
||||
HttpURLConnection conn = null;
|
||||
while (location != null && !location.isEmpty()) {
|
||||
URL url = new URL(location);
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestProperty(
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)");
|
||||
conn.connect();
|
||||
location = conn.getHeaderField("Location");
|
||||
}
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
|
||||
String line;
|
||||
String mcVersion = Proxies.common.getMinecraftVersion();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.startsWith(mcVersion) && line.contains(Constants.MOD)) {
|
||||
String[] tokens = line.split(":");
|
||||
recommendedVersion = tokens[2];
|
||||
}
|
||||
}
|
||||
|
||||
if (recommendedVersion == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int result = FMLCommonHandler.instance().findContainerFor(Forestry.instance).getProcessedVersion()
|
||||
.compareTo(new DefaultArtifactVersion(recommendedVersion));
|
||||
if (result >= 0) {
|
||||
Log.finer(
|
||||
"Using the latest version [" + VERSION
|
||||
+ " (build:"
|
||||
+ BUILD_NUMBER
|
||||
+ ")] for Minecraft "
|
||||
+ mcVersion);
|
||||
currentVersion = EnumUpdateState.CURRENT;
|
||||
return;
|
||||
}
|
||||
|
||||
cachedChangelog = grabChangelog(recommendedVersion);
|
||||
|
||||
Log.warning(
|
||||
"Using outdated version [" + VERSION
|
||||
+ " (build:"
|
||||
+ BUILD_NUMBER
|
||||
+ ")] for Minecraft "
|
||||
+ mcVersion
|
||||
+ ". Consider updating.");
|
||||
currentVersion = EnumUpdateState.OUTDATED;
|
||||
|
||||
} catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
Log.warning("Unable to read from remote version authority.");
|
||||
currentVersion = EnumUpdateState.CONNECTION_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void versionCheck() {
|
||||
new VersionChecker().start();
|
||||
}
|
||||
@Deprecated
|
||||
public static void versionCheck() {}
|
||||
|
||||
@Deprecated
|
||||
public static String[] getChangelog() {
|
||||
return cachedChangelog;
|
||||
return FAILED_CHANGELOG;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String[] grabChangelog(String version) {
|
||||
|
||||
try {
|
||||
String location = REMOTE_CHANGELOG_ROOT + version;
|
||||
HttpURLConnection conn;
|
||||
do {
|
||||
URL url = new URL(location);
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestProperty(
|
||||
"User-Agent",
|
||||
"Mozilla/5.0 (Windows; U; Windows NT 6.0; ru; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)");
|
||||
conn.connect();
|
||||
location = conn.getHeaderField("Location");
|
||||
} while (location != null && !location.isEmpty());
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
|
||||
String line;
|
||||
ArrayList<String> changelog = new ArrayList<>();
|
||||
while ((line = reader.readLine()) != null) {
|
||||
if (line.startsWith("#")) {
|
||||
continue;
|
||||
}
|
||||
if (line.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
changelog.add(line);
|
||||
}
|
||||
|
||||
return changelog.toArray(new String[changelog.size()]);
|
||||
|
||||
} catch (Exception ex) {
|
||||
// ex.printStackTrace();
|
||||
Log.warning("Unable to read changelog from remote site.");
|
||||
}
|
||||
|
||||
return new String[] { String.format("Unable to retrieve changelog for %s %s", Constants.MOD, version) };
|
||||
return FAILED_CHANGELOG;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user