X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=getdown%2Fsrc%2Fgetdown%2Fcore%2Fsrc%2Fmain%2Fjava%2Fcom%2Fthreerings%2Fgetdown%2Futil%2FLaunchUtil.java;fp=getdown%2Fsrc%2Fgetdown%2Fcore%2Fsrc%2Fmain%2Fjava%2Fcom%2Fthreerings%2Fgetdown%2Futil%2FLaunchUtil.java;h=ae493bbe8db13a81e523e8760881409fc77e3ba9;hb=6a05eb3f55d97e685f0c723822384633d5636778;hp=f2cd5736e1c2d4298f4e159a6512ac979616c3ca;hpb=d113749a183a3ea8f3f7e22c725511f59f1d833f;p=jalview.git diff --git a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/LaunchUtil.java b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/LaunchUtil.java index f2cd573..ae493bb 100644 --- a/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/LaunchUtil.java +++ b/getdown/src/getdown/core/src/main/java/com/threerings/getdown/util/LaunchUtil.java @@ -9,8 +9,14 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.Locale; +import javax.xml.bind.DatatypeConverter; + +import java.security.MessageDigest; + import static com.threerings.getdown.Log.log; /** @@ -125,6 +131,21 @@ public class LaunchUtil return vmpath; } + private static String _getMD5FileChecksum (File file) { + // check md5 digest + String algo = "MD5"; + String checksum = ""; + try { + MessageDigest md = MessageDigest.getInstance(algo); + md.update(Files.readAllBytes(Paths.get(file.getAbsolutePath()))); + byte[] digest = md.digest(); + checksum = DatatypeConverter.printHexBinary(digest).toUpperCase(); + } catch (Exception e) { + System.out.println("Couldn't create "+algo+" digest of "+file.getPath()); + } + return checksum; + } + /** * Upgrades Getdown by moving an installation managed copy of the Getdown jar file over the * non-managed copy (which would be used to run Getdown itself). @@ -137,9 +158,17 @@ public class LaunchUtil // we assume getdown's jar file size changes with every upgrade, this is not guaranteed, // but in reality it will, and it allows us to avoid pointlessly upgrading getdown every // time the client is updated which is unnecessarily flirting with danger - if (!newgd.exists() || newgd.length() == curgd.length()) { + if (!newgd.exists()) + { return; } + + if (newgd.length() == curgd.length()) { + if (_getMD5FileChecksum(newgd).equals(_getMD5FileChecksum(curgd))) + { + return; + } + } log.info("Updating Getdown with " + newgd + "...");