diff --git a/src/java/com/threerings/resource/DownloadManager.java b/src/java/com/threerings/resource/DownloadManager.java index 94b6fa243..2af905c07 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.10 2003/08/05 23:34:01 mdb Exp $ +// $Id: DownloadManager.java,v 1.11 2003/08/08 17:45:00 mdb Exp $ package com.threerings.resource; @@ -133,7 +133,8 @@ public class DownloadManager if (protocol.equals("file")) { return new FileDownloader(); } else if (protocol.equals("http")) { - return new JNLPDownloader(); + return VERSIONING ? (Downloader)new JNLPDownloader() : + (Downloader)new HTTPDownloader(); } else { throw new IOException( "Unknown source file protocol " + @@ -276,21 +277,33 @@ public class DownloadManager } // now go through and do the post-download phase + IOException failure = null; + DownloadDescriptor fdesc = null; 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; - } + // we want to try to apply as many of the patches as we + // can, so we don't fail entirely here, just keep track of + // the last failure and report that when we're done + fdesc = loader.getDescriptor(); + failure = ioe; + Log.warning("Downloader failed in postDownload hook " + + "[desc=" + fdesc + "]."); + Log.logStackTrace(ioe); } } - // make sure to always let the observer know that we've wrapped up - // by reporting 100% completion - notifyProgress(obs, 100, 0L); + // if we had any failure, go ahead and report it now + if (failure != null) { + notifyFailed(obs, fdesc, failure); + + } else { + // make sure to always let the observer know that we've + // wrapped up by reporting 100% completion + notifyProgress(obs, 100, 0L); + } } /** Helper function. */ diff --git a/src/java/com/threerings/resource/HTTPDownloader.java b/src/java/com/threerings/resource/HTTPDownloader.java new file mode 100644 index 000000000..f04c7ff8a --- /dev/null +++ b/src/java/com/threerings/resource/HTTPDownloader.java @@ -0,0 +1,70 @@ +// +// $Id: HTTPDownloader.java,v 1.1 2003/08/08 17:45:00 mdb Exp $ + +package com.threerings.resource; + +import java.io.File; +import java.io.IOException; +import java.net.HttpURLConnection; + +import com.threerings.resource.DownloadManager.DownloadObserver; + +/** + * Downloads resources via HTTP using on last modification timestamps to + * determine whether updates are needed. + */ +public class HTTPDownloader extends Downloader +{ + // documentation inherited + public boolean checkUpdate (ProgressInfo info) + throws IOException + { + // read the file information via an HTTP HEAD request + HttpURLConnection ucon = (HttpURLConnection) + _desc.sourceURL.openConnection(); + ucon.setRequestMethod("HEAD"); + ucon.connect(); + + // make sure we got a satisfactory response code + if (ucon.getResponseCode() != HttpURLConnection.HTTP_OK) { + String errmsg = "Unable to check up-to-date for " + + _desc.sourceURL + ": " + ucon.getResponseCode(); + throw new IOException(errmsg); + } + + // read size and last modified information from the HEAD response + long fileSize = ucon.getContentLength(); + _desc.lastModified = ucon.getLastModified(); + + if (compareWithLocal(fileSize, _desc.lastModified)) { + // increment the total file size to be fetched + info.totalSize += fileSize; + Log.debug("Resource deemed stale [url=" + _desc.sourceURL + "]."); + return true; + } else { + Log.debug("Resource up-to-date [url=" + _desc.sourceURL + "]."); + return false; + } + } + + // documentation inherited + public void processDownload (DownloadManager dmgr, DownloadObserver obs, + ProgressInfo pinfo, byte[] buffer) + throws IOException + { + // download the resource bundle from the specified URL + HttpURLConnection ucon = (HttpURLConnection) + _desc.sourceURL.openConnection(); + ucon.connect(); + + // make sure we got a satisfactory response code + if (ucon.getResponseCode() != HttpURLConnection.HTTP_OK) { + String errmsg = "Unable to download update for " + + _desc.sourceURL + ": " + ucon.getResponseCode(); + throw new IOException(errmsg); + } + + Log.info("Downloading updated jar [url=" + _desc.sourceURL + "]."); + downloadContent(dmgr, obs, pinfo, buffer, ucon, _desc.destFile); + } +}