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
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user