Java tutorial
/* Copyright (c) 2015 Lance Selga <lyonecro55@gmail.com> * * This work is free. You can redistribute it and/or modify it under the * terms of the Do What The Fuck You Want To Public License, Version 2, * as published by Sam Hocevar. See the COPYING file for more details. */ package lyonlancer5.pfsteel.util; import java.io.InputStream; import java.net.URL; import java.util.List; import lyonlancer5.pfsteel.LL5_PerfectSteel; import org.apache.commons.io.IOUtils; public class ModUpdater implements Runnable { private static boolean isLatestVersion = false; private int latestVersion = -1; private final String urlUpdateFile = "https://raw.githubusercontent.com/Lyonlancer5/Perfect-Steel/master/1.7.10-src/recent-version.ll5"; public boolean hasChecked = false; private static String latestVersionName = ""; private static String forumThread; private List<String> updateParams; @Override public void run() { InputStream in = null; try { in = new URL(urlUpdateFile).openStream(); LL5_PerfectSteel.pfsLogger.info("Checking for updates..."); } catch (Exception e) { LL5_PerfectSteel.pfsLogger .info("The update checker encountered an error while checking for updates : " + e.toString()); return; } try { updateParams = IOUtils.readLines(in); latestVersion = Integer.parseInt(updateParams.get(0)); latestVersionName = updateParams.get(2); forumThread = updateParams.get(3); } catch (Exception e) { LL5_PerfectSteel.pfsLogger .info("The update checker encountered an error while checking for updates : " + e.toString()); return; } finally { IOUtils.closeQuietly(in); } LL5_PerfectSteel.pfsLogger.info("Got version info from GitHub - " + latestVersionName); isLatestVersion = ModVersion.getBuildNumber() == latestVersion; if (!isLatestVersion) { if (ModVersion.getBuildNumber() > latestVersion) { LL5_PerfectSteel.pfsLogger.info( "The build number specified in this version is greater than the one specified on the update!"); LL5_PerfectSteel.pfsLogger.info("Are you running a custom version?"); } else { LL5_PerfectSteel.pfsLogger.info("There is a new update available!"); } } else { LL5_PerfectSteel.pfsLogger.info("No updates available"); } hasChecked = true; } public boolean isLatestVersion() { return isLatestVersion; } public String getLatestVersion() { return latestVersionName; } public String getForumThread() { return forumThread; } }