Prioritypublic class Priority extends OptionsConsoleCommand the priority command changes the priority of files within a torrent |
Fields Summary |
---|
private static final int | NORMAL | private static final int | HIGH | private static final int | DONOTDOWNLOAD | private static final int | DELETE | private static final String[] | priostr | private int | newprio |
Constructors Summary |
---|
public Priority()
super(new String []{ "prio" } );
|
Methods Summary |
---|
public void | execute(java.lang.String commandName, org.gudy.azureus2.ui.console.ConsoleInput console, org.apache.commons.cli.CommandLine commandLine)
String tnumstr, fnumstr, newpriostr;
int tnumber;
DiskManagerFileInfo[] files;
String[] sections;
List args = commandLine.getArgList();
LinkedList fs,fe;
DownloadManager dm;
if( args.isEmpty() )
{
console.out.println("Torrent # required!");
return;
} else {
tnumstr = (String) args.remove(0);
}
if( args.isEmpty() )
{
console.out.println("File # required!");
return;
} else {
fnumstr = (String) args.remove(0);
}
if ((console.torrents == null) || console.torrents.isEmpty()) {
console.out.println("> Command 'prio': No torrents in list (try 'show torrents' first).");
return;
}
try {
tnumber = Integer.parseInt(tnumstr);
if ((tnumber == 0) || (tnumber > console.torrents.size())) {
console.out.println("> Command 'prio': Torrent #" + tnumber + " unknown.");
return;
}
dm = (DownloadManager) console.torrents.get(tnumber - 1);
files = dm.getDiskManagerFileInfo();
}
catch (Exception e) {
e.printStackTrace();
console.out.println("> Command 'prio': Torrent # '" + tnumstr + "' unknown.");
return;
}
if( args.isEmpty() )
{
console.out.println("> Command 'prio': missing parameter for new priority");
return;
} else {
newpriostr = (String) args.remove(0);
}
if (newpriostr.equalsIgnoreCase("normal")) {
newprio = NORMAL;
} else if (newpriostr.equalsIgnoreCase("high")) {
newprio = HIGH;
} else if (newpriostr.equalsIgnoreCase("dnd")) {
newprio = DONOTDOWNLOAD;
} else if (newpriostr.equalsIgnoreCase("del")) {
newprio = DELETE;
} else {
console.out.println("> Command 'prio': unknown priority "
+ newpriostr);
return;
}
if (fnumstr.equalsIgnoreCase("all")) {
sections = new String[1];
sections[0] = "1-"+files.length;
} else
sections = fnumstr.split(",");
fs = new LinkedList();
fe = new LinkedList();
int dash,start,end;
for (int i=0; i<sections.length; i++) {
try {
if ((dash = sections[i].indexOf('-")) != -1) {
start = Integer.parseInt(sections[i].substring(0,dash));
end = Integer.parseInt(sections[i].substring(dash+1));
} else
start = end = Integer.parseInt(sections[i]);
if ((start == 0) || (end > files.length)) {
console.out.println("> Command 'prio': Invalid file range " + sections[i]);
return;
}
if (start > end) {
console.out.println("> Command 'prio': Invalid file range '"+sections[i]+"'");
}
// -1 compensates for 0-based offsets
fs.add(new Integer(start - 1));
fe.add(new Integer(end - 1));
} catch (Exception e) {
console.out.println("> Command 'prio': File # '" + sections[i]
+ "' unknown.");
return;
}
}
// console.out.println("DM was " + dm.getState());
if ((newprio == DELETE) && (dm.getState() != DownloadManager.STATE_STOPPED)) {
try {
dm.stopIt( DownloadManager.STATE_STOPPED, false, false );
} catch (Exception e) {
console.out.println("Failed to stop torrent " + tnumber);
return;
}
}
// console.out.println("DM is " + dm.getState());
int nummod = 0;
while (fs.size() > 0) {
start = ((Integer) fs.removeFirst()).intValue();
end = ((Integer) fe.removeFirst()).intValue();
for (int i = start; i <= end; i++) {
nummod++;
// DEBUG
// console.out.println("Setting priority for file " + i + " to " + newprio);
if (newprio == NORMAL) {
files[i].setPriority(false);
files[i].setSkipped(false);
} else if (newprio == HIGH) {
files[i].setPriority(true);
files[i].setSkipped(false);
} else if (newprio == DONOTDOWNLOAD) {
files[i].setPriority(false);
files[i].setSkipped(true);
} else if (newprio == DELETE) {
if (files[i].setStorageType(DiskManagerFileInfo.ST_COMPACT)) {
files[i].setPriority(false);
files[i].setSkipped(true);
} else {
console.out.println("> Command 'prio': Failed to delete file " + (i+1));
nummod--;
}
}
}
}
if ((newprio == DELETE) && (dm.getState() == DownloadManager.STATE_STOPPED)) {
try {
dm.stopIt( DownloadManager.STATE_QUEUED, false, false );
} catch (Exception e) {
console.out.println("Failed to restart torrent " + tnumber);
return;
}
}
// console.out.println("DM is again " + dm.getState());
console.out.println(nummod + " file(s) priority set to " + priostr[newprio-1]);
| public java.lang.String | getCommandDescriptions()
return "prio [#torrent] [#file|range(i.e. 1-2,5)|all] [normal|high|dnd|del]";
| public void | printHelp(java.io.PrintStream out, java.util.List args)
out.println("> -----");
out.println("Usage: prio [torrent] [file(s)] [priority]");
out.println("Options:");
out.println("\t[torrent]\tThe torrent number from 'show torrents'");
out.println("\t[file(s)] is one of:");
out.println("\t\t\t#file:\tthe file number from 'show [#torrent]',");
out.println("\t\t\trange:\ta range of file numbers, i.e. 1-3 or 1-10,12-15 or 1,3,5-8 ,");
out.println("\t\t\tall:\t 'all' applies priority to all files of the torrent");
out.println("\t[priority] is one of:");
out.println("\t\t\tnormal\tNormal priority");
out.println("\t\t\thigh \tHigh priority");
out.println("\t\t\tdnd \tDo not download (skip)");
out.println("\t\t\tdel \tDo not download & delete file");
out.println("> -----");
|
|