Try to fix auto update

This commit is contained in:
huangyuhui 2017-02-24 19:22:06 +08:00
parent 17eca9dd2f
commit 4b435d4ac3
2 changed files with 7 additions and 2 deletions

View File

@ -161,15 +161,19 @@ public class AppDataUpgrader extends IUpgrader {
@Override @Override
public void executeTask(boolean areDependTasksSucceeded) throws Exception { public void executeTask(boolean areDependTasksSucceeded) throws Exception {
if (!areDependTasksSucceeded) {
tempFile.delete();
return;
}
HashMap<String, String> json = new HashMap<>(); HashMap<String, String> json = new HashMap<>();
File f = getSelf(newestVersion); File f = getSelf(newestVersion);
if (!FileUtils.makeDirectory(f.getParentFile())) if (!FileUtils.makeDirectory(f.getParentFile()))
HMCLog.warn("Failed to make directories: " + f.getParent()); throw new IOException("Failed to make directories: " + f.getParent());
for (int i = 0; f.exists(); i++) for (int i = 0; f.exists(); i++)
f = new File(BASE_FOLDER, "HMCL-" + newestVersion + (i > 0 ? "-" + i : "") + ".jar"); f = new File(BASE_FOLDER, "HMCL-" + newestVersion + (i > 0 ? "-" + i : "") + ".jar");
if (!f.createNewFile()) if (!f.createNewFile())
HMCLog.warn("Failed to create new file: " + f); throw new IOException("Failed to create new file: " + f);
try (JarOutputStream jos = new JarOutputStream(FileUtils.openOutputStream(f))) { try (JarOutputStream jos = new JarOutputStream(FileUtils.openOutputStream(f))) {
Pack200.newUnpacker().unpack(new GZIPInputStream(FileUtils.openInputStream(tempFile)), jos); Pack200.newUnpacker().unpack(new GZIPInputStream(FileUtils.openInputStream(tempFile)), jos);

View File

@ -212,6 +212,7 @@ public class FileDownloadTask extends Task implements PreviousResult<File>, Prev
ppl.onProgressProviderDone(this); ppl.onProgressProviderDone(this);
return; return;
} catch (IOException | IllegalStateException e) { } catch (IOException | IllegalStateException e) {
filePath.delete();
setFailReason(new IOException(C.i18n("download.failed") + " " + url, e)); setFailReason(new IOException(C.i18n("download.failed") + " " + url, e));
} finally { } finally {
closeFiles(); closeFiles();