use of com.biglybt.pif.torrent.Torrent in project BiglyBT by BiglySoftware.
the class MySharesView method startStopSelectedShares.
private void startStopSelectedShares(boolean do_stop) {
List items = getSelectedItems();
if (items.size() == 0) {
return;
}
PluginInterface pi = PluginInitializer.getDefaultInterface();
com.biglybt.pif.download.DownloadManager dm = pi.getDownloadManager();
Tracker tracker = pi.getTracker();
for (int i = 0; i < items.size(); i++) {
ShareItem item = (ShareItem) items.get(i);
try {
Torrent t = item.getTorrent();
TrackerTorrent tracker_torrent = tracker.getTorrent(t);
Download download = dm.getDownload(t);
if (download == null) {
continue;
}
int dl_state = download.getState();
if (dl_state == Download.ST_ERROR) {
} else if (dl_state != Download.ST_STOPPED) {
if (do_stop) {
try {
download.stop();
} catch (Throwable e) {
}
if (tracker_torrent != null) {
try {
tracker_torrent.stop();
} catch (Throwable e) {
}
}
}
} else {
if (!do_stop) {
try {
download.restart();
} catch (Throwable e) {
}
if (tracker_torrent != null) {
try {
tracker_torrent.start();
} catch (Throwable e) {
}
}
}
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
}
}
use of com.biglybt.pif.torrent.Torrent in project BiglyBT by BiglySoftware.
the class SubscriptionManagerUI method createSubsColumns.
private void createSubsColumns(TableManager table_manager) {
final TableCellRefreshListener subs_refresh_listener = new TableCellRefreshListener() {
@Override
public void refresh(TableCell _cell) {
TableCellSWT cell = (TableCellSWT) _cell;
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
Download dl = (Download) cell.getDataSource();
if (dl == null) {
return;
}
Torrent torrent = dl.getTorrent();
if (torrent != null) {
Subscription[] subs = subs_man.getKnownSubscriptions(torrent.getHash());
int num_subscribed = 0;
int num_unsubscribed = 0;
for (int i = 0; i < subs.length; i++) {
if (subs[i].isSubscribed()) {
num_subscribed++;
} else {
num_unsubscribed++;
}
}
Graphic graphic;
String tooltip;
int height = cell.getHeight();
int sort_order = 0;
if (subs.length == 0) {
graphic = null;
tooltip = null;
} else {
if (num_subscribed == subs.length) {
graphic = height >= 22 ? icon_rss_all_add_big : icon_rss_all_add_small;
tooltip = MessageText.getString("subscript.all.subscribed");
} else if (num_subscribed > 0) {
graphic = height >= 22 ? icon_rss_some_add_big : icon_rss_some_add_small;
tooltip = MessageText.getString("subscript.some.subscribed");
sort_order = 10000;
} else {
graphic = height >= 22 ? icon_rss_big : icon_rss_small;
tooltip = MessageText.getString("subscript.none.subscribed");
sort_order = 1000000;
}
}
sort_order += 1000 * num_unsubscribed + num_subscribed;
cell.setMarginHeight(0);
cell.setGraphic(graphic);
cell.setToolTip(tooltip);
cell.setSortValue(sort_order);
cell.setCursorID(graphic == null ? SWT.CURSOR_ARROW : SWT.CURSOR_HAND);
} else {
cell.setCursorID(SWT.CURSOR_ARROW);
cell.setSortValue(0);
}
}
};
final TableCellMouseListener subs_mouse_listener = new TableCellMouseListener() {
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN) {
TableCell cell = event.cell;
Download dl = (Download) cell.getDataSource();
Torrent torrent = dl.getTorrent();
if (torrent != null) {
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
Subscription[] subs = subs_man.getKnownSubscriptions(torrent.getHash());
if (subs.length > 0) {
event.skipCoreFunctionality = true;
new SubscriptionWizard(PluginCoreUtils.unwrap(dl));
COConfigurationManager.setParameter("subscriptions.wizard.shown", true);
refreshTitles(mdiEntryOverview);
// new SubscriptionListWindow(PluginCoreUtils.unwrap(dl),true);
}
}
}
}
};
columnCreationSubs = new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn result) {
result.setAlignment(TableColumn.ALIGN_CENTER);
result.setPosition(TableColumn.POSITION_LAST);
result.setWidth(32);
result.setRefreshInterval(TableColumn.INTERVAL_INVALID_ONLY);
result.setType(TableColumn.TYPE_GRAPHIC);
result.addCellRefreshListener(subs_refresh_listener);
result.addCellMouseListener(subs_mouse_listener);
result.setIconReference("image.subscription.column", true);
synchronized (columns) {
columns.add(result);
}
}
};
table_manager.registerColumn(Download.class, "azsubs.ui.column.subs", columnCreationSubs);
final TableCellRefreshListener link_refresh_listener = new TableCellRefreshListener() {
@Override
public void refresh(TableCell _cell) {
TableCellSWT cell = (TableCellSWT) _cell;
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
Download dl = (Download) cell.getDataSource();
if (dl == null) {
return;
}
String str = "";
Torrent torrent = dl.getTorrent();
if (torrent != null) {
byte[] hash = torrent.getHash();
Subscription[] subs = subs_man.getKnownSubscriptions(hash);
for (int i = 0; i < subs.length; i++) {
Subscription sub = subs[i];
if (sub.hasAssociation(hash)) {
str += (str.length() == 0 ? "" : "; ") + sub.getName();
}
}
}
cell.setCursorID(str.length() > 0 ? SWT.CURSOR_HAND : SWT.CURSOR_ARROW);
cell.setText(str);
}
};
final TableCellMouseListener link_mouse_listener = new TableCellMouseListener() {
@Override
public void cellMouseTrigger(TableCellMouseEvent event) {
if (event.eventType == TableCellMouseEvent.EVENT_MOUSEDOWN) {
TableCell cell = event.cell;
Download dl = (Download) cell.getDataSource();
Torrent torrent = dl.getTorrent();
SubscriptionManager subs_man = SubscriptionManagerFactory.getSingleton();
if (torrent != null) {
byte[] hash = torrent.getHash();
Subscription[] subs = subs_man.getKnownSubscriptions(hash);
for (int i = 0; i < subs.length; i++) {
Subscription sub = subs[i];
if (sub.hasAssociation(hash)) {
showSubscriptionMDI(sub);
break;
}
}
}
}
}
};
columnCreationSubsLink = new TableColumnCreationListener() {
@Override
public void tableColumnCreated(TableColumn result) {
result.setAlignment(TableColumn.ALIGN_LEAD);
result.setPosition(TableColumn.POSITION_INVISIBLE);
result.setWidth(85);
result.setRefreshInterval(TableColumn.INTERVAL_INVALID_ONLY);
result.setType(TableColumn.TYPE_TEXT_ONLY);
result.addCellRefreshListener(link_refresh_listener);
result.addCellMouseListener(link_mouse_listener);
result.setMinimumRequiredUserMode(Parameter.MODE_INTERMEDIATE);
synchronized (columns) {
columns.add(result);
}
}
};
table_manager.registerColumn(Download.class, "azsubs.ui.column.subs_link", columnCreationSubsLink);
}
use of com.biglybt.pif.torrent.Torrent in project BiglyBT by BiglySoftware.
the class DownloadRemoveRulesPlugin method handleAnnounceScrapeStatus.
protected void handleAnnounceScrapeStatus(Download download, String status) {
if (!monitored_downloads.contains(download)) {
return;
}
status = status.toLowerCase();
boolean download_completed = download.isComplete();
if (status.contains("not authori") || status.toLowerCase().contains("unauthori")) {
if (remove_unauthorised.getValue() && ((!remove_unauthorised_seeding_only.getValue()) || download_completed)) {
log.log(download.getTorrent(), LoggerChannel.LT_INFORMATION, "Download '" + download.getName() + "' is unauthorised and removal triggered");
removeDownload(download, remove_unauthorised_data.getValue());
return;
}
}
Torrent torrent = download.getTorrent();
if (torrent != null && torrent.getAnnounceURL() != null) {
String url_string = torrent.getAnnounceURL().toString().toLowerCase();
if (url_string.contains(UPDATE_TRACKER)) {
if ((download_completed && status.contains("too many seeds")) || status.contains("too many peers")) {
log.log(download.getTorrent(), LoggerChannel.LT_INFORMATION, "Download '" + download.getName() + "' being removed on instruction from the tracker");
removeDownloadDelayed(download, false);
} else if (download_completed && remove_update_torrents.getValue()) {
long seeds = download.getLastScrapeResult().getSeedCount();
long peers = download.getLastScrapeResult().getNonSeedCount();
if (seeds / (peers == 0 ? 1 : peers) > MAX_SEED_TO_PEER_RATIO) {
log.log(download.getTorrent(), LoggerChannel.LT_INFORMATION, "Download '" + download.getName() + "' being removed to reduce swarm size");
removeDownloadDelayed(download, false);
} else {
long creation_time = download.getCreationTime();
long running_mins = (SystemTime.getCurrentTime() - creation_time) / (60 * 1000);
if (running_mins > 15) {
// big is a relative term here and generally distinguishes between core updates
// and plugin updates
boolean big_torrent = torrent.getSize() > 1024 * 1024;
if ((seeds > AELITIS_BIG_TORRENT_SEED_LIMIT && big_torrent) || (seeds > AELITIS_SMALL_TORRENT_SEED_LIMIT && !big_torrent)) {
log.log("Download '" + download.getName() + "' being removed to reduce swarm size");
removeDownloadDelayed(download, false);
}
}
}
}
}
}
}
use of com.biglybt.pif.torrent.Torrent in project BiglyBT by BiglySoftware.
the class UISWTInstanceImpl method eventOccurred.
@Override
public boolean eventOccurred(final UIManagerEvent event) {
boolean done = true;
final Object data = event.getData();
switch(event.getType()) {
case UIManagerEvent.ET_SHOW_TEXT_MESSAGE:
{
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
String[] params = (String[]) data;
new TextViewerWindow(params[0], params[1], params[2]);
}
});
break;
}
case UIManagerEvent.ET_SHOW_MSG_BOX:
{
final int[] result = { UIManagerEvent.MT_NONE };
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
uiFunctions.bringToFront();
Object[] params = (Object[]) data;
long _styles = ((Long) (params[2])).longValue();
int styles = 0;
int def = 0;
if ((_styles & UIManagerEvent.MT_YES) != 0) {
styles |= SWT.YES;
}
if ((_styles & UIManagerEvent.MT_YES_DEFAULT) != 0) {
styles |= SWT.YES;
def = SWT.YES;
}
if ((_styles & UIManagerEvent.MT_NO) != 0) {
styles |= SWT.NO;
}
if ((_styles & UIManagerEvent.MT_NO_DEFAULT) != 0) {
styles |= SWT.NO;
def = SWT.NO;
}
if ((_styles & UIManagerEvent.MT_OK) != 0) {
styles |= SWT.OK;
}
if ((_styles & UIManagerEvent.MT_OK_DEFAULT) != 0) {
styles |= SWT.OK;
def = SWT.OK;
}
if ((_styles & UIManagerEvent.MT_CANCEL) != 0) {
styles |= SWT.CANCEL;
}
MessageBoxShell mb = new MessageBoxShell(styles, MessageText.getString((String) params[0]), MessageText.getString((String) params[1]));
if (def != 0) {
mb.setDefaultButtonUsingStyle(def);
}
if (params.length == 4 && params[3] instanceof Map) {
Map<String, Object> options = (Map<String, Object>) params[3];
String rememberID = (String) options.get(UIManager.MB_PARAM_REMEMBER_ID);
Boolean rememberByDefault = (Boolean) options.get(UIManager.MB_PARAM_REMEMBER_BY_DEF);
String rememberText = (String) options.get(UIManager.MB_PARAM_REMEMBER_RES);
if (rememberID != null && rememberByDefault != null && rememberText != null) {
mb.setRemember(rememberID, rememberByDefault, rememberText);
Number rememberIfOnlyButton = (Number) options.get(UIManager.MB_PARAM_REMEMBER_IF_ONLY_BUTTON);
if (rememberIfOnlyButton != null) {
mb.setRememberOnlyIfButton(rememberIfOnlyButton.intValue());
}
}
Number auto_close_ms = (Number) options.get(UIManager.MB_PARAM_AUTO_CLOSE_MS);
if (auto_close_ms != null) {
mb.setAutoCloseInMS(auto_close_ms.intValue());
}
} else if (params.length >= 6) {
String rememberID = (String) params[3];
Boolean rememberByDefault = (Boolean) params[4];
String rememberText = (String) params[5];
if (rememberID != null && rememberByDefault != null && rememberText != null) {
mb.setRemember(rememberID, rememberByDefault, rememberText);
}
}
mb.open(null);
int _r = mb.waitUntilClosed();
int r = 0;
if ((_r & SWT.YES) != 0) {
r |= UIManagerEvent.MT_YES;
}
if ((_r & SWT.NO) != 0) {
r |= UIManagerEvent.MT_NO;
}
if ((_r & SWT.OK) != 0) {
r |= UIManagerEvent.MT_OK;
}
if ((_r & SWT.CANCEL) != 0) {
r |= UIManagerEvent.MT_CANCEL;
}
result[0] = r;
}
}, false);
event.setResult(new Long(result[0]));
break;
}
case UIManagerEvent.ET_OPEN_TORRENT_VIA_FILE:
{
TorrentOpener.openTorrent(((File) data).toString());
break;
}
case UIManagerEvent.ET_OPEN_TORRENT_VIA_TORRENT:
{
Torrent t = (Torrent) data;
try {
File f = AETemporaryFileHandler.createTempFile();
t.writeToFile(f);
TorrentOpener.openTorrent(f.toString());
} catch (Throwable e) {
Debug.printStackTrace(e);
}
break;
}
case UIManagerEvent.ET_OPEN_TORRENT_VIA_URL:
{
Display display = Utils.getDisplay();
display.syncExec(new AERunnable() {
@Override
public void runSupport() {
Object[] params = (Object[]) data;
URL target = (URL) params[0];
URL referrer = (URL) params[1];
boolean auto_download = ((Boolean) params[2]).booleanValue();
Map<?, ?> request_properties = (Map<?, ?>) params[3];
if (auto_download) {
final Shell shell = uiFunctions.getMainShell();
if (shell != null) {
final List<String> alt_uris = new ArrayList<>();
if (request_properties != null) {
request_properties = new HashMap(request_properties);
for (int i = 1; i < 16; i++) {
String key = "X-Alternative-URI-" + i;
String uri = (String) request_properties.remove(key);
if (uri != null) {
alt_uris.add(uri);
} else {
break;
}
}
}
final Map<?, ?> f_request_properties = request_properties;
new FileDownloadWindow(shell, target.toString(), referrer == null ? null : referrer.toString(), request_properties, new Runnable() {
int alt_index = 0;
@Override
public void run() {
if (alt_index < alt_uris.size()) {
String alt_target = alt_uris.get(alt_index++);
new FileDownloadWindow(shell, alt_target, null, f_request_properties, this);
}
}
});
}
} else {
// TODO: handle referrer?
TorrentOpener.openTorrent(target.toString());
}
}
});
break;
}
case UIManagerEvent.ET_PLUGIN_VIEW_MODEL_CREATED:
{
if (data instanceof BasicPluginViewModel) {
BasicPluginViewModel model = (BasicPluginViewModel) data;
// property bundles can't handle spaces in keys
//
// If this behaviour changes, change the openView(model)
// method lower down.
String sViewID = model.getName().replace(' ', '.');
UISWTInstance ui = getInstance(model.getPluginInterface());
ui.registerView(UISWTInstance.VIEW_MAIN, ui.createViewBuilder(sViewID, BasicPluginViewImpl.class).setInitialDatasource(data));
}
break;
}
case UIManagerEvent.ET_PLUGIN_VIEW_MODEL_DESTROYED:
{
if (data instanceof BasicPluginViewModel) {
BasicPluginViewModel model = (BasicPluginViewModel) data;
// property bundles can't handle spaces in keys
//
// If this behaviour changes, change the openView(model)
// method lower down.
String sViewID = model.getName().replace(' ', '.');
removeViews(UISWTInstance.VIEW_MAIN, sViewID);
}
break;
}
case UIManagerEvent.ET_COPY_TO_CLIPBOARD:
{
ClipboardCopy.copyToClipBoard((String) data, event.getPluginInterface());
break;
}
case UIManagerEvent.ET_OPEN_URL:
{
Utils.launch(((URL) data).toExternalForm());
break;
}
case UIManagerEvent.ET_SHOW_CONFIG_SECTION:
{
event.setResult(Boolean.FALSE);
if (!(data instanceof String)) {
break;
}
event.setResult(Boolean.TRUE);
uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_CONFIG, data);
break;
}
case UIManagerEvent.ET_FILE_OPEN:
{
File file_to_use = (File) data;
Utils.launch(file_to_use.getAbsolutePath());
break;
}
case UIManagerEvent.ET_FILE_SHOW:
{
File file_to_use = (File) data;
final boolean use_open_containing_folder = COConfigurationManager.getBooleanParameter("MyTorrentsView.menu.show_parent_folder_enabled");
ManagerUtils.open(file_to_use, use_open_containing_folder);
break;
}
case UIManagerEvent.ET_HIDE_ALL:
{
boolean hide = (Boolean) data;
uiFunctions.setHideAll(hide);
break;
}
case UIManagerEvent.ET_HIDE_ALL_TOGGLE:
{
uiFunctions.setHideAll(!uiFunctions.getHideAll());
break;
}
default:
{
done = false;
break;
}
}
return (done);
}
use of com.biglybt.pif.torrent.Torrent in project BiglyBT by BiglySoftware.
the class NetworkAdminSpeedTesterBTImpl method start.
/**
* The downloads have been stopped just need to do the testing.
* @param tot - Torrent recieved from testing service.
*/
public synchronized void start(TOTorrent tot) {
if (test_started) {
Debug.out("Test already started!");
return;
}
test_started = true;
// OK lets start the test.
try {
TorrentUtils.setFlag(tot, TorrentUtils.TORRENT_FLAG_LOW_NOISE, true);
Torrent torrent = new TorrentImpl(tot);
String fileName = torrent.getName();
sendStageUpdateToListeners(MessageText.getString("SpeedTestWizard.stage.message.preparing"));
// create a blank file of specified size. (using the temporary name.)
File saveLocation = AETemporaryFileHandler.createTempFile();
File baseDir = saveLocation.getParentFile();
File blankFile = FileUtil.newFile(baseDir, fileName);
File blankTorrentFile = FileUtil.newFile(baseDir, "speedTestTorrent.torrent");
torrent.writeToFile(blankTorrentFile);
URL announce_url = torrent.getAnnounceURL();
if (announce_url.getProtocol().equalsIgnoreCase("https")) {
SESecurityManager.setCertificateHandler(announce_url, new SECertificateListener() {
@Override
public boolean trustCertificate(String resource, X509Certificate cert) {
return (true);
}
});
}
Download speed_download = plugin.getDownloadManager().addDownloadStopped(torrent, blankTorrentFile, blankFile);
speed_download.setBooleanAttribute(speedTestAttrib, true);
DownloadManager core_download = PluginCoreUtils.unwrap(speed_download);
core_download.setPieceCheckingEnabled(false);
// make sure we've got a bunch of upload slots
core_download.getDownloadState().setIntParameter(DownloadManagerState.PARAM_MAX_UPLOADS, 32);
core_download.getDownloadState().setIntParameter(DownloadManagerState.PARAM_MAX_UPLOADS_WHEN_SEEDING, 32);
if (use_crypto) {
core_download.setCryptoLevel(NetworkManager.CRYPTO_OVERRIDE_REQUIRED);
}
core_download.addPeerListener(new DownloadManagerPeerListener() {
@Override
public void peerManagerWillBeAdded(PEPeerManager peer_manager) {
DiskManager disk_manager = peer_manager.getDiskManager();
DiskManagerPiece[] pieces = disk_manager.getPieces();
int startPiece = setStartPieceBasedOnMode(testMode, pieces.length);
for (int i = startPiece; i < pieces.length; i++) {
pieces[i].setDone(true);
}
}
@Override
public void peerManagerAdded(PEPeerManager peer_manager) {
}
@Override
public void peerManagerRemoved(PEPeerManager manager) {
}
@Override
public void peerAdded(PEPeer peer) {
}
@Override
public void peerRemoved(PEPeer peer) {
}
});
speed_download.moveTo(1);
speed_download.setFlag(Download.FLAG_DISABLE_AUTO_FILE_MOVE, true);
speed_download.setFlag(Download.FLAG_DISABLE_STOP_AFTER_ALLOC, true);
core_download.initialize();
core_download.setForceStart(true);
TorrentSpeedTestMonitorThread monitor = new TorrentSpeedTestMonitorThread(speed_download);
monitor.start();
// The test has now started!!
} catch (Throwable e) {
test_completed = true;
abort("Could not start test", e);
}
}
Aggregations