File outputFile = null;
String requiredMinecraftVersion = build.getMinecraftVersion();
while (tries > 0) {
Util.logi("Starting download of minecraft, with %s trie(s) remaining", tries);
tries--;
Download download = new Download(build.getMinecraftURL(user), output);
download.setListener(listener);
download.run();
if (!download.isSuccess()) {
if (download.getOutFile() != null) {
download.getOutFile().delete();
}
System.err.println("Download of minecraft failed!");
listener.stateChanged("Download Failed, retries remaining: " + tries, 0F);
} else {
// String minecraftMD5 = MD5Utils.getMD5(FileType.minecraft,
// build.getLatestMinecraftVersion());
String resultMD5 = MD5Utils.getMD5(download.getOutFile());
String minecraftVersion = MD5Utils.getMinecraftMD5(resultMD5);
if (minecraftVersion != null) {
Util.log("Downloaded 'minecraft.jar' matches MD5 of version '%s'.", minecraftVersion);
} else {
Util.log("Downloaded 'minecraft.jar' does not matche MD5 of any known minecraft version!");
continue;
}
// Util.log("Expected MD5: " + minecraftMD5 + " Result MD5: " +
// resultMD5);
//
// if (!resultMD5.equals(minecraftMD5)) {
// continue;
// }
if (!minecraftVersion.equals(requiredMinecraftVersion)) {
File patch = new File(GameUpdater.tempDir, "mc.patch");
String patchURL = build.getPatchURL(minecraftVersion, requiredMinecraftVersion);
Download patchDownload = DownloadUtils.downloadFile(patchURL, patch.getPath(), null, null, listener);
if (patchDownload.isSuccess()) {
File patchedMinecraft = new File(GameUpdater.tempDir, "patched_minecraft.jar");
patchedMinecraft.delete();
listener.stateChanged(String.format("Patching Minecraft to '%s'.", requiredMinecraftVersion), 0F);
JBPatch.bspatch(download.getOutFile(), patchedMinecraft, patch);
listener.stateChanged(String.format("Patched Minecraft to '%s'.", requiredMinecraftVersion), 100F);