String subcommand = (String) args.remove(0);
if (ci.torrents.isEmpty()) {
ci.out.println("> Command '" + getCommandName() + "': No torrents in list (Maybe you forgot to 'show torrents' first).");
} else {
String name;
DownloadManager dm;
try {
int number = Integer.parseInt(subcommand);
if ((number > 0) && (number <= ci.torrents.size())) {
dm = (DownloadManager) ci.torrents.get(number - 1);
if (dm.getDisplayName() == null)
name = "?";
else
name = dm.getDisplayName();
performCommandIfAllowed(ci, args, dm, "#" + subcommand, name);
} else
ci.out.println("> Command '" + getCommandName() + "': Torrent #" + subcommand + " unknown.");
} catch (NumberFormatException e) {
if ("all".equalsIgnoreCase(subcommand)) {
Iterator torrent = ci.torrents.iterator();
while (torrent.hasNext()) {
dm = (DownloadManager) torrent.next();
if (dm.getDisplayName() == null)
name = "?";
else
name = dm.getDisplayName();
performCommandIfAllowed(ci, args, dm, subcommand, name);
}
} else if ("hash".equalsIgnoreCase(subcommand)) {
String hash = (String) args.remove(0);
List torrents = ci.getGlobalManager().getDownloadManagers();
boolean foundit = false;
Iterator torrent = torrents.iterator();
while (torrent.hasNext()) {
dm = (DownloadManager) torrent.next();
if (hash.equals(TorrentUtils.nicePrintTorrentHash(dm.getTorrent(), true))) {
if (dm.getDisplayName() == null)
name = "?";
else
name = dm.getDisplayName();
// FIXME: check user permission here and fix it to take torrent hash instead of subcommand
performCommandIfAllowed(ci, args, dm, hash, name);
foundit = true;
break;