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