Merge commit '7ce18848c8327967ce27b90abf2e280953530b5f'
[nikiroo-utils.git] / src / be / nikiroo / fanfix / Main.java
index b49cf0fb13e38338c293166027882e3df3876e67..c0dd9e0db608b4b8c4394821d63c783926150251 100644 (file)
@@ -28,6 +28,7 @@ import be.nikiroo.fanfix.supported.BasicSupport;
 import be.nikiroo.fanfix.supported.SupportType;
 import be.nikiroo.utils.Progress;
 import be.nikiroo.utils.Version;
+import be.nikiroo.utils.VersionCheck;
 import be.nikiroo.utils.serial.server.ServerObject;
 
 /**
@@ -126,6 +127,9 @@ public class Main {
 
                int exitCode = 0;
                for (int i = 0; exitCode == 0 && i < args.length; i++) {
+                       if (args[i] == null)
+                               continue;
+
                        // Action (--) handling:
                        if (!noMoreActions && args[i].startsWith("--")) {
                                if (args[i].equals("--")) {
@@ -394,8 +398,10 @@ public class Main {
                if (exitCode == 0) {
                        switch (action) {
                        case IMPORT:
-                               if (updates != null)
-                                       updates.ok(); // we consider it read
+                               if (updates != null) {
+                                       // we consider it read
+                                       Instance.getInstance().setVersionChecked(); 
+                               }
                                
                                try {
                                        exitCode = imprt(BasicReader.getUrl(urlString), pg);
@@ -406,8 +412,10 @@ public class Main {
                                
                                break;
                        case EXPORT:
-                               if (updates != null)
-                                       updates.ok(); // we consider it read
+                               if (updates != null) {
+                                       // we consider it read
+                                       Instance.getInstance().setVersionChecked(); 
+                               }
                                
                                OutputType exportType = OutputType.valueOfNullOkUC(sourceString, null);
                                if (exportType == null) {
@@ -420,8 +428,10 @@ public class Main {
                                
                                break;
                        case CONVERT:
-                               if (updates != null)
-                                       updates.ok(); // we consider it read
+                               if (updates != null) {
+                                       // we consider it read
+                                       Instance.getInstance().setVersionChecked(); 
+                               }
                                
                                OutputType convertType = OutputType.valueOfAllOkUC(sourceString, null);
                                if (convertType == null) {
@@ -596,8 +606,10 @@ public class Main {
                                exitCode = 0;
                                break;
                        case VERSION:
-                               if (updates != null)
-                                       updates.ok(); // we consider it read
+                               if (updates != null) {
+                                       // we consider it read
+                                       Instance.getInstance().setVersionChecked(); 
+                               }
                                
                                System.out
                                                .println(String.format("Fanfix version %s"
@@ -687,10 +699,13 @@ public class Main {
        }
 
        /**
-        * Will check if updates are available.
+        * Will check if updates are available, synchronously.
         * <p>
         * For this, it will simply forward the call to
         * {@link Main#checkUpdates(String)} with a value of "nikiroo/fanfix".
+        * <p>
+        * You may want to override it so you call the forward method with the right
+        * parameters (or also if you want it to be asynchronous).
         * 
         * @return the newer version information or NULL if nothing new
         */
@@ -710,12 +725,17 @@ public class Main {
         * @return the newer version information or NULL if nothing new
         */
        protected VersionCheck checkUpdates(String githubProject) {
-               VersionCheck updates = VersionCheck.check(githubProject);
-               if (updates.isNewVersionAvailable()) {
-                       notifyUpdates(updates);
-                       return updates;
+               try {
+                       VersionCheck updates = VersionCheck.check(githubProject,
+                                       Instance.getInstance().getTrans().getLocale());
+                       if (updates.isNewVersionAvailable()) {
+                               notifyUpdates(updates);
+                               return updates;
+                       }
+               } catch (IOException e) {
+                       // Maybe no internet. Do not report any update.
                }
-               
+
                return null;
        }
 
@@ -724,9 +744,9 @@ public class Main {
         * <p>
         * Will only be called when a version is available.
         * <p>
-        * Note that you can call {@link VersionCheck#ok()} on it if the user has
-        * read the information (by default, it is marked read only on certain other
-        * actions).
+        * Note that you can call {@link Instance#setVersionChecked()} on it if the
+        * user has read the information (by default, it is marked read only on
+        * certain other actions).
         * 
         * @param updates
         *            the new version information