From 380a1c1f29542a01f71304713e9c40ef829d88bb Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Fri, 10 Apr 2015 14:54:32 +0100 Subject: [PATCH] The ingame downloader now downloads the file as a .jar.dl file and renames it to a .jar when done to prevent loading of broken mods if any interruptions happen. --- .../common/core/version/ThreadDownloadMod.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/vazkii/botania/common/core/version/ThreadDownloadMod.java b/src/main/java/vazkii/botania/common/core/version/ThreadDownloadMod.java index 54c994429..5fd694aee 100644 --- a/src/main/java/vazkii/botania/common/core/version/ThreadDownloadMod.java +++ b/src/main/java/vazkii/botania/common/core/version/ThreadDownloadMod.java @@ -64,7 +64,7 @@ public class ThreadDownloadMod extends Thread { webReader = url.openStream(); File dir = new File(".", "mods"); - File f = new File(dir, fileName); + File f = new File(dir, fileName + ".dl"); f.createNewFile(); FileOutputStream outputStream = new FileOutputStream(f.getAbsolutePath()); @@ -74,15 +74,19 @@ public class ThreadDownloadMod extends Thread { buffer = new byte[10240]; totalBytesDownloaded += bytesJustDownloaded; } + outputStream.close(); + webReader.close(); + File f1 = new File(dir, fileName); + if(!f1.exists()) + f.renameTo(f1); + if(Minecraft.getMinecraft().thePlayer != null) Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentTranslation("botania.versioning.doneDownloading", fileName).setChatStyle(new ChatStyle().setColor(EnumChatFormatting.GREEN))); Desktop.getDesktop().open(dir); VersionChecker.downloadedFile = true; - - outputStream.close(); - webReader.close(); + finalize(); } catch(Throwable e) { e.printStackTrace();