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);
}
}
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;
}
}
}
Aggregations