Search in sources :

Example 1 with Download

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);
    }
}
Also used : DownloadStub(com.biglybt.pif.download.DownloadStub) DownloadStubFile(com.biglybt.pif.download.DownloadStub.DownloadStubFile) PluginInterface(com.biglybt.pif.PluginInterface) Download(com.biglybt.pif.download.Download)

Example 2 with Download

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()]);
}
Also used : ArrayList(java.util.ArrayList) Download(com.biglybt.pif.download.Download) File(java.io.File)

Example 3 with Download

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));
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point) Tag(com.biglybt.core.tag.Tag) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) Download(com.biglybt.pif.download.Download) File(java.io.File)

Example 4 with Download

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);
}
Also used : DiskManagerFileInfo(com.biglybt.pif.disk.DiskManagerFileInfo) DownloadException(com.biglybt.pif.download.DownloadException) Download(com.biglybt.pif.download.Download)

Example 5 with Download

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());
}
Also used : Download(com.biglybt.pif.download.Download)

Aggregations

Download (com.biglybt.pif.download.Download)80 DownloadManager (com.biglybt.core.download.DownloadManager)22 Torrent (com.biglybt.pif.torrent.Torrent)17 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)12 File (java.io.File)12 TOTorrent (com.biglybt.core.torrent.TOTorrent)11 PluginInterface (com.biglybt.pif.PluginInterface)11 URL (java.net.URL)10 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)8 PEPeerManager (com.biglybt.core.peer.PEPeerManager)8 List (java.util.List)7 Tag (com.biglybt.core.tag.Tag)6 MenuItem (com.biglybt.pif.ui.menus.MenuItem)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 DownloadException (com.biglybt.pif.download.DownloadException)5 DiskManager (com.biglybt.core.disk.DiskManager)4 DownloadManager (com.biglybt.pif.download.DownloadManager)4 DownloadScrapeResult (com.biglybt.pif.download.DownloadScrapeResult)4 Peer (com.biglybt.pif.peers.Peer)4