Merge branch 'develop' into feature/JAL-3187linkedFeatures
[jalview.git] / getdown / src / getdown / core / src / main / java / com / threerings / getdown / util / LaunchUtil.java
index f2cd573..ae493bb 100644 (file)
@@ -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 + "...");