Update year in copyright lines
[Sone.git] / src / main / java / net / pterodactylus / sone / core / UpdateChecker.java
index 07398ec..2c2f121 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - UpdateChecker.java - Copyright © 2011–2015 David Roden
+ * Sone - UpdateChecker.java - Copyright © 2011–2019 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -30,7 +30,6 @@ import java.util.logging.Logger;
 
 import javax.inject.Singleton;
 
-import net.pterodactylus.sone.core.FreenetInterface.Fetched;
 import net.pterodactylus.sone.core.event.UpdateFoundEvent;
 import net.pterodactylus.sone.main.SonePlugin;
 import net.pterodactylus.util.io.Closer;
@@ -44,8 +43,6 @@ import freenet.support.api.Bucket;
 
 /**
  * Watches the official Sone homepage for new releases.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 @Singleton
 public class UpdateChecker {
@@ -63,10 +60,11 @@ public class UpdateChecker {
        private FreenetURI currentUri;
 
        /** The latest known edition. */
-       private long latestEdition;
+       private long latestEdition = SonePlugin.getLatestEdition();
 
        /** The current latest known version. */
-       private Version currentLatestVersion = SonePlugin.VERSION;
+       private Version currentLatestVersion;
+       private final Version currentRunningVersion;
 
        /** The release date of the latest version. */
        private long latestVersionDate;
@@ -80,9 +78,11 @@ public class UpdateChecker {
         *            The freenet interface to use
         */
        @Inject
-       public UpdateChecker(EventBus eventBus, FreenetInterface freenetInterface) {
+       public UpdateChecker(EventBus eventBus, FreenetInterface freenetInterface, Version currentVersion) {
                this.eventBus = eventBus;
                this.freenetInterface = freenetInterface;
+               this.currentRunningVersion = currentVersion;
+               this.currentLatestVersion = currentVersion;
        }
 
        //
@@ -96,7 +96,7 @@ public class UpdateChecker {
         * @return {@code true} if a new version was found
         */
        public boolean hasLatestVersion() {
-               return currentLatestVersion.compareTo(SonePlugin.VERSION) > 0;
+               return currentLatestVersion.compareTo(currentRunningVersion) > 0;
        }
 
        /**
@@ -221,9 +221,22 @@ public class UpdateChecker {
                if (version.compareTo(currentLatestVersion) > 0) {
                        currentLatestVersion = version;
                        latestVersionDate = releaseTime;
-                       logger.log(Level.INFO, String.format("Found new version: %s (%tc)", version, new Date(releaseTime)));
-                       eventBus.post(new UpdateFoundEvent(version, releaseTime, edition));
+                       boolean disruptive = disruptiveVersionBetweenCurrentAndFound(properties);
+                       logger.log(Level.INFO, String.format("Found new version: %s (%tc%s)", version, new Date(releaseTime), disruptive ? ", disruptive" : ""));
+                       eventBus.post(new UpdateFoundEvent(version, releaseTime, edition, disruptive));
+               }
+       }
+
+       private boolean disruptiveVersionBetweenCurrentAndFound(Properties properties) {
+               for (String key : properties.stringPropertyNames()) {
+                       if (key.startsWith("DisruptiveVersion/")) {
+                               Version disruptiveVersion = Version.parse(key.substring("DisruptiveVersion/".length()));
+                               if (disruptiveVersion.compareTo(currentRunningVersion) > 0) {
+                                       return true;
+                               }
+                       }
                }
+               return false;
        }
 
 }