Skip to content

Instantly share code, notes, and snippets.

@phl0w
Created June 18, 2012 19:46
Show Gist options
  • Select an option

  • Save phl0w/2950317 to your computer and use it in GitHub Desktop.

Select an option

Save phl0w/2950317 to your computer and use it in GitHub Desktop.
private final Pattern UPDATER_VERSION_PATTERN = Pattern
.compile("version\\s*=\\s*([0-9.]+)");
doUpdates("http://phl0w.site88.net/scripts/barb.php");
public double getVersion() {
return iTBarbFisher.class.getAnnotation(Manifest.class).version();
}
private void doUpdates(String url) {
try {
double currentVersion = getVersion();
double newVersion = -1;
URL site = new URL(url);
BufferedReader in = new BufferedReader(new InputStreamReader(
site.openStream()));
String line;
Matcher m;
while ((line = in.readLine()) != null) {
if ((m = UPDATER_VERSION_PATTERN.matcher(line)).find()) {
newVersion = Double.parseDouble(m.group(1));
break;
}
}
if (newVersion < 0) {
log.info("Unable to find the new version number. Update failed");
} else if (currentVersion == newVersion) {
log.info("You already have the latest version of the script.");
} else {
log.info("You do not have the most recent version! Check the forums for version "
+ newVersion);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment