📄 show.java
字号:
/*
* Written and copyright 2001-2003 Tobias Minich. Distributed under the GNU
* General Public License; see the README file. This code comes with NO
* WARRANTY.
*
* Show.java
*
* Created on 23.03.2004
*
*/
package org.gudy.azureus2.ui.console.commands;
import java.io.PrintStream;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.gudy.azureus2.core3.disk.DiskManager;
import org.gudy.azureus2.core3.disk.DiskManagerFileInfo;
import org.gudy.azureus2.core3.download.DownloadManager;
import org.gudy.azureus2.core3.download.DownloadManagerStats;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.peer.PEPeerManagerStats;
import org.gudy.azureus2.core3.tracker.client.TRTrackerAnnouncer;
import org.gudy.azureus2.core3.tracker.client.TRTrackerScraperResponse;
import org.gudy.azureus2.core3.util.ByteFormatter;
import org.gudy.azureus2.core3.util.DisplayFormatters;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.ui.console.ConsoleInput;
import com.aelitis.azureus.core.dht.DHT;
import com.aelitis.azureus.core.dht.control.DHTControlStats;
import com.aelitis.azureus.core.dht.db.DHTDBStats;
import com.aelitis.azureus.core.dht.router.DHTRouterStats;
import com.aelitis.azureus.core.dht.transport.*;
import com.aelitis.azureus.plugins.dht.DHTPlugin;
/**
* @author Tobias Minich
*/
public class Show extends IConsoleCommand {
private static final class TorrentComparator implements Comparator {
public final int compare(Object a, Object b) {
DownloadManager aDL = (DownloadManager) a;
DownloadManager bDL = (DownloadManager) b;
boolean aIsComplete = aDL.getStats().getDownloadCompleted(false) == 1000;
boolean bIsComplete = bDL.getStats().getDownloadCompleted(false) == 1000;
if (aIsComplete && !bIsComplete)
return 1;
if (!aIsComplete && bIsComplete)
return -1;
return aDL.getPosition() - bDL.getPosition();
}
}
public Show()
{
super( new String[] { "show", "sh" });
}
public String getCommandDescriptions() {
return("show [<various options>]\tsh\tShow info. Use without parameter to get a list of available options.");
}
public void printHelp(PrintStream out, List args) {
out.println("> -----");
out.println("'show' options: ");
out.println("<#>\t\t\t\tFurther info on a single torrent. Run 'show torrents' first for the number.");
out.println("options\t\t\to\tShow list of options for 'set' (also available by 'set' without parameters).");
out.println("files\t\t\tf\tShow list of files found from the 'add -f' command (also available by 'add -l')");
out.println("torrents [options]\tt\tShow list of torrents. torrent options mayb be any (or none) of:");
out.println("\t\tactive\t\ta\tShow only active torrents.");
out.println("\t\tcomplete\tc\tShow only complete torrents.");
out.println("\t\tincomplete\ti\tShow only incomplete torrents.");
out.println("dht\t\t\td\tShow distributed database statistics");
out.println("> -----");
}
public void execute(String commandName, ConsoleInput ci, List args) {
if( args.isEmpty() )
{
printHelp(ci.out, args);
return;
}
String subCommand = (String) args.remove(0);
if (subCommand.equalsIgnoreCase("options") || subCommand.equalsIgnoreCase("o")) {
ci.invokeCommand("set", null);
} else if(subCommand.equalsIgnoreCase("files") || subCommand.equalsIgnoreCase("f")) {
ci.invokeCommand("add", Arrays.asList( new String[] { "--list"} ));
} else if (subCommand.equalsIgnoreCase("torrents") || subCommand.equalsIgnoreCase("t")) {
ci.out.println("> -----");
ci.torrents.clear();
ci.torrents.addAll(ci.gm.getDownloadManagers());
Collections.sort(ci.torrents, new TorrentComparator());
if (ci.torrents.isEmpty()) {
ci.out.println("No Torrents");
ci.out.println("> -----");
return;
}
long totalReceived = 0;
long totalSent = 0;
long totalDiscarded = 0;
int connectedSeeds = 0;
int connectedPeers = 0;
PEPeerManagerStats ps;
int nrTorrent = 0;
boolean bShowOnlyActive = false;
boolean bShowOnlyComplete = false;
boolean bShowOnlyIncomplete = false;
for (Iterator iter = args.iterator(); iter.hasNext();) {
String arg = (String) iter.next();
if ("active".equalsIgnoreCase(arg) || "a".equalsIgnoreCase(arg)) {
bShowOnlyActive = true;
iter.remove();
} else if ("complete".equalsIgnoreCase(arg) || "c".equalsIgnoreCase(arg)) {
bShowOnlyComplete = true;
iter.remove();
} else if ("incomplete".equalsIgnoreCase(arg) || "i".equalsIgnoreCase(arg)) {
bShowOnlyIncomplete = true;
iter.remove();
}
}
Iterator torrent;
if( args.size() > 0 )
{
List matchedTorrents = new TorrentFilter().getTorrents(ci.torrents, args);
torrent = matchedTorrents.iterator();
}
else
torrent = ci.torrents.iterator();
while (torrent.hasNext()) {
nrTorrent++;
DownloadManager dm = (DownloadManager) torrent.next();
DownloadManagerStats stats = dm.getStats();
boolean bDownloadCompleted = stats.getDownloadCompleted(false) == 1000;
boolean bCanShow = ((bShowOnlyComplete == bShowOnlyIncomplete) || (bDownloadCompleted && bShowOnlyComplete) || (!bDownloadCompleted && bShowOnlyIncomplete));
if (bCanShow && bShowOnlyActive) {
int dmstate = dm.getState();
bCanShow = (dmstate == DownloadManager.STATE_SEEDING) || (dmstate == DownloadManager.STATE_DOWNLOADING) || (dmstate == DownloadManager.STATE_CHECKING) || (dmstate == DownloadManager.STATE_INITIALIZING) || (dmstate == DownloadManager.STATE_ALLOCATING);
}
if (bCanShow) {
try {
ps = dm.getPeerManager().getStats();
} catch (Exception e) {
ps = null;
}
if (ps != null) {
totalReceived += dm.getStats().getTotalDataBytesReceived();
totalSent += dm.getStats().getTotalDataBytesSent();
totalDiscarded += ps.getTotalDiscarded();
connectedSeeds += dm.getNbSeeds();
connectedPeers += dm.getNbPeers();
}
ci.out.print(((nrTorrent < 10) ? " " : "") + nrTorrent + " ");
ci.out.println(getTorrentSummary(dm));
ci.out.println();
}
}
ci.out.println("Total Speed (down/up): " + DisplayFormatters.formatByteCountToKiBEtcPerSec(ci.gm.getStats().getDataReceiveRate() + ci.gm.getStats().getProtocolReceiveRate() ) + " / " + DisplayFormatters.formatByteCountToKiBEtcPerSec(ci.gm.getStats().getDataSendRate() + ci.gm.getStats().getProtocolSendRate() ));
ci.out.println("Transferred Volume (down/up/discarded): " + DisplayFormatters.formatByteCountToKiBEtc(totalReceived) + " / " + DisplayFormatters.formatByteCountToKiBEtc(totalSent) + " / " + DisplayFormatters.formatByteCountToKiBEtc(totalDiscarded));
ci.out.println("Total Connected Peers (seeds/peers): " + Integer.toString(connectedSeeds) + " / " + Integer.toString(connectedPeers));
ci.out.println("> -----");
} else if (subCommand.equalsIgnoreCase("dht") || subCommand.equalsIgnoreCase("d")) {
showDHTStats( ci );
} else {
if ((ci.torrents == null) || (ci.torrents != null) && ci.torrents.isEmpty()) {
ci.out.println("> Command 'show': No torrents in list (try 'show torrents' first).");
return;
}
try {
int number = Integer.parseInt(subCommand);
if ((number == 0) || (number > ci.torrents.size())) {
ci.out.println("> Command 'show': Torrent #" + number + " unknown.");
return;
}
DownloadManager dm = (DownloadManager) ci.torrents.get(number - 1);
printTorrentDetails(ci.out, dm, number);
}
catch (Exception e) {
ci.out.println("> Command 'show': Subcommand '" + subCommand + "' unknown.");
return;
}
}
}
/**
* returns the summary details for the specified torrent. - we do this by obtaining
* the summary format and then performing variable substitution
* NOTE: we currently reprocess
* the summary format string each time however we could pre-parse this once.. its
* probably not that important though.
* @return
*/
protected String getTorrentSummary(DownloadManager dm) {
StringBuffer tstate = new StringBuffer();
String summaryFormat = getDefaultSummaryFormat();
char lastch = '0';
char []summaryChars = summaryFormat.toCharArray();
for (int i = 0; i < summaryChars.length; i++) {
char ch = summaryChars[i];
if( ch == '%' && lastch != '\\' )
{
i++;
if( i >= summaryChars.length )
tstate.append('%');
else
tstate.append(expandVariable(summaryChars[i], dm));
}
else
tstate.append(ch);
lastch = ch;
}
return tstate.toString();
}
/**
* expands the specified variable character into a string. <br>currently available
* variables that can be expanded are:<br>
* <hr>
* %a for state<br>
* %c percentage complete<br>
* %t torrent details - error message if error, otherwise torrent name<br>
* %z size<br>
* %e ETA<br>
* %r progress, if we have disabled some files<br>
* %d download speed<br>
* %u upload speed<br>
* %D amount downloaded<br>
* %U amount uploaded<br>
* %s connected seeds<br>
* %p connected peers<br>
* %S tracker seeds<br>
* %P tracker peers<br>
* @param variable variable character, eg: 'e' for ETA
* @param dm download manager object
* @return string expansion of the variable
*/
protected String expandVariable( char variable, DownloadManager dm )
{
switch( variable )
{
case 'a':
return getShortStateString(dm.getState());
case 'c':
DecimalFormat df = new DecimalFormat("000.0%");
return df.format(dm.getStats().getCompleted() / 1000.0);
case 't':
if (dm.getState() == DownloadManager.STATE_ERROR)
return dm.getErrorDetails();
else {
if (dm.getDisplayName() == null)
return "?";
else
return dm.getDisplayName();
}
case 'z':
return DisplayFormatters.formatByteCountToKiBEtc(dm.getSize());
case 'e':
return DisplayFormatters.formatETA(dm.getStats().getETA());
case 'r':
long to = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -