From 9f61ba8d4339278ee2f7a3ab065593da9153dc68 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Tue, 18 Mar 2008 13:12:33 +0000 Subject: [PATCH] UpdateCheck now look for last version from properties file located on download site --- build.xml | 5 +- resources/config/updatecheck.properties | 1 - resources/install/build.xml | 20 ++++ .../plugin/updatechecker/resources.properties | 3 +- .../updatechecker/UpdateCheckActivator.java | 101 +++++++----------- 5 files changed, 61 insertions(+), 69 deletions(-) diff --git a/build.xml b/build.xml index 90359c9dc..eae30c3b4 100644 --- a/build.xml +++ b/build.xml @@ -345,7 +345,7 @@ - + @@ -616,7 +616,8 @@ bundle-pluginmanager,bundle-notification, bundle-ssh,bundle-plugin-sshaccregwizz, bundle-contacteventhandler,bundle-plugin-contactinfo, - bundle-plugin-accountinfo,bundle-plugin-chatalerter"/> + bundle-plugin-accountinfo,bundle-plugin-chatalerter, + bundle-updatecheckplugin"/> diff --git a/resources/config/updatecheck.properties b/resources/config/updatecheck.properties index 197d1fe51..d255b1331 100644 --- a/resources/config/updatecheck.properties +++ b/resources/config/updatecheck.properties @@ -1,2 +1 @@ destinationPath=http://download.sip-communicator.org/nightly -pkgName=sip-communicator \ No newline at end of file diff --git a/resources/install/build.xml b/resources/install/build.xml index e81a431b3..a59f0e76f 100644 --- a/resources/install/build.xml +++ b/resources/install/build.xml @@ -143,6 +143,11 @@ + + + + @@ -216,6 +221,13 @@ + + + + + @@ -398,6 +410,14 @@ + + + + + + There is new version of {0}
you can download it at :
\ No newline at end of file +dialogMessage1=There is new version of {0} ! +dialogMessage2=
You can download it at :
diff --git a/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java b/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java index 7670e7f81..8d09081e3 100644 --- a/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java +++ b/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java @@ -43,6 +43,8 @@ public class UpdateCheckActivator private static BundleContext bundleContext = null; private static BrowserLauncherService browserLauncherService; + + private String downloadLink = null; /** * Starts this bundle @@ -82,12 +84,19 @@ public void start(BundleContext bundleContext) throws Exception contentMessage.setContentType("text/html"); contentMessage.setOpaque(false); contentMessage.setEditable(false); - contentMessage.setText( - MessageFormat.format( - Resources.getLangString("dialogMessage"), - ver.getApplicationName()) + - "" + - Resources.getConfigString("destinationPath") + " "); + + String dialogMsg = MessageFormat.format( + Resources.getLangString("dialogMessage1"), + ver.getApplicationName()); + + if(downloadLink != null) + { + dialogMsg += Resources.getLangString("dialogMessage2") + + "" + + downloadLink + " "; + } + + contentMessage.setText(dialogMsg); contentMessage.addHyperlinkListener(new HyperlinkListener() { @@ -167,72 +176,34 @@ public static BrowserLauncherService getBrowserLauncher() */ private boolean isNewestVersion(String currentVersionStr) { - String pkgName = Resources.getConfigString("pkgName") + "-"; - - EditorKit kit = new HTMLEditorKit(); - Document doc = kit.createDefaultDocument(); - - // The Document class does not yet - // handle charset's properly. - doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE); - try + try { - // as some of the distribution has own mechanisums of - // updating so just check from one of the platforms - // which is the last version + String osName = System.getProperty("os.name"); + String osDir = null; - // Create a reader on the HTML content. - Reader rd = getReader(Resources.getConfigString("destinationPath") + "/windows"); - - // Parse the HTML. - kit.read(rd, doc, 0); - - // Iterate through the elements - // of the HTML document. - ElementIterator it = new ElementIterator(doc); - Element elem; - while ((elem = it.next()) != null) - { - SimpleAttributeSet s = (SimpleAttributeSet) - elem.getAttributes().getAttribute(HTML.Tag.A); - if (s != null) - { - String link = s.getAttribute(HTML.Attribute.HREF).toString(); - - if(!link.startsWith(pkgName)) - continue; - - link = link.replaceAll(pkgName, ""); - - link = link.substring(0, link.lastIndexOf('.')); - - return link.compareTo(currentVersionStr) <= 0; - } - } + if (osName.startsWith("Mac")) + osDir = "/macosx"; + else if (osName.startsWith("Linux")) + osDir = "/linux"; + else if (osName.startsWith("Windows")) + osDir = "/windows"; + + URL url = new URL(Resources.getConfigString("destinationPath") + + osDir + "/versionupdate.properties"); + + Properties props = new Properties(); + props.load(url.openStream()); + + String lastVersion = props.getProperty("last_version"); + downloadLink = props.getProperty("download_link"); + + return lastVersion.compareTo(currentVersionStr) <= 0; } catch (Exception e) { - e.printStackTrace(); + logger.error("Cannot get and compare versions!", e); } return false; } - - // Returns a reader on the HTML data. If 'uri' begins - // with "http:", it's treated as a URL; otherwise, - // it's assumed to be a local filename. - static Reader getReader(String uri) - throws IOException - { - if (uri.startsWith("http:")) - { - // Retrieve from Internet. - URLConnection conn = new URL(uri).openConnection(); - return new InputStreamReader(conn.getInputStream()); - } - else - { - return new FileReader(uri); - } - } } \ No newline at end of file