Use a downloader that checks timestamps if we're not doing versioning.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2747 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -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;
|
package com.threerings.resource;
|
||||||
|
|
||||||
@@ -133,7 +133,8 @@ public class DownloadManager
|
|||||||
if (protocol.equals("file")) {
|
if (protocol.equals("file")) {
|
||||||
return new FileDownloader();
|
return new FileDownloader();
|
||||||
} else if (protocol.equals("http")) {
|
} else if (protocol.equals("http")) {
|
||||||
return new JNLPDownloader();
|
return VERSIONING ? (Downloader)new JNLPDownloader() :
|
||||||
|
(Downloader)new HTTPDownloader();
|
||||||
} else {
|
} else {
|
||||||
throw new IOException(
|
throw new IOException(
|
||||||
"Unknown source file protocol " +
|
"Unknown source file protocol " +
|
||||||
@@ -276,21 +277,33 @@ public class DownloadManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// now go through and do the post-download phase
|
// now go through and do the post-download phase
|
||||||
|
IOException failure = null;
|
||||||
|
DownloadDescriptor fdesc = null;
|
||||||
for (int ii = 0; ii < size; ii++) {
|
for (int ii = 0; ii < size; ii++) {
|
||||||
Downloader loader = (Downloader)fetch.get(ii);
|
Downloader loader = (Downloader)fetch.get(ii);
|
||||||
try {
|
try {
|
||||||
loader.postDownload(this, obs, pinfo);
|
loader.postDownload(this, obs, pinfo);
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
notifyFailed(obs, loader.getDescriptor(), ioe);
|
// we want to try to apply as many of the patches as we
|
||||||
if (fragile) {
|
// can, so we don't fail entirely here, just keep track of
|
||||||
return;
|
// 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
|
// if we had any failure, go ahead and report it now
|
||||||
// by reporting 100% completion
|
if (failure != null) {
|
||||||
notifyProgress(obs, 100, 0L);
|
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. */
|
/** Helper function. */
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user