+ public void run() {
+ Connection connection = freenetInterface.getConnection("jSite-" + ++counter + "-UpdateChecker");
+ try {
+ connection.connect();
+ } catch (IOException e1) {
+ e1.printStackTrace();
+ }
+ Client client = new Client(connection);
+ while (!shouldStop()) {
+ System.out.println("Trying " + constructUpdateKey(lastUpdateEdition));
+ ClientGet clientGet = new ClientGet("get-update-key");
+ clientGet.setUri(constructUpdateKey(lastUpdateEdition));
+ clientGet.setPersistence(Persistence.CONNECTION);
+ clientGet.setReturnType(ReturnType.direct);
+ clientGet.setVerbosity(Verbosity.ALL);
+ try {
+ client.execute(clientGet);
+ boolean stop = false;
+ while (!stop) {
+ Message message = client.readMessage();
+ System.out.println(message);
+ if ("GetFailed".equals(message.getName())) {
+ if ("27".equals(message.get("code"))) {
+ String editionString = message.get("redirecturi").split("/")[2];
+ int editionNumber = -1;
+ try {
+ editionNumber = Integer.parseInt(editionString);
+ } catch (NumberFormatException nfe1) {
+ /* ignore. */
+ }
+ if (editionNumber != -1) {
+ System.out.println("Found new edition " + editionNumber);
+ lastUpdateEdition = editionNumber;
+ break;
+ }
+ }
+ }
+ if ("AllData".equals(message.getName())) {
+ System.out.println("Update data found.");
+ InputStream dataInputStream = null;
+ Properties properties = new Properties();
+ try {
+ dataInputStream = message.getPayloadInputStream();
+ properties.load(dataInputStream);
+ } finally {
+ Closer.close(dataInputStream);
+ }
+
+ String foundVersionString = properties.getProperty("jSite.Version");
+ if (foundVersionString != null) {
+ Version foundVersion = Version.parse(foundVersionString);
+ if (foundVersion != null) {
+ if (foundVersion.compareTo(Main.getVersion()) > 0) {
+ lastVersion = foundVersion;
+ String versionTimestampString = properties.getProperty("jSite.Date");
+ long versionTimestamp = -1;
+ try {
+ versionTimestamp = Long.parseLong(versionTimestampString);
+ } catch (NumberFormatException nfe1) {
+ /* ignore. */
+ }
+ fireUpdateFound(foundVersion, versionTimestamp);
+ }
+ }
+ }
+ }