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);