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;
/**
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).
// 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 + "...");