/** * Checks if newer versions of cachewolf are available * * @return [0] = recommended version type, [1]...[4]: 0: no update available, 1: newer version * available, 2: version doesn't exists, 3: error * @throws IOException */ public static void checkForUpdates() throws IOException { Properties curvers = UrlFetcher.fetchPropertyList("http://www.cachewolf.org/currentversions.txt"); versionnumbers = new String[updateavailabe.length]; for (int i = updateavailabe.length - 1; i >= 1; i--) { updateavailabe[i] = checkVersion(curvers, "T" + (i - 1), i); // this also sets versionnumber[i] } updateavailabe[0] = Convert.toInt(curvers.getProperty("RecommendedType", "0")); }
/** * @param url * @return: 1 = newer Version available, 0 = this is up to date, 3 = check failed */ private static int checkVersion(Properties curvers, String prefix, int t) { try { int curvmaj = Convert.toInt(curvers.getProperty(prefix + "VersionMajor", "0")); int curvmin = Convert.toInt(curvers.getProperty(prefix + "VersionMinor", "0")); String svnRString = curvers.getProperty(prefix + "SvnRevision", "0"); if (svnRString.startsWith("http")) { String tmp; Regex s; int i = svnRString.indexOf(' '); if (i > 0) { tmp = UrlFetcher.fetchString(svnRString.substring(0, i)); s = new Regex( svnRString.substring( i + 1, svnRString .length())); // flyingfish works 3/2008 with // ("(?i)Revision[\\s]*[:=][\\s]*[\\\\r]*[\\\\n]*[\\s]*([0-9]*)"); } else { versionnumbers[t] = "error: no RegEx"; return 3; } s.search(tmp); if (!s.didMatch()) { versionnumbers[t] = "error: RegEx didnot match"; return 3; } svnRString = s.stringMatched(1); } versionnumbers[t] = curvmaj + "." + curvmin + "." + svnRString; if (curvmaj > VER_MAJOR) return 1; if (curvmaj < VER_MAJOR) return 0; if (curvmin > VER_MINOR) return 1; if (curvmin < VER_MINOR) return 0; if (Convert.toInt(svnRString) > SVN_REVISION) return 1; return 0; } catch (IOException e) { versionnumbers[t] = "IO-error"; return 3; } }