X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FUpdateChecker.java;h=511f4e1478d4e2654c1afc77eb501fd9f4b20232;hp=0839cb9dbabd8a8c944ad7502dadfa3d19d6cfc0;hb=c9e306ac8e3ada846e87a0cc256a20fc148f381c;hpb=fa63b855e28c5fbf270bfdca1bb23fd048affae5 diff --git a/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java b/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java index 0839cb9..511f4e1 100644 --- a/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java +++ b/src/main/java/net/pterodactylus/sone/core/UpdateChecker.java @@ -49,7 +49,7 @@ public class UpdateChecker { private static final String SONE_HOMEPAGE = "USK@nwa8lHa271k2QvJ8aa0Ov7IHAV-DFOCFgmDt3X6BpCI,DuQSUZiI~agF8c-6tjsFFGuZ8eICrzWCILB60nT8KKo,AQACAAE/sone/"; /** The current latest known edition. */ - private static final int LATEST_EDITION = 23; + private static final int LATEST_EDITION = 49; /** The Freenet interface. */ private final FreenetInterface freenetInterface; @@ -60,6 +60,9 @@ public class UpdateChecker { /** The current URI of the homepage. */ private FreenetURI currentUri; + /** The latest known edition. */ + private long latestEdition; + /** The current latest known version. */ private Version currentLatestVersion = SonePlugin.VERSION; @@ -135,6 +138,15 @@ public class UpdateChecker { return latestVersionDate; } + /** + * Returns the latest known edition of the Sone homepage. + * + * @return The latest edition of the Sone homepage + */ + public long getLatestEdition() { + return latestEdition; + } + // // ACTIONS // @@ -154,18 +166,19 @@ public class UpdateChecker { @Override @SuppressWarnings("synthetic-access") public void editionFound(FreenetURI uri, long edition, boolean newKnownGood, boolean newSlot) { - logger.log(Level.FINEST, "Found update for %s: %d, %s, %s", new Object[] { uri, edition, newKnownGood, newSlot }); + logger.log(Level.FINEST, String.format("Found update for %s: %d, %s, %s", uri, edition, newKnownGood, newSlot)); if (newKnownGood || newSlot) { Pair uriResult = freenetInterface.fetchUri(uri.setMetaString(new String[] { "sone.properties" })); if (uriResult == null) { - logger.log(Level.WARNING, "Could not fetch properties of latest homepage: %s", uri); + logger.log(Level.WARNING, String.format("Could not fetch properties of latest homepage: %s", uri)); return; } Bucket resultBucket = uriResult.getRight().asBucket(); try { - parseProperties(resultBucket.getInputStream()); + parseProperties(resultBucket.getInputStream(), edition); + latestEdition = edition; } catch (IOException ioe1) { - logger.log(Level.WARNING, "Could not parse sone.properties of " + uri, ioe1); + logger.log(Level.WARNING, String.format("Could not parse sone.properties of %s!", uri), ioe1); } finally { resultBucket.free(); } @@ -189,14 +202,16 @@ public class UpdateChecker { * Parses the properties of the latest version and fires events, if * necessary. * - * @see UpdateListener#updateFound(Version, long) - * @see UpdateListenerManager#fireUpdateFound(Version, long) + * @see UpdateListener#updateFound(Version, long, long) + * @see UpdateListenerManager#fireUpdateFound(Version, long, long) * @param propertiesInputStream * The input stream to parse + * @param edition + * The latest edition of the Sone homepage * @throws IOException * if an I/O error occured */ - private void parseProperties(InputStream propertiesInputStream) throws IOException { + private void parseProperties(InputStream propertiesInputStream, long edition) throws IOException { Properties properties = new Properties(); InputStreamReader inputStreamReader = null; try { @@ -225,8 +240,8 @@ public class UpdateChecker { if (version.compareTo(currentLatestVersion) > 0) { currentLatestVersion = version; latestVersionDate = releaseTime; - logger.log(Level.INFO, "Found new version: %s (%tc)", new Object[] { version, new Date(releaseTime) }); - updateListenerManager.fireUpdateFound(version, releaseTime); + logger.log(Level.INFO, String.format("Found new version: %s (%tc)", version, new Date(releaseTime))); + updateListenerManager.fireUpdateFound(version, releaseTime, edition); } }