Search in sources :

Example 6 with TrackerTorrent

use of com.biglybt.pif.tracker.TrackerTorrent 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)

Example 7 with TrackerTorrent

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

the class ShareHosterPlugin method canResourceBeDeleted.

protected void canResourceBeDeleted(ShareResource resource) throws ShareResourceDeletionVetoException {
    Download dl = (Download) resource_dl_map.get(resource);
    if (dl != null) {
        try {
            download_being_removed = dl;
            dl.canBeRemoved();
        } catch (DownloadRemovalVetoException e) {
            throw (new ShareResourceDeletionVetoException(e.getMessage()));
        } finally {
            download_being_removed = null;
        }
    }
    TrackerTorrent tt = (TrackerTorrent) resource_tt_map.get(resource);
    if (tt != null) {
        try {
            torrent_being_removed = tt;
            tt.canBeRemoved();
        } catch (TrackerTorrentRemovalVetoException e) {
            throw (new ShareResourceDeletionVetoException(e.getMessage()));
        } finally {
            torrent_being_removed = null;
        }
    }
}
Also used : TrackerTorrent(com.biglybt.pif.tracker.TrackerTorrent) TrackerTorrentRemovalVetoException(com.biglybt.pif.tracker.TrackerTorrentRemovalVetoException)

Aggregations

TrackerTorrent (com.biglybt.pif.tracker.TrackerTorrent)7 Torrent (com.biglybt.pif.torrent.Torrent)3 PluginInterface (com.biglybt.pif.PluginInterface)2 Tracker (com.biglybt.pif.tracker.Tracker)2 TrackerTorrentRemovalVetoException (com.biglybt.pif.tracker.TrackerTorrentRemovalVetoException)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 TorrentAttribute (com.biglybt.pif.torrent.TorrentAttribute)1 TrackerException (com.biglybt.pif.tracker.TrackerException)1 TrackerTorrentWillBeRemovedListener (com.biglybt.pif.tracker.TrackerTorrentWillBeRemovedListener)1 RPException (com.biglybt.pifimpl.remote.RPException)1 RPObject (com.biglybt.pifimpl.remote.RPObject)1 RPReply (com.biglybt.pifimpl.remote.RPReply)1 RPTorrent (com.biglybt.pifimpl.remote.torrent.RPTorrent)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1