* i2psnark:

- Add link to finished torrent in message box
      - Don't let one bad torrent prevent others from
        starting or stopping
This commit is contained in:
zzz
2010-10-02 15:43:56 +00:00
parent b83184e895
commit ec0c678cc9
2 changed files with 26 additions and 7 deletions

View File

@ -437,7 +437,7 @@ public class Snark
try { storage.close(); } catch (IOException ioee) { try { storage.close(); } catch (IOException ioee) {
ioee.printStackTrace(); ioee.printStackTrace();
} }
fatal("Could not create storage", ioe); fatal("Could not check or create storage", ioe);
} }
} }

View File

@ -439,7 +439,10 @@ public class SnarkManager implements Snark.CompleteListener {
return null; return null;
} }
/** @throws RuntimeException via Snark.fatal() */
public void addTorrent(String filename) { addTorrent(filename, false); } public void addTorrent(String filename) { addTorrent(filename, false); }
/** @throws RuntimeException via Snark.fatal() */
public void addTorrent(String filename, boolean dontAutoStart) { public void addTorrent(String filename, boolean dontAutoStart) {
if ((!dontAutoStart) && !_util.connected()) { if ((!dontAutoStart) && !_util.connected()) {
addMessage(_("Connecting to I2P")); addMessage(_("Connecting to I2P"));
@ -724,9 +727,13 @@ public class SnarkManager implements Snark.CompleteListener {
/** two listeners */ /** two listeners */
public void torrentComplete(Snark snark) { public void torrentComplete(Snark snark) {
File f = new File(snark.torrent); StringBuilder buf = new StringBuilder(256);
buf.append("<a href=\"/i2psnark/").append(snark.storage.getBaseName());
if (snark.meta.getFiles() != null)
buf.append('/');
buf.append("\">").append(snark.storage.getBaseName()).append("</a>");
long len = snark.meta.getTotalLength(); long len = snark.meta.getTotalLength();
addMessage(_("Download finished: \"{0}\"", f.getName()) + " (" + _("size: {0}B", DataHelper.formatSize2(len)) + ')'); addMessage(_("Download finished: {0}", buf.toString()) + " (" + _("size: {0}B", DataHelper.formatSize2(len)) + ')');
updateStatus(snark); updateStatus(snark);
} }
@ -736,7 +743,7 @@ public class SnarkManager implements Snark.CompleteListener {
private void monitorTorrents(File dir) { private void monitorTorrents(File dir) {
String fileNames[] = dir.list(TorrentFilenameFilter.instance()); String fileNames[] = dir.list(TorrentFilenameFilter.instance());
List foundNames = new ArrayList(0); List<String> foundNames = new ArrayList(0);
if (fileNames != null) { if (fileNames != null) {
for (int i = 0; i < fileNames.length; i++) { for (int i = 0; i < fileNames.length; i++) {
try { try {
@ -747,7 +754,7 @@ public class SnarkManager implements Snark.CompleteListener {
} }
} }
Set existingNames = listTorrentFiles(); Set<String> existingNames = listTorrentFiles();
// lets find new ones first... // lets find new ones first...
for (int i = 0; i < foundNames.size(); i++) { for (int i = 0; i < foundNames.size(); i++) {
if (existingNames.contains(foundNames.get(i))) { if (existingNames.contains(foundNames.get(i))) {
@ -755,7 +762,13 @@ public class SnarkManager implements Snark.CompleteListener {
} else { } else {
if (shouldAutoStart() && !_util.connect()) if (shouldAutoStart() && !_util.connect())
addMessage(_("Unable to connect to I2P!")); addMessage(_("Unable to connect to I2P!"));
addTorrent((String)foundNames.get(i), !shouldAutoStart()); try {
// Snark.fatal() throws a RuntimeException
// don't let one bad torrent kill the whole loop
addTorrent(foundNames.get(i), !shouldAutoStart());
} catch (Exception e) {
addMessage(_("Unable to add {0}", foundNames.get(i)) + ": " + e);
}
} }
} }
// now lets see which ones have been removed... // now lets see which ones have been removed...
@ -765,7 +778,13 @@ public class SnarkManager implements Snark.CompleteListener {
// known and still there. noop // known and still there. noop
} else { } else {
// known, but removed. drop it // known, but removed. drop it
stopTorrent(name, true); try {
// Snark.fatal() throws a RuntimeException
// don't let one bad torrent kill the whole loop
stopTorrent(name, true);
} catch (Exception e) {
// don't bother with message
}
} }
} }
} }