Search in sources :

Example 1 with GlobalManagerDownloadRemovalVetoException

use of com.biglybt.core.global.GlobalManagerDownloadRemovalVetoException 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

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 PluginInterface (com.biglybt.pif.PluginInterface)1 PlatformManagerException (com.biglybt.pif.platform.PlatformManagerException)1 Tracker (com.biglybt.pif.tracker.Tracker)1 TrackerTorrent (com.biglybt.pif.tracker.TrackerTorrent)1