Fix update check.
This commit is contained in:
parent
76280ac71c
commit
3225985e1e
@ -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>
|
||||||
|
@ -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,13 +49,20 @@ 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 )) {
|
|
||||||
|
String manifestRevision = attributes.getValue( Attributes.Name.IMPLEMENTATION_VERSION );
|
||||||
|
String upstreamRevisionURL = "http://masterpasswordapp.com/masterpassword-gui.jar.rev";
|
||||||
|
CharSource upstream = Resources.asCharSource( URI.create( upstreamRevisionURL ).toURL(), Charsets.UTF_8 );
|
||||||
|
String upstreamRevision = upstream.readFirstLine();
|
||||||
|
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"
|
logger.wrn( "You are not running the current official version. Please update from:\n"
|
||||||
+ "http://masterpasswordapp.com/masterpassword-gui.jar" );
|
+ "http://masterpasswordapp.com/masterpassword-gui.jar" );
|
||||||
JOptionPane.showMessageDialog( null, "A new version of Master Password is available.\n"
|
JOptionPane.showMessageDialog( null, "A new version of Master Password is available.\n"
|
||||||
@ -61,6 +70,7 @@ public class GUI implements UnlockFrame.SignInCallback {
|
|||||||
"Update Available", JOptionPane.WARNING_MESSAGE );
|
"Update Available", JOptionPane.WARNING_MESSAGE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
logger.wrn( e, "Couldn't check for version update." );
|
logger.wrn( e, "Couldn't check for version update." );
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user