string thisver = "3.10.6";
string check_version() {
string soft = "Universal Recovery";
string prop = "_version_BalesUniversalRecovery";
int thread = 1780;
int w; string page;
boolean sameornewer(string local, string server) {
if (local == server) return true;
string[int] loc = split_string(local,"\\.");
string[int] ser = split_string(server,"\\.");
for i from 0 to max(count(loc)-1,count(ser)-1) {
if (i+1 > count(loc)) return false;
if (i+1 > count(ser)) return true;
if (loc[i].to_int() < ser[i].to_int()) return false;
if (loc[i].to_int() > ser[i].to_int()) return true;
}
return local == server;
}
switch(get_property(prop)) {
case thisver: return "";
case "":
print("Checking for updates (running "+soft+" ver. "+thisver+")...");
page = visit_url("http://kolmafia.us/showthread.php?t="+thread);
matcher find_ver = create_matcher("<b>"+soft+" (.+?)</b>",page);
if (!find_ver.find()) {
print("Unable to load current version info.", "red");
set_property(prop,thisver);
return "";
}
w=19;
set_property(prop,find_ver.group(1));
default:
if(sameornewer(thisver,get_property(prop))) {
set_property(prop,thisver);
print("You have a current version of "+soft+".");
return "";
}
string msg = "<big><font color=red><b>New Version of "+soft+" Available: "+get_property(prop)+"</b></font></big>"+
"<br><a href='http://kolmafia.us/showthread.php?t="+thread+"' target='_blank'><u>Upgrade from "+thisver+" to "+get_property(prop)+" here!</u></a><br>"+
"<small>Think you are getting this message in error? Force a re-check by typing \"set "+prop+" =\" in the CLI.</small><br>";
find_ver = create_matcher("\\[requires revision (.+?)\\]",page);
if (find_ver.find() && find_ver.group(1).to_int() > get_revision())
msg += " (Note: you will also need to <a href='http://builds.kolmafia.us/' target='_blank'>update mafia to r"+find_ver.group(1)+" or higher</a> to use this update.)";
print_html(msg);
if(w > 0) wait(w);
return "<div class='versioninfo'>"+msg+"</div>";
}
return "";
}