From 6eed6697dcdd2b42b835a156b5ae57358c9ae5a0 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 26 Jul 2006 20:11:34 +0000 Subject: [PATCH] Do not simply assume we want to use the Bit Torrent downloader. It causes weird things to happen if one is not actually running a tracker. Fortunately this did not break everything, but having our users see "2,147,483,647%" complete" instead of actual download progress is not an especially graceful fallback. --- .../threerings/getdown/data/Application.java | 13 ++++++++ .../threerings/getdown/launcher/Getdown.java | 33 +++++++++++-------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/java/com/threerings/getdown/data/Application.java b/src/java/com/threerings/getdown/data/Application.java index 2671d01..7fbbdef 100644 --- a/src/java/com/threerings/getdown/data/Application.java +++ b/src/java/com/threerings/getdown/data/Application.java @@ -150,6 +150,15 @@ public class Application _config = getLocalPath(CONFIG_FILE); } + /** + * Indicates whether or not we support downloading of our resources using + * the Bittorrent protocol. + */ + public boolean getUseTorrent () + { + return _useTorrent; + } + /** * Returns a resource that refers to the application configuration * file itself. @@ -429,6 +438,9 @@ public class Application } } + // determine whether or not we should be using bit torrent + _useTorrent = Boolean.parseBoolean((String)cdata.get("torrent")); + // look for a debug.txt file which causes us to run in java.exe on // Windows so that we can obtain a thread dump of the running JVM _windebug = getLocalPath("debug.txt").exists(); @@ -996,6 +1008,7 @@ public class Application protected String _class; protected String _name; protected boolean _windebug; + protected boolean _useTorrent = false; protected ArrayList _codes = new ArrayList(); protected ArrayList _resources = new ArrayList(); diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index 78c5cb4..1e24ad7 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -504,21 +504,26 @@ public abstract class Getdown extends Thread } }; - Downloader dl; - if (resources.equals(_app.getAllResources())) { - ArrayList full = new ArrayList(); - full.add(_app.getFullResource()); - full.addAll(resources); - dl = new TorrentDownloader(full, obs); - } else if (resources.size() == 1 && - resources.get(0).getPath().startsWith("patch")) { - dl = new TorrentDownloader(resources, obs); - } else { - dl = new HTTPDownloader(resources, obs); - } - dl.start(); + // assume we're going to use an HTTP downloader + Downloader dl = new HTTPDownloader(resources, obs); - // now wait for it to complete + // if torrent downloading is enabled and we are downloading the right + // set of resources (a single patch file or the entire app from + // scratch), then use a torrent downloader instead + if (_app.getUseTorrent()) { + if (resources.equals(_app.getAllResources())) { + ArrayList full = new ArrayList(); + full.add(_app.getFullResource()); + full.addAll(resources); + dl = new TorrentDownloader(full, obs); + } else if (resources.size() == 1 && + resources.get(0).getPath().startsWith("patch")) { + dl = new TorrentDownloader(resources, obs); + } + } + + // start the download and wait for it to complete + dl.start(); synchronized (lock) { try { lock.wait();