2
0

Fix update check.

This commit is contained in:
Maarten Billemont 2014-08-28 00:07:24 -04:00
parent 76280ac71c
commit 3225985e1e
2 changed files with 25 additions and 15 deletions

View File

@ -48,7 +48,7 @@
<configuration> <configuration>
<archive> <archive>
<manifestEntries> <manifestEntries>
<SCM-Revision>${buildNumber}</SCM-Revision> <Implementation-Version>${buildNumber}</Implementation-Version>
</manifestEntries> </manifestEntries>
</archive> </archive>
</configuration> </configuration>

View File

@ -18,8 +18,7 @@
package com.lyndir.masterpassword; package com.lyndir.masterpassword;
import com.google.common.base.Charsets; import com.google.common.base.Charsets;
import com.google.common.io.ByteStreams; import com.google.common.io.*;
import com.google.common.io.CharStreams;
import com.lyndir.lhunath.opal.system.CodeUtils; import com.lyndir.lhunath.opal.system.CodeUtils;
import com.lyndir.lhunath.opal.system.MessageDigests; import com.lyndir.lhunath.opal.system.MessageDigests;
import com.lyndir.lhunath.opal.system.logging.Logger; import com.lyndir.lhunath.opal.system.logging.Logger;
@ -27,6 +26,9 @@ import com.lyndir.lhunath.opal.system.util.TypeUtils;
import java.io.*; import java.io.*;
import java.net.URI; import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.*;
import javax.swing.*; import javax.swing.*;
@ -47,18 +49,26 @@ public class GUI implements UnlockFrame.SignInCallback {
throws IOException { throws IOException {
try { try {
byte[] manifest = ByteStreams.toByteArray( GUI.class.getClassLoader().getResourceAsStream( "META-INF/MANIFEST.MF" ) ); Enumeration<URL> manifestURLs = Thread.currentThread().getContextClassLoader().getResources( JarFile.MANIFEST_NAME );
String manifestHash = CodeUtils.encodeHex( CodeUtils.digest( MessageDigests.SHA1, manifest ) ); while (manifestURLs.hasMoreElements()) {
InputStream upstream = URI.create( "http://masterpasswordapp.com/masterpassword-gui.jar.mf.sha1" ).toURL().openStream(); InputStream manifestStream = manifestURLs.nextElement().openStream();
String upstreamHash = CharStreams.toString( new InputStreamReader( upstream, Charsets.UTF_8 ) ); Attributes attributes = new Manifest( manifestStream ).getMainAttributes();
logger.inf( "Local Manifest Hash: %s", manifestHash ); if (!GUI.class.getCanonicalName().equals( attributes.getValue( Attributes.Name.MAIN_CLASS ) ))
logger.inf( "Upstream Manifest Hash: %s", upstreamHash ); continue;
if (!manifestHash.equalsIgnoreCase( upstreamHash )) {
logger.wrn( "You are not running the current official version. Please update from:\n" String manifestRevision = attributes.getValue( Attributes.Name.IMPLEMENTATION_VERSION );
+ "http://masterpasswordapp.com/masterpassword-gui.jar" ); String upstreamRevisionURL = "http://masterpasswordapp.com/masterpassword-gui.jar.rev";
JOptionPane.showMessageDialog( null, "A new version of Master Password is available.\n" CharSource upstream = Resources.asCharSource( URI.create( upstreamRevisionURL ).toURL(), Charsets.UTF_8 );
+ "Please download the latest version from http://masterpasswordapp.com", String upstreamRevision = upstream.readFirstLine();
"Update Available", JOptionPane.WARNING_MESSAGE ); logger.inf( "Local Revision: <%s>", manifestRevision );
logger.inf( "Upstream Revision: <%s>", upstreamRevision );
if (!manifestRevision.equalsIgnoreCase( upstreamRevision )) {
logger.wrn( "You are not running the current official version. Please update from:\n"
+ "http://masterpasswordapp.com/masterpassword-gui.jar" );
JOptionPane.showMessageDialog( null, "A new version of Master Password is available.\n"
+ "Please download the latest version from http://masterpasswordapp.com",
"Update Available", JOptionPane.WARNING_MESSAGE );
}
} }
} }
catch (IOException e) { catch (IOException e) {