Better way of checking implementation-version.
This commit is contained in:
parent
954c4f8d63
commit
e5ff374a9c
@ -30,9 +30,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.net.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Optional;
|
||||
import java.util.jar.*;
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
@ -85,15 +83,8 @@ public class GUI implements UnlockFrame.SignInCallback {
|
||||
|
||||
private static void checkUpdate() {
|
||||
try {
|
||||
Enumeration<URL> manifestURLs = Thread.currentThread().getContextClassLoader().getResources( JarFile.MANIFEST_NAME );
|
||||
while (manifestURLs.hasMoreElements())
|
||||
try (InputStream manifestStream = manifestURLs.nextElement().openStream()) {
|
||||
Attributes attributes = new Manifest( manifestStream ).getMainAttributes();
|
||||
if (!GUI.class.getCanonicalName().equals( attributes.getValue( Attributes.Name.MAIN_CLASS ) ))
|
||||
continue;
|
||||
|
||||
String manifestRevision = attributes.getValue( Attributes.Name.IMPLEMENTATION_VERSION );
|
||||
String upstreamRevision = new ByteSource() {
|
||||
String implementationVersion = GUI.class.getPackage().getImplementationVersion();
|
||||
String latestVersion = new ByteSource() {
|
||||
@Override
|
||||
public InputStream openStream()
|
||||
throws IOException {
|
||||
@ -104,27 +95,23 @@ public class GUI implements UnlockFrame.SignInCallback {
|
||||
}
|
||||
}.asCharSource( Charsets.UTF_8 ).readFirstLine();
|
||||
|
||||
if ((manifestRevision != null) && (upstreamRevision != null) && !manifestRevision.equalsIgnoreCase(
|
||||
upstreamRevision )) {
|
||||
logger.inf( "Local Revision: <%s>", manifestRevision );
|
||||
logger.inf( "Upstream Revision: <%s>", upstreamRevision );
|
||||
if ((implementationVersion != null) && (latestVersion != null) &&
|
||||
!implementationVersion.equalsIgnoreCase( latestVersion )) {
|
||||
logger.inf( "Implementation: <%s>", implementationVersion );
|
||||
logger.inf( "Latest : <%s>", latestVersion );
|
||||
logger.wrn( "You are not running the current official version. Please update from:%n%s",
|
||||
"https://masterpassword.app/masterpassword-gui.jar" );
|
||||
JOptionPane.showMessageDialog( null,
|
||||
strf( "A new version of Master Password is available.%n "
|
||||
+ "Please download the latest version from %s",
|
||||
"https://masterpassword.app" ),
|
||||
"Update Available", JOptionPane.WARNING_MESSAGE );
|
||||
"Update Available", JOptionPane.INFORMATION_MESSAGE );
|
||||
}
|
||||
}
|
||||
catch (final IOException e) {
|
||||
logger.wrn( e, "Couldn't check for version update." );
|
||||
}
|
||||
}
|
||||
catch (final IOException e) {
|
||||
logger.wrn( e, "Couldn't inspect JAR." );
|
||||
}
|
||||
}
|
||||
|
||||
protected void open() {
|
||||
SwingUtilities.invokeLater( () -> {
|
||||
|
Loading…
Reference in New Issue
Block a user