[COLOR="#FF0000"][B]setvar("stableUpdateOnly",true);[/B][/COLOR] // Actually this goes at the bottom of the script
// checks script version once daily, returns empty string, OR div with update message inside
string check_version(string soft, string prop, string thisver, int thread) { int w = 8; string page; matcher find_ver;
if (svn_exists(prop)[COLOR="#FF0000"][B] && vars["stableUpdateOnly"] == "false"[/B][/COLOR]) { return check_version(soft, prop, thread); }
if (count(zv) == 0) file_to_map("zversions.txt",zv);
boolean sameornewer(string local, string server) {
if (equals(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;
}
if (zv[prop].vdate != today_to_string()) {
vprint("Checking for updates (running "+soft+" ver. "+thisver+")...",1);
page = visit_url("http://kolmafia.us/showthread.php?t="+thread);
find_ver = create_matcher("<b>"+soft+" (.+?)</b>",page);
zv[prop].vdate = today_to_string();
if (!find_ver.find()) {
vprint("Unable to load current version info.",-1);
map_to_file(zv,"zversions.txt");
return "";
} w=1;
zv[prop].ver = find_ver.group(1);
map_to_file(zv,"zversions.txt");
}
if (sameornewer(thisver,zv[prop].ver)) { vprint("Running "+soft+" version: "+thisver+" (current)","gray",w); return ""; }
[COLOR="#FF0000"][B]if (svn_exists(prop)) { return check_version(soft, prop, thread); }[/B][/COLOR]
string msg = "<big><font color=red><b>New Version of "+soft+" Available: "+zv[prop].ver+"</b></font></big>"+
"<br><a href='http://kolmafia.us/showthread.php?t="+thread+"' target='_blank'><u>Upgrade from "+thisver+" to "+zv[prop].ver+" here!</u></a><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.)";
vprint_html(msg,1);
return "<div class='versioninfo'>"+msg+"</div>";
}