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.
This commit is contained in:
Michael Bayne
2006-07-26 20:11:34 +00:00
parent ae36f9138d
commit 6eed6697dc
2 changed files with 32 additions and 14 deletions
@@ -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<Resource> _codes = new ArrayList<Resource>();
protected ArrayList<Resource> _resources = new ArrayList<Resource>();
@@ -504,21 +504,26 @@ public abstract class Getdown extends Thread
}
};
Downloader dl;
if (resources.equals(_app.getAllResources())) {
ArrayList<Resource> full = new ArrayList<Resource>();
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<Resource> full = new ArrayList<Resource>();
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();