use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class Archive method execute.
@Override
public void execute(String commandName, ConsoleInput ci, List<String> args) {
if (args.size() > 0) {
PluginInterface pi = ci.getCore().getPluginManager().getDefaultPluginInterface();
DownloadStub[] stubs = pi.getDownloadManager().getDownloadStubs();
String sub = args.get(0);
int index = -1;
if (args.size() > 1) {
String index_str = args.get(1);
try {
index = Integer.parseInt(index_str);
index--;
if (index < 0 || index >= stubs.length) {
index = -1;
}
} catch (Throwable e) {
}
if (index == -1) {
ci.out.println("Invalid archive index: " + index_str);
}
}
if (sub.equals("list") || sub.equals("l")) {
int pos = 1;
ci.out.println("> -----");
for (DownloadStub stub : stubs) {
System.out.println(" " + (pos++) + "\t" + stub.getName() + " (" + DisplayFormatters.formatByteCountToKiBEtc(stub.getTorrentSize()) + ")");
}
ci.out.println("> -----");
} else if (index != -1 && (sub.equals("show") || sub.equals("s"))) {
try {
DownloadStub stub = stubs[index];
ci.out.println("> -----");
ci.out.println(" " + stub.getName() + " - hash=" + ByteFormatter.encodeString(stub.getTorrentHash()));
DownloadStubFile[] files = stub.getStubFiles();
ci.out.println(" Files: " + files.length);
for (DownloadStubFile file : files) {
long length = file.getLength();
ci.out.println(" " + file.getFile() + " - " + (length < 0 ? ("Not downloaded") : DisplayFormatters.formatByteCountToKiBEtc(length)));
}
ci.out.println("> -----");
} catch (Throwable e) {
ci.out.print(e);
}
} else if (index != -1 && (sub.equals("restore") || sub.equals("res"))) {
try {
Download d = stubs[index].destubbify();
ci.out.println("> Restore of " + d.getName() + " succeeded.");
} catch (Throwable e) {
ci.out.print(e);
}
} else if (index != -1 && (sub.equals("delete") || sub.equals("del"))) {
try {
DownloadStub stub = stubs[index];
String name = stub.getName();
stub.remove();
ci.out.println("> Delete of " + name + " succeeded.");
} catch (Throwable e) {
ci.out.print(e);
}
} else {
ci.out.println("Unsupported sub-command: " + sub);
return;
}
} else {
printHelp(ci.out, args);
}
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class DownloadManagerMoveHandler method getRelatedDirs.
/**
* Find all file locations that a download might exist in - this is used
* to see locate existing files to reuse to prevent downloads being re-added.
*/
public static File[] getRelatedDirs(DownloadManager dm) {
ArrayList result = new ArrayList();
Download d = PluginCoreUtils.wrap(dm);
if (isOnCompleteEnabled()) {
addFile(result, COConfigurationManager.getStringParameter("Completed Files Directory"));
addFile(result, CURRENT_HANDLER.onCompletion(d, false, false));
addFile(result, DownloadManagerDefaultPaths.DEFAULT_HANDLER.onCompletion(d, false, false));
}
if (isOnRemovalEnabled()) {
addFile(result, COConfigurationManager.getStringParameter("File.move.download.removed.path"));
addFile(result, CURRENT_HANDLER.onRemoval(d, false, false));
addFile(result, DownloadManagerDefaultPaths.DEFAULT_HANDLER.onRemoval(d, false, false));
}
return (File[]) result.toArray(new File[result.size()]);
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class ColumnTagGroupIcons method cellPaint.
@Override
public void cellPaint(GC gc, TableCellSWT cell) {
Download dm = (Download) cell.getDataSource();
List<String> files = new ArrayList<>();
if (dm != null) {
List<Tag> tags = tag_manager.getTagsForTaggable(interesting_tts, PluginCoreUtils.unwrap(dm));
tags = TagUtils.sortTagIcons(tags);
for (Tag tag : tags) {
if (tag.getGroupContainer() == tag_group) {
String file = tag.getImageFile();
if (file != null) {
files.add(file);
}
}
}
}
int num_files = files.size();
if (num_files > 0) {
Rectangle bounds = cell.getBounds();
bounds.x += 1;
bounds.y += 1;
bounds.width -= 1;
bounds.height -= 1;
int w = bounds.width / num_files;
List<Image> images = new ArrayList<>();
List<String> keys = new ArrayList<>();
for (String file : files) {
try {
ImageLoader.getInstance().getFileImage(new File(file), new Point(w - 1, bounds.height), new ImageLoader.ImageDownloaderListener() {
@Override
public void imageDownloaded(Image image, String key, boolean returnedImmediately) {
if (image != null && returnedImmediately) {
images.add(image);
keys.add(key);
}
}
});
} catch (Throwable e) {
}
}
if (images.size() > 0) {
int width_per_image = bounds.width / images.size();
for (int i = 0; i < images.size(); i++) {
Image image = images.get(i);
int iw = image.getBounds().width;
gc.drawImage(image, bounds.x + (width_per_image - iw) / 2, bounds.y);
bounds.x += width_per_image;
ImageLoader.getInstance().releaseImage(keys.get(i));
}
}
}
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class TranscodeFileImpl method getName.
@Override
public String getName() {
TranscodeJob job = getJob();
String text;
if (job == null) {
try {
DiskManagerFileInfo sourceFile = getSourceFile();
try {
Download download = sourceFile.getDownload();
if (download == null) {
text = sourceFile.getFile().getName();
} else {
text = download.getName();
DiskManagerFileInfo[] fileInfo = download.getDiskManagerFileInfo();
if (fileInfo.length > 1) {
text += ": " + sourceFile.getFile(true).getName();
}
}
} catch (DownloadException e) {
text = sourceFile.getFile().getName();
}
} catch (Throwable e) {
text = "";
}
} else {
text = job.getName();
}
return (text);
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class TranscodeFileImpl method setSourceFile.
protected void setSourceFile(DiskManagerFileInfo file) {
try {
Download download = file.getDownload();
if (download != null && download.getTorrent() != null) {
setString(KEY_SOURCE_FILE_HASH, Base32.encode(download.getTorrent().getHash()));
setLong(KEY_SOURCE_FILE_INDEX, file.getIndex());
}
} catch (Throwable e) {
}
setString(KEY_SOURCE_FILE_LINK, file.getFile().getAbsolutePath());
}
Aggregations