Search in sources :

Example 1 with TorrentHandle

use of com.frostwire.jlibtorrent.TorrentHandle in project frostwire by frostwire.

the class BTEngine method download.

public void download(TorrentCrawledSearchResult sr, File saveDir, boolean dontSaveTorrentFile) {
    if (swig() == null) {
        return;
    }
    saveDir = setupSaveDir(saveDir);
    if (saveDir == null) {
        return;
    }
    TorrentInfo ti = sr.getTorrentInfo();
    int fileIndex = sr.getFileIndex();
    TorrentHandle th = find(ti.infoHash());
    boolean exists = th != null;
    if (th != null) {
        Priority[] priorities = th.filePriorities();
        if (priorities[fileIndex] == Priority.IGNORE) {
            priorities[fileIndex] = Priority.NORMAL;
            download(ti, saveDir, priorities, null, null);
        }
    } else {
        Priority[] priorities = Priority.array(Priority.IGNORE, ti.numFiles());
        priorities[fileIndex] = Priority.NORMAL;
        download(ti, saveDir, priorities, null, null);
    }
    if (!exists) {
        saveResumeTorrent(ti);
        if (!dontSaveTorrentFile) {
            saveTorrent(ti);
        }
    }
}
Also used : TorrentHandle(com.frostwire.jlibtorrent.TorrentHandle) Priority(com.frostwire.jlibtorrent.Priority) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) TcpEndpoint(com.frostwire.jlibtorrent.TcpEndpoint)

Example 2 with TorrentHandle

use of com.frostwire.jlibtorrent.TorrentHandle in project frostwire by frostwire.

the class BTEngine method download.

private void download(TorrentInfo ti, File saveDir, Priority[] priorities, File resumeFile, List<TcpEndpoint> peers) {
    TorrentHandle th = find(ti.infoHash());
    if (th != null) {
        // found a download with the same hash, just adjust the priorities if needed
        if (priorities != null) {
            if (ti.numFiles() != priorities.length) {
                throw new IllegalArgumentException("The priorities length should be equals to the number of files");
            }
            th.prioritizeFiles(priorities);
            fireDownloadUpdate(th);
            th.resume();
        } else {
            // did they just add the entire torrent (therefore not selecting any priorities)
            final Priority[] wholeTorrentPriorities = Priority.array(Priority.NORMAL, ti.numFiles());
            th.prioritizeFiles(wholeTorrentPriorities);
            fireDownloadUpdate(th);
            th.resume();
        }
    } else {
        // new download
        download(ti, saveDir, resumeFile, priorities, peers);
    }
}
Also used : TorrentHandle(com.frostwire.jlibtorrent.TorrentHandle) Priority(com.frostwire.jlibtorrent.Priority)

Example 3 with TorrentHandle

use of com.frostwire.jlibtorrent.TorrentHandle in project frostwire by frostwire.

the class BTEngine method download.

public void download(File torrent, File saveDir, boolean[] selection) {
    if (swig() == null) {
        return;
    }
    saveDir = setupSaveDir(saveDir);
    if (saveDir == null) {
        return;
    }
    TorrentInfo ti = new TorrentInfo(torrent);
    if (selection == null) {
        selection = new boolean[ti.numFiles()];
        Arrays.fill(selection, true);
    }
    Priority[] priorities = null;
    TorrentHandle th = find(ti.infoHash());
    boolean exists = th != null;
    if (selection != null) {
        if (th != null) {
            priorities = th.filePriorities();
        } else {
            priorities = Priority.array(Priority.IGNORE, ti.numFiles());
        }
        boolean changed = false;
        for (int i = 0; i < selection.length; i++) {
            if (selection[i]) {
                if (priorities[i] == Priority.IGNORE) {
                    priorities[i] = Priority.NORMAL;
                    changed = true;
                }
            }
        }
        if (!changed) {
            // nothing to do
            return;
        }
    }
    download(ti, saveDir, priorities, null, null);
    if (!exists) {
        saveResumeTorrent(ti);
    }
}
Also used : TorrentHandle(com.frostwire.jlibtorrent.TorrentHandle) Priority(com.frostwire.jlibtorrent.Priority) TorrentInfo(com.frostwire.jlibtorrent.TorrentInfo) TcpEndpoint(com.frostwire.jlibtorrent.TcpEndpoint)

Example 4 with TorrentHandle

use of com.frostwire.jlibtorrent.TorrentHandle in project frostwire by frostwire.

the class BTEngine method download.

public void download(TorrentInfo ti, File saveDir, boolean[] selection, List<TcpEndpoint> peers, boolean dontSaveTorrentFile) {
    if (swig() == null) {
        return;
    }
    saveDir = setupSaveDir(saveDir);
    if (saveDir == null) {
        return;
    }
    if (selection == null) {
        selection = new boolean[ti.numFiles()];
        Arrays.fill(selection, true);
    }
    Priority[] priorities = null;
    TorrentHandle th = find(ti.infoHash());
    boolean torrentHandleExists = th != null;
    if (torrentHandleExists) {
        try {
            priorities = th.filePriorities();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    } else {
        priorities = Priority.array(Priority.IGNORE, ti.numFiles());
    }
    if (priorities != null) {
        boolean changed = false;
        for (int i = 0; i < selection.length; i++) {
            if (selection[i] && i < priorities.length) {
                if (priorities[i] == Priority.IGNORE) {
                    priorities[i] = Priority.NORMAL;
                    changed = true;
                }
            }
        }
        if (!changed) {
            // nothing to do
            return;
        }
    }
    download(ti, saveDir, priorities, null, peers);
    if (!torrentHandleExists) {
        saveResumeTorrent(ti);
        if (!dontSaveTorrentFile) {
            saveTorrent(ti);
        }
    }
}
Also used : TorrentHandle(com.frostwire.jlibtorrent.TorrentHandle) Priority(com.frostwire.jlibtorrent.Priority) TcpEndpoint(com.frostwire.jlibtorrent.TcpEndpoint)

Example 5 with TorrentHandle

use of com.frostwire.jlibtorrent.TorrentHandle in project frostwire by frostwire.

the class TransferDetailTrackersFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    if (uiBittorrentDownload == null) {
        return;
    }
    if (adapter == null && isAdded()) {
        adapter = new TrackerRecyclerViewAdapter(uiBittorrentDownload, getFragmentManager());
    }
    // ensureComponentsReferenced();
    if (recyclerView.getAdapter() == null) {
        recyclerView.setAdapter(adapter);
    }
    if (addTrackerButtonClickListener == null && adapter != null) {
        TorrentHandle torrentHandle = uiBittorrentDownload.getDl().getTorrentHandle();
        addTrackerButtonClickListener = new AddTrackerButtonClickListener(torrentHandle, adapter);
        addTrackerButton.setOnClickListener(addTrackerButtonClickListener);
    }
    onTime();
}
Also used : TorrentHandle(com.frostwire.jlibtorrent.TorrentHandle)

Aggregations

TorrentHandle (com.frostwire.jlibtorrent.TorrentHandle)5 Priority (com.frostwire.jlibtorrent.Priority)4 TcpEndpoint (com.frostwire.jlibtorrent.TcpEndpoint)3 TorrentInfo (com.frostwire.jlibtorrent.TorrentInfo)2