Author: jflesch
Date: 2007-08-27 17:01:55 +0000 (Mon, 27 Aug 2007)
New Revision: 14890

Modified:
   trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
   trunk/apps/Thaw/src/thaw/i18n/thaw.properties
   trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java
   trunk/apps/Thaw/src/thaw/plugins/index/Index.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java
Log:
Try to warn the user of new versions of Thaw thanks to the index 'Thaw'

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-08-27 
15:20:48 UTC (rev 14889)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-08-27 
17:01:55 UTC (rev 14890)
@@ -411,6 +411,10 @@

 thaw.plugin.index.recentlyAdded=R?cemment ajout?s

+thaw.plugins.index.newThawVersion=Une nouvelle version de Thaw est disponible 
: X
+
+
+
 # Peer monitor

 thaw.plugin.peerMonitor.peerMonitor=Connexion

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-08-27 15:20:48 UTC 
(rev 14889)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-08-27 17:01:55 UTC 
(rev 14890)
@@ -422,6 +422,7 @@
 thaw.plugin.index.autoSortFolderAction=Sort the indexes according to their 
categories
 thaw.plugin.index.recentlyAdded=Recently added

+thaw.plugins.index.newThawVersion=New version of Thaw available: X


 # Peer monitor

Modified: trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java  2007-08-27 15:20:48 UTC 
(rev 14889)
+++ trunk/apps/Thaw/src/thaw/plugins/IndexBrowser.java  2007-08-27 17:01:55 UTC 
(rev 14890)
@@ -19,16 +19,19 @@

 public class IndexBrowser extends ToolbarModifier implements Plugin, 
ChangeListener {

+       /**
+        * Thaw index is always specified first
+        */
        public static final String[] DEFAULT_INDEXES = new String[] {
+               /* Thaw index */
+               "USK at p-uFAWUomLm37MCQLu3r67-B8e6yF1kS4q2v0liM1Vk,"+
+               "h0MWqM~lF0Bec-AIv445PLn06ams9-RFbnwO6Cm2Snc,AQACAAE"+
+               "/Thaw/2/Thaw.frdx",
+
                /* publicly writable index */
                "USK at 61m2WMJEA9pyQQQ-hjGN8lIM2xToNJHyacJ8ZPB9JCQ,"+
                "5aEPJBhwIV~HpGIG8YTpKSB39WCGgd0BUNWZ012745Y,AQACAAE"+
-               "/Publicly%20writable%20index/35/Publicly writable index.frdx",
-
-               /* Thaw index */
-               "USK at p-uFAWUomLm37MCQLu3r67-B8e6yF1kS4q2v0liM1Vk,"+
-               "h0MWqM~lF0Bec-AIv445PLn06ams9-RFbnwO6Cm2Snc,AQACAAE"+
-               "/Thaw/2/Thaw.frdx"
+               "/Publicly%20writable%20index/35/Publicly writable index.frdx"
        };

        private Core core;

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-08-27 15:20:48 UTC 
(rev 14889)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-08-27 17:01:55 UTC 
(rev 14890)
@@ -815,7 +815,8 @@

                boolean v = realDownloadFromFreenet(specificRev);

-               this.addObserver(o);
+               if (o != null)
+                       this.addObserver(o);

                return (v ? 1 : 0);
        }
@@ -1992,4 +1993,69 @@
        public boolean downloadSuccessful() {
                return successful;
        }
+
+
+       public void setClientVersion(String str) {
+               /* only used if it's the Thaw index who was updated */
+
+               final String thawIndexPart = 
FreenetURIHelper.getComparablePart(thaw.plugins.IndexBrowser.DEFAULT_INDEXES[0]);
+               final String thisIndexPart = 
FreenetURIHelper.getComparablePart(getPublicKey());
+
+
+               if (!thawIndexPart.equals(thisIndexPart))
+                       return;
+
+               try {
+                       if (!str.startsWith("Thaw ")) { /* not made with Thaw 
?! */
+                               Logger.notice(this, "Can't parse the Thaw 
version in the index '"+toString(false)+"' ?!");
+                               return;
+                       }
+
+                       str = str.substring(5);
+
+                       int spacePos = -1;
+
+                       if ( (spacePos = str.indexOf(" ")) < 0) { /* hu ? */
+                               Logger.notice(this, "Can't parse the Thaw 
version in the index '"+toString(false)+"' ?!");
+                               return;
+                       }
+
+                       str = str.substring(0, spacePos);
+
+                       String[] numbers = str.split("\\.");
+                       int major  = Integer.parseInt(numbers[0]);
+                       int minor  = Integer.parseInt(numbers[1]);
+                       int update = Integer.parseInt(numbers[2]);
+
+                       boolean mustPopup = false;
+
+                       if (major > Main._major)
+                               mustPopup = true;
+
+                       else if (major == Main._major) {
+
+                               if (minor > Main._minor)
+                                       mustPopup = true;
+                               else if (update > Main._update)
+                                       mustPopup = true;
+
+                       }
+
+
+                       if (mustPopup) {
+                               String newVersion =
+                                       Integer.toString(major)+"."+
+                                       Integer.toString(minor)+"."+
+                                       Integer.toString(update);
+
+                               /* quick and dirty way to warn the user */
+                               Logger.warning(this, 
I18n.getMessage("thaw.plugins.index.newThawVersion").replaceAll("X", 
newVersion));
+                       }
+
+               } catch(Exception e) {
+                       Logger.notice(this, "Unable to parse the client string 
of the index '"+toString(false)+
+                                     "' because : "+e.toString());
+                       e.printStackTrace();
+               }
+       }
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java  2007-08-27 
15:20:48 UTC (rev 14889)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java  2007-08-27 
17:01:55 UTC (rev 14890)
@@ -74,4 +74,6 @@

        public void setCategory(String str);
        public String getCategory();
+
+       public void setClientVersion(String str);
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java     2007-08-27 
15:20:48 UTC (rev 14889)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java     2007-08-27 
17:01:55 UTC (rev 14890)
@@ -338,8 +338,8 @@
                private boolean dateTag = false;
                private boolean commentsTag = false;
                private boolean categoryTag = false;
-
                private boolean hasCommentTag = false;
+               private boolean clientTag = false;

                private String dateStr = null;
                private String categoryStr = null;
@@ -368,41 +368,28 @@
                        if ("owner".equals(rawName)) {
                                ownerTag = true;
                                return;
-                       }
-
-                       if ("privateKey".equals(rawName)) {
+                       } else if ("privateKey".equals(rawName)) {
                                privateKeyTag = true;
                                return;
-                       }
-
-                       if ("date".equals(rawName)) {
+                       } else if ("date".equals(rawName)) {
                                dateTag = true;
                                return;
-                       }
-
-                       if ("category".equals(rawName)) {
+                       } else if ("category".equals(rawName)) {
                                categoryTag = true;
                                return;
-                       }
+                       } else if ("link".equals(rawName)
+                                  || "index".equals(rawName)) { /* links */

-                       if ("link".equals(rawName)
-                           || "index".equals(rawName)) { /* links */
-
                                index.addLink(attrs.getValue("key"));

                                return;
-                       }
+                       } else if ("file".equals(rawName)) {

-                       if ("file".equals(rawName)) {
-
                                index.addFile(attrs.getValue("key"),
                                              
Long.parseLong(attrs.getValue("size")),
                                              attrs.getValue("mime"));

-                       }
-
-
-                       if ("comments".equals(rawName)) {
+                       } else if ("comments".equals(rawName)) {
                                String pub = attrs.getValue("publicKey");
                                String priv = attrs.getValue("privateKey");

@@ -412,10 +399,13 @@
                                        Logger.debug(this, "Comment allowed in 
this index");
                                        index.setCommentKeys(pub, priv);
                                }
-                       }

+                       } else if ("client".equals(rawName)) {

-                       if ("blackListed".equals(rawName)) {
+                               clientTag = true;
+                               return;
+
+                       } else if ("blackListed".equals(rawName)) {
                                int blRev;

                                blRev = Integer.parseInt(attrs.getValue("rev"));
@@ -448,24 +438,16 @@
                        if ("owner".equals(rawName)) {
                                ownerTag = false;
                                return;
-                       }
-
-                       if ("privateKey".equals(rawName)) {
+                       } else if ("privateKey".equals(rawName)) {
                                privateKeyTag = false;
                                return;
-                       }
-
-                       if ("date".equals(rawName)) {
+                       } else if ("date".equals(rawName)) {
                                dateTag = false;
                                return;
-                       }
-
-                       if ("category".equals(rawName)) {
+                       } else if ("category".equals(rawName)) {
                                categoryTag = false;
                                return;
-                       }
-
-                       if ("header".equals(rawName)) {
+                       } else if ("header".equals(rawName)) {
                                if (dateStr != null) {
                                        java.text.SimpleDateFormat sdf =
                                                new 
java.text.SimpleDateFormat(DATE_FORMAT);
@@ -476,11 +458,12 @@

                                if (categoryStr != null)
                                        index.setCategory(categoryStr);
-                       }
-
-                       if ("comments".equals(rawName)) {
+                       } else if ("comments".equals(rawName)) {
                                commentsTag = false;
                                return;
+                       } else if ("client".equals(rawName)) {
+                               clientTag = false;
+                               return;
                        }
                }

@@ -509,6 +492,10 @@
                                categoryStr = txt;
                        }

+                       if (clientTag) {
+                               index.setClientVersion(txt);
+                       }
+
                        if (privateKeyTag) {
                                if (index.getPrivateKey() == null
                                    || 
index.getPrivateKey().trim().equals(txt.trim())) {


Reply via email to