Check for updates on startup and in About Frame
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@156 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
9640e6ddc9
commit
a4ee02cae6
|
@ -1,11 +1,18 @@
|
|||
package davmail;
|
||||
|
||||
import davmail.http.DavGatewaySSLProtocolSocketFactory;
|
||||
import davmail.http.DavGatewayHttpClientFactory;
|
||||
import davmail.pop.PopServer;
|
||||
import davmail.smtp.SmtpServer;
|
||||
import davmail.tray.DavGatewayTray;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
|
||||
/**
|
||||
* DavGateway main class
|
||||
|
@ -52,8 +59,15 @@ public class DavGateway {
|
|||
smtpServer.start();
|
||||
popServer.start();
|
||||
|
||||
DavGatewayTray.info("DavMail gateway listening on SMTP port " + smtpPort +
|
||||
" and POP port " + popPort);
|
||||
String message = "DavMail gateway listening on SMTP port " + smtpPort +
|
||||
" and POP port " + popPort;
|
||||
String releasedVersion = getReleasedVersion();
|
||||
String currentVersion = getCurrentVersion();
|
||||
if (currentVersion != null && releasedVersion != null && currentVersion.compareTo(releasedVersion) < 0) {
|
||||
message += " A new version ("+releasedVersion+") of DavMail Gateway is available !";
|
||||
}
|
||||
|
||||
DavGatewayTray.info(message);
|
||||
} catch (IOException e) {
|
||||
DavGatewayTray.error("Exception creating server socket", e);
|
||||
}
|
||||
|
@ -81,4 +95,33 @@ public class DavGateway {
|
|||
}
|
||||
}
|
||||
|
||||
public static String getCurrentVersion() {
|
||||
Package davmailPackage = DavGateway.class.getPackage();
|
||||
return davmailPackage.getImplementationVersion();
|
||||
}
|
||||
|
||||
public static String getReleasedVersion() {
|
||||
String version = null;
|
||||
BufferedReader versionReader = null;
|
||||
try {
|
||||
HttpClient httpClient = DavGatewayHttpClientFactory.getInstance();
|
||||
GetMethod getMethod = new GetMethod("http://davmail.sourceforge.net/version.txt");
|
||||
int status = httpClient.executeMethod(getMethod);
|
||||
if (status == HttpStatus.SC_OK) {
|
||||
versionReader = new BufferedReader(new InputStreamReader(getMethod.getResponseBodyAsStream()));
|
||||
version = versionReader.readLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
} finally {
|
||||
if (versionReader != null) {
|
||||
try {
|
||||
versionReader.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package davmail.ui;
|
||||
|
||||
import davmail.tray.DavGatewayTray;
|
||||
import davmail.DavGateway;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.*;
|
||||
|
@ -35,16 +36,21 @@ public class AboutFrame extends JFrame {
|
|||
} catch (IOException e) {
|
||||
DavGatewayTray.error("Unable to create icon", e);
|
||||
}
|
||||
Package davmailPackage = this.getClass().getPackage();
|
||||
Package davmailPackage = DavGateway.class.getPackage();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
buffer.append("<html><b>DavMail Gateway</b><br>");
|
||||
String version = davmailPackage.getImplementationVersion();
|
||||
if (version != null) {
|
||||
buffer.append("<b>Version ").append(version).append("</b><br>");
|
||||
String currentVersion = davmailPackage.getImplementationVersion();
|
||||
if (currentVersion != null) {
|
||||
buffer.append("<b>Version ").append(currentVersion).append("</b><br>");
|
||||
}
|
||||
buffer.append("By Mickaël Guessant<br>" +
|
||||
"<br>" +
|
||||
"Help and setup instructions available at:<br>" +
|
||||
buffer.append("By Mickaël Guessant<br><br>");
|
||||
String releasedVersion = DavGateway.getReleasedVersion();
|
||||
if (currentVersion != null && releasedVersion != null && currentVersion.compareTo(releasedVersion) < 0) {
|
||||
buffer.append("<b>Latest version available ").append(releasedVersion).append("</b><br>" +
|
||||
"A new version of DavMail Gateway is available." +
|
||||
"<a href=\"http://sourceforge.net/project/platformdownload.php?group_id=184600\">Download latest version</a><br>");
|
||||
}
|
||||
buffer.append("Help and setup instructions available at:<br>" +
|
||||
"<a href=\"http://davmail.sourceforge.net\">http://davmail.sourceforge.net</a><br>" +
|
||||
"<br>" +
|
||||
"To send comments or report bugs, <br>use <a href=\"http://sourceforge.net/tracker/?group_id=184600\">" +
|
||||
|
@ -115,4 +121,6 @@ public class AboutFrame extends JFrame {
|
|||
getSize().height / 2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue