From 00b983ccf71b8d0c6b3e0fab0832d29faf6446f6 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 5 Aug 2003 07:03:34 +0000 Subject: [PATCH] Break the patching out into a separate phase, clean up the diff and old jar files when we're done patching. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2741 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/resource/DownloadManager.java | 16 +++++++++++- .../com/threerings/resource/Downloader.java | 13 +++++++++- .../threerings/resource/JNLPDownloader.java | 25 +++++++++++++------ 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/src/java/com/threerings/resource/DownloadManager.java b/src/java/com/threerings/resource/DownloadManager.java index d3a9b53de..64fdc9352 100644 --- a/src/java/com/threerings/resource/DownloadManager.java +++ b/src/java/com/threerings/resource/DownloadManager.java @@ -1,5 +1,5 @@ // -// $Id: DownloadManager.java,v 1.8 2003/08/05 01:33:20 mdb Exp $ +// $Id: DownloadManager.java,v 1.9 2003/08/05 07:03:33 mdb Exp $ package com.threerings.resource; @@ -257,6 +257,7 @@ public class DownloadManager } Log.info("Initiating download of " + pinfo.totalSize + " bytes."); + // download all stale files size = fetch.size(); pinfo.start = System.currentTimeMillis(); @@ -272,6 +273,19 @@ public class DownloadManager } } + // now go through and do the post-download phase + for (int ii = 0; ii < size; ii++) { + Downloader loader = (Downloader)fetch.get(ii); + try { + loader.postDownload(this, obs, pinfo); + } catch (IOException ioe) { + notifyFailed(obs, loader.getDescriptor(), ioe); + if (fragile) { + return; + } + } + } + // make sure to always let the observer know that we've wrapped up // by reporting 100% completion notifyProgress(obs, 100, 0L); diff --git a/src/java/com/threerings/resource/Downloader.java b/src/java/com/threerings/resource/Downloader.java index 3040f17ec..1b090c158 100644 --- a/src/java/com/threerings/resource/Downloader.java +++ b/src/java/com/threerings/resource/Downloader.java @@ -1,5 +1,5 @@ // -// $Id: Downloader.java,v 1.1 2003/08/05 01:33:20 mdb Exp $ +// $Id: Downloader.java,v 1.2 2003/08/05 07:03:34 mdb Exp $ package com.threerings.resource; @@ -87,6 +87,17 @@ public abstract class Downloader } } + /** + * Called after the download phase has completed to allow patching or + * other post-download activities. + */ + public void postDownload (DownloadManager dmgr, DownloadObserver obs, + ProgressInfo pinfo) + throws IOException + { + // nothing to do by default + } + /** * Downloads the content from the supplied URL connection into the * specified destination file, informing the supplied download manager diff --git a/src/java/com/threerings/resource/JNLPDownloader.java b/src/java/com/threerings/resource/JNLPDownloader.java index 4d3a8c92e..c48e02ec5 100644 --- a/src/java/com/threerings/resource/JNLPDownloader.java +++ b/src/java/com/threerings/resource/JNLPDownloader.java @@ -1,5 +1,5 @@ // -// $Id: JNLPDownloader.java,v 1.2 2003/08/05 06:54:01 mdb Exp $ +// $Id: JNLPDownloader.java,v 1.3 2003/08/05 07:03:34 mdb Exp $ package com.threerings.resource; @@ -89,9 +89,7 @@ public class JNLPDownloader extends Downloader return true; } - /** - * Processes a single download descriptor. - */ + // documentation inherited public void processDownload (DownloadManager dmgr, DownloadObserver obs, ProgressInfo pinfo, byte[] buffer) throws IOException @@ -115,6 +113,18 @@ public class JNLPDownloader extends Downloader _patchFile = new File(mungePath(_desc.destFile, ".diff")); downloadContent(dmgr, obs, pinfo, buffer, ucon, _patchFile); + } else { + Log.info("Downloading whole jar [url=" + rsrcURL + "]."); + downloadContent(dmgr, obs, pinfo, buffer, ucon, _desc.destFile); + } + } + + // documentation inherited + public void postDownload (DownloadManager dmgr, DownloadObserver obs, + ProgressInfo pinfo) + throws IOException + { + if (_patchFile != null) { // move the old jar out of the way File oldDest = new File(_desc.destFile.getPath() + ".old"); if (!_desc.destFile.renameTo(oldDest)) { @@ -150,12 +160,11 @@ public class JNLPDownloader extends Downloader cleanUpAndFail(ioe); } - } else { - Log.info("Downloading whole jar [url=" + rsrcURL + "]."); - downloadContent(dmgr, obs, pinfo, buffer, ucon, _desc.destFile); + // clean up the old jar and the patch file + oldDest.delete(); + _patchFile.delete(); } - // now that we've patched, update our version file PrintWriter pout = new PrintWriter( new BufferedWriter(new FileWriter(_vfile))); pout.println(_desc.version);