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