Search in sources :

Example 1 with Tracker

use of com.biglybt.pif.tracker.Tracker in project BiglyBT by BiglySoftware.

the class MySharesView method startStopSelectedShares.

private void startStopSelectedShares(boolean do_stop) {
    List items = getSelectedItems();
    if (items.size() == 0) {
        return;
    }
    PluginInterface pi = PluginInitializer.getDefaultInterface();
    com.biglybt.pif.download.DownloadManager dm = pi.getDownloadManager();
    Tracker tracker = pi.getTracker();
    for (int i = 0; i < items.size(); i++) {
        ShareItem item = (ShareItem) items.get(i);
        try {
            Torrent t = item.getTorrent();
            TrackerTorrent tracker_torrent = tracker.getTorrent(t);
            Download download = dm.getDownload(t);
            if (tracker_torrent == null || download == null) {
                continue;
            }
            int dl_state = download.getState();
            if (dl_state == Download.ST_ERROR) {
            } else if (dl_state != Download.ST_STOPPED) {
                if (do_stop) {
                    try {
                        download.stop();
                    } catch (Throwable e) {
                    }
                    try {
                        tracker_torrent.stop();
                    } catch (Throwable e) {
                    }
                }
            } else {
                if (!do_stop) {
                    try {
                        download.restart();
                    } catch (Throwable e) {
                    }
                    try {
                        tracker_torrent.start();
                    } catch (Throwable e) {
                    }
                }
            }
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
}
Also used : Tracker(com.biglybt.pif.tracker.Tracker) Torrent(com.biglybt.pif.torrent.Torrent) TrackerTorrent(com.biglybt.pif.tracker.TrackerTorrent) TrackerTorrent(com.biglybt.pif.tracker.TrackerTorrent) PluginInterface(com.biglybt.pif.PluginInterface) List(java.util.List) Download(com.biglybt.pif.download.Download)

Example 2 with Tracker

use of com.biglybt.pif.tracker.Tracker in project BiglyBT by BiglySoftware.

the class ManagerUtils method asyncStopDelete.

public static void asyncStopDelete(final DownloadManager dm, final int stateAfterStopped, final boolean bDeleteTorrent, final boolean bDeleteData, final AERunnable deleteFailed) {
    TorrentUtils.startTorrentDelete();
    final boolean[] endDone = { false };
    try {
        async.dispatch(new AERunnable() {

            @Override
            public void runSupport() {
                try {
                    // I would move the FLAG_DO_NOT_DELETE_DATA_ON_REMOVE even deeper
                    // but I fear what could possibly go wrong.
                    boolean reallyDeleteData = bDeleteData && !dm.getDownloadState().getFlag(Download.FLAG_DO_NOT_DELETE_DATA_ON_REMOVE);
                    dm.getGlobalManager().removeDownloadManager(dm, bDeleteTorrent, reallyDeleteData);
                } catch (GlobalManagerDownloadRemovalVetoException f) {
                    try {
                        PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface();
                        ShareManager sm = pi.getShareManager();
                        Tracker tracker = pi.getTracker();
                        ShareResource[] shares = sm.getShares();
                        TOTorrent torrent = dm.getTorrent();
                        byte[] target_hash = torrent.getHash();
                        for (ShareResource share : shares) {
                            int type = share.getType();
                            byte[] hash;
                            if (type == ShareResource.ST_DIR) {
                                hash = ((ShareResourceDir) share).getItem().getTorrent().getHash();
                            } else if (type == ShareResource.ST_FILE) {
                                hash = ((ShareResourceFile) share).getItem().getTorrent().getHash();
                            } else {
                                hash = null;
                            }
                            if (hash != null) {
                                if (Arrays.equals(target_hash, hash)) {
                                    try {
                                        dm.stopIt(DownloadManager.STATE_STOPPED, false, false);
                                    } catch (Throwable e) {
                                    }
                                    try {
                                        TrackerTorrent tracker_torrent = tracker.getTorrent(PluginCoreUtils.wrap(torrent));
                                        if (tracker_torrent != null) {
                                            tracker_torrent.stop();
                                        }
                                    } catch (Throwable e) {
                                    }
                                    share.delete();
                                    return;
                                }
                            }
                        }
                    } catch (Throwable e) {
                    }
                    if (!f.isSilent()) {
                        UIFunctionsManager.getUIFunctions().forceNotify(UIFunctions.STATUSICON_WARNING, MessageText.getString("globalmanager.download.remove.veto"), f.getMessage(), null, null, -1);
                    // Logger.log(new LogAlert(dm, false,
                    // "{globalmanager.download.remove.veto}", f));
                    }
                    if (deleteFailed != null) {
                        deleteFailed.runSupport();
                    }
                } catch (Exception ex) {
                    Debug.printStackTrace(ex);
                    if (deleteFailed != null) {
                        deleteFailed.runSupport();
                    }
                } finally {
                    synchronized (endDone) {
                        if (!endDone[0]) {
                            TorrentUtils.endTorrentDelete();
                            endDone[0] = true;
                        }
                    }
                }
            }
        });
    } catch (Throwable e) {
        synchronized (endDone) {
            if (!endDone[0]) {
                TorrentUtils.endTorrentDelete();
                endDone[0] = true;
            }
        }
        Debug.out(e);
    }
}
Also used : Tracker(com.biglybt.pif.tracker.Tracker) GlobalManagerDownloadRemovalVetoException(com.biglybt.core.global.GlobalManagerDownloadRemovalVetoException) PluginInterface(com.biglybt.pif.PluginInterface) PlatformManagerException(com.biglybt.pif.platform.PlatformManagerException) TRHostException(com.biglybt.core.tracker.host.TRHostException) PluginException(com.biglybt.pif.PluginException) GlobalManagerDownloadRemovalVetoException(com.biglybt.core.global.GlobalManagerDownloadRemovalVetoException) TrackerTorrent(com.biglybt.pif.tracker.TrackerTorrent) TOTorrent(com.biglybt.core.torrent.TOTorrent)

Aggregations

PluginInterface (com.biglybt.pif.PluginInterface)2 Tracker (com.biglybt.pif.tracker.Tracker)2 TrackerTorrent (com.biglybt.pif.tracker.TrackerTorrent)2 GlobalManagerDownloadRemovalVetoException (com.biglybt.core.global.GlobalManagerDownloadRemovalVetoException)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TRHostException (com.biglybt.core.tracker.host.TRHostException)1 PluginException (com.biglybt.pif.PluginException)1 Download (com.biglybt.pif.download.Download)1 PlatformManagerException (com.biglybt.pif.platform.PlatformManagerException)1 Torrent (com.biglybt.pif.torrent.Torrent)1 List (java.util.List)1