use of com.biglybt.pif.tracker.TrackerTorrentRemovalVetoException in project BiglyBT by BiglySoftware.
the class ShareHosterPlugin method resourceAdded.
@Override
public void resourceAdded(final ShareResource resource) {
log.log(LoggerChannel.LT_INFORMATION, "Resource added:".concat(resource.getName()));
try {
resource.addDeletionListener(new ShareResourceWillBeDeletedListener() {
@Override
public void resourceWillBeDeleted(ShareResource resource) throws ShareResourceDeletionVetoException {
canResourceBeDeleted(resource);
}
});
Download new_download = null;
int type = resource.getType();
if (type == ShareResource.ST_FILE) {
ShareResourceFile file_resource = (ShareResourceFile) resource;
ShareItem item = file_resource.getItem();
Torrent torrent = item.getTorrent();
Download download = download_manager.getDownload(torrent);
if (download == null) {
new_download = addDownload(resource, torrent, item.getTorrentFile(), file_resource.getFile());
}
} else if (type == ShareResource.ST_DIR) {
ShareResourceDir dir_resource = (ShareResourceDir) resource;
ShareItem item = dir_resource.getItem();
Torrent torrent = item.getTorrent();
Download download = download_manager.getDownload(torrent);
if (download == null) {
new_download = addDownload(resource, torrent, item.getTorrentFile(), dir_resource.getDir());
}
}
if (new_download != null) {
final Download f_new_download = new_download;
resource_dl_map.put(resource, new_download);
resource.addChangeListener(new ShareResourceListener() {
@Override
public void shareResourceChanged(ShareResource resource, ShareResourceEvent event) {
if (event.getType() == ShareResourceEvent.ET_ATTRIBUTE_CHANGED) {
TorrentAttribute attribute = (TorrentAttribute) event.getData();
// System.out.println( "sh: res -> ds: " + attribute.getName() + "/" + resource.getAttribute( attribute ));
f_new_download.setAttribute(attribute, resource.getAttribute(attribute));
}
}
});
TorrentAttribute[] attributes = resource.getAttributes();
for (int i = 0; i < attributes.length; i++) {
TorrentAttribute ta = attributes[i];
new_download.setAttribute(ta, resource.getAttribute(ta));
}
new_download.addAttributeListener(new DownloadAttributeListener() {
@Override
public void attributeEventOccurred(Download d, TorrentAttribute attr, int event_type) {
resource.setAttribute(attr, d.getAttribute(attr));
}
}, plugin_interface.getTorrentManager().getAttribute(TorrentAttribute.TA_CATEGORY), DownloadAttributeListener.WRITTEN);
boolean persistent = resource.isPersistent();
Torrent dl_torrent = new_download.getTorrent();
if (dl_torrent != null) {
TrackerTorrent tt = tracker.host(dl_torrent, persistent);
if (!persistent) {
tt.addRemovalListener(new TrackerTorrentWillBeRemovedListener() {
@Override
public void torrentWillBeRemoved(TrackerTorrent tt) throws TrackerTorrentRemovalVetoException {
if (tt != torrent_being_removed) {
throw (new TrackerTorrentRemovalVetoException(MessageText.getString("plugin.sharing.torrent.remove.veto")));
}
}
});
}
resource_tt_map.put(resource, tt);
}
if (!persistent) {
new_download.addDownloadWillBeRemovedListener(new DownloadWillBeRemovedListener() {
@Override
public void downloadWillBeRemoved(Download dl) throws DownloadRemovalVetoException {
if (dl != download_being_removed) {
throw (new DownloadRemovalVetoException(MessageText.getString("plugin.sharing.download.remove.veto")));
}
}
});
}
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
use of com.biglybt.pif.tracker.TrackerTorrentRemovalVetoException 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