Search in sources :

Example 11 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class BuddyPluginView method checkBetaInit.

private void checkBetaInit() {
    if (plugin.isBetaEnabled() && plugin.getBeta().isAvailable()) {
        synchronized (this) {
            if (beta_init_done) {
                return;
            }
            beta_init_done = true;
        }
        MenuManager menu_manager = plugin.getPluginInterface().getUIManager().getMenuManager();
        MenuItem chat_item = menu_manager.addMenuItem(MenuManager.MENU_DOWNLOAD_CONTEXT, "label.chat");
        chat_item.setDisposeWithUIDetach(UIInstance.UIT_SWT);
        chat_item.setHeaderCategory(MenuItem.HEADER_SOCIAL);
        final MenuItem mi_chat = MenuBuildUtils.addChatMenu(menu_manager, chat_item, new MenuBuildUtils.ChatKeyResolver() {

            @Override
            public String getResourceKey() {
                return ("menu.discuss.download");
            }

            @Override
            public String getChatKey(Object object) {
                return (BuddyPluginUtils.getChatKey((Download) object));
            }

            @Override
            public boolean canShareMessage() {
                return (true);
            }

            @Override
            public void shareMessage(Object target, ChatInstance chat) {
                if (target instanceof Download) {
                    Download dl = (Download) target;
                    chat.sendMessage(dl);
                } else {
                    Download[] dls = (Download[]) target;
                    for (Download dl : dls) {
                        chat.sendMessage(dl);
                    }
                }
            }
        });
        addBetaSubviews(true);
        beta_status = ui_instance.createStatusEntry();
        beta_status.setImageEnabled(true);
        beta_status.setVisible(true);
        updateIdleTT(false);
        Utils.execSWTThread(new AERunnable() {

            @Override
            public void runSupport() {
                ImageLoader imageLoader = ImageLoader.getInstance();
                bs_chat_gray = imageLoader.getImage("dchat_gray");
                bs_chat_gray_text = imageLoader.getImage("dchat_gray_text");
                bs_chat_green = imageLoader.getImage("dchat_green");
                bs_chat_red = imageLoader.getImage("dchat_red");
                bs_chat_swarm_merge = imageLoader.getImage("dchat_swarm_merge");
                setBetaStatus(bs_chat_gray);
                mi_chat.setGraphic(ui_instance.createGraphic(bs_chat_gray));
            }
        });
        beta_status.setListener(new UISWTStatusEntryListener() {

            @Override
            public void entryClicked(UISWTStatusEntry entry) {
                Set<ChatInstance> current_instances = menu_latest_instances;
                // might be a lot of chats, just pick first 10
                int rem = 10;
                for (ChatInstance chat : current_instances) {
                    if (chat.getMessageOutstanding()) {
                        try {
                            openChat(chat.getClone());
                            rem--;
                            if (rem == 0) {
                                break;
                            }
                        } catch (Throwable e) {
                            Debug.out(e);
                        }
                    }
                }
            }
        });
        periodicEventMsgCheck = SimpleTimer.addPeriodicEvent("msgcheck", 30 * 1000, new TimerEventPerformer() {

            @Override
            public void perform(TimerEvent event) {
                List<ChatInstance> chats = plugin.getBeta().getChats();
                Map<ChatInstance, ChatMessage> pending = new HashMap<>();
                synchronized (pending_msg_map) {
                    for (ChatInstance chat : chats) {
                        if (chat.isInvisible()) {
                            continue;
                        }
                        if (!chat_uis.containsKey(chat)) {
                            if (chat.isFavourite() || chat.isAutoNotify() || chat.isInteresting()) {
                                if (!chat.isStatistics()) {
                                    ChatMessage last_msg = chat.getLastMessageRequiringAttention();
                                    if (last_msg != null) {
                                        ChatMessage last_handled = (ChatMessage) chat.getUserData(CHAT_LM_KEY);
                                        long last_msg_time = last_msg.getTimeStamp();
                                        if (last_handled == null || last_msg_time > last_handled.getTimeStamp()) {
                                            chat.setUserData(CHAT_LM_KEY, last_msg);
                                            pending.put(chat, last_msg);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!pending.isEmpty()) {
                        betaMessagesPending(pending);
                    }
                    updateIdleTT(false);
                }
            }
        });
    }
}
Also used : ChatInstance(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance) ChatMessage(com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatMessage) MenuItem(com.biglybt.pif.ui.menus.MenuItem) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader) Download(com.biglybt.pif.download.Download) MenuBuildUtils(com.biglybt.ui.swt.MenuBuildUtils)

Example 12 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class DownloadManagerImpl method getTrackerPeerSources.

@Override
public List<TrackerPeerSource> getTrackerPeerSources() {
    try {
        this_mon.enter();
        Object[] tps_data = (Object[]) getUserData(TPS_Key);
        List<TrackerPeerSource> tps;
        if (tps_data == null) {
            tps = new ArrayList<>();
            TOTorrentListener tol = new TOTorrentListener() {

                @Override
                public void torrentChanged(TOTorrent torrent, int type) {
                    if (type == TOTorrentListener.CT_ANNOUNCE_URLS) {
                        torrent.removeListener(this);
                        informTPSChanged();
                    }
                }
            };
            setUserData(TPS_Key, new Object[] { tps, tol });
            Download plugin_download = PluginCoreUtils.wrap(this);
            if (isDestroyed() || plugin_download == null) {
                return (tps);
            }
            // tracker peer sources
            final TOTorrent t = getTorrent();
            if (t != null) {
                t.addListener(tol);
                TOTorrentAnnounceURLSet[] sets = t.getAnnounceURLGroup().getAnnounceURLSets();
                if (sets.length == 0) {
                    sets = new TOTorrentAnnounceURLSet[] { t.getAnnounceURLGroup().createAnnounceURLSet(new URL[] { torrent.getAnnounceURL() }) };
                }
                for (final TOTorrentAnnounceURLSet set : sets) {
                    final URL[] urls = set.getAnnounceURLs();
                    if (urls.length == 0 || TorrentUtils.isDecentralised(urls[0])) {
                        continue;
                    }
                    tps.add(new TrackerPeerSource() {

                        private TrackerPeerSource _delegate;

                        private TRTrackerAnnouncer ta;

                        private long ta_fixup;

                        private long last_scrape_fixup_time;

                        private Object[] last_scrape;

                        private TrackerPeerSource fixup() {
                            long now = SystemTime.getMonotonousTime();
                            if (now - ta_fixup > 1000) {
                                TRTrackerAnnouncer current_ta = getTrackerClient();
                                if (current_ta == ta) {
                                    if (current_ta != null && _delegate == null) {
                                        _delegate = current_ta.getTrackerPeerSource(set);
                                    }
                                } else {
                                    if (current_ta == null) {
                                        _delegate = null;
                                    } else {
                                        _delegate = current_ta.getTrackerPeerSource(set);
                                    }
                                    ta = current_ta;
                                }
                                ta_fixup = now;
                            }
                            return (_delegate);
                        }

                        protected Object[] getScrape() {
                            long now = SystemTime.getMonotonousTime();
                            if (now - last_scrape_fixup_time > 30 * 1000 || last_scrape == null) {
                                TRTrackerScraper scraper = globalManager.getTrackerScraper();
                                int max_peers = -1;
                                int max_seeds = -1;
                                int max_comp = -1;
                                int max_time = 0;
                                int min_scrape = Integer.MAX_VALUE;
                                String status_str = null;
                                boolean found_usable = false;
                                for (URL u : urls) {
                                    TRTrackerScraperResponse resp = scraper.peekScrape(torrent, u);
                                    if (resp != null) {
                                        if (!resp.isDHTBackup()) {
                                            found_usable = true;
                                            int peers = resp.getPeers();
                                            int seeds = resp.getSeeds();
                                            int comp = resp.getCompleted();
                                            if (peers > max_peers) {
                                                max_peers = peers;
                                            }
                                            if (seeds > max_seeds) {
                                                max_seeds = seeds;
                                            }
                                            if (comp > max_comp) {
                                                max_comp = comp;
                                            }
                                            status_str = resp.getStatusString();
                                            if (resp.getStatus() != TRTrackerScraperResponse.ST_INITIALIZING) {
                                                int time = resp.getScrapeTime();
                                                if (time > max_time) {
                                                    max_time = time;
                                                }
                                                long next_scrape = resp.getNextScrapeStartTime();
                                                if (next_scrape > 0) {
                                                    int ns = (int) (next_scrape / 1000);
                                                    if (ns < min_scrape) {
                                                        min_scrape = ns;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (found_usable || last_scrape == null) {
                                    last_scrape = new Object[] { max_seeds, max_peers, max_time, min_scrape, max_comp, status_str };
                                }
                                last_scrape_fixup_time = now;
                            }
                            return (last_scrape);
                        }

                        @Override
                        public int getType() {
                            return (TrackerPeerSource.TP_TRACKER);
                        }

                        @Override
                        public String getName() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return (urls[0].toExternalForm());
                            }
                            return (delegate.getName());
                        }

                        @Override
                        public URL getURL() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return (urls[0]);
                            }
                            return (delegate.getURL());
                        }

                        @Override
                        public int getStatus() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return (ST_STOPPED);
                            }
                            return (delegate.getStatus());
                        }

                        @Override
                        public String getStatusString() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return ((String) getScrape()[5]);
                            }
                            return (delegate.getStatusString());
                        }

                        @Override
                        public int getSeedCount() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return ((Integer) getScrape()[0]);
                            }
                            int seeds = delegate.getSeedCount();
                            if (seeds < 0) {
                                seeds = (Integer) getScrape()[0];
                            }
                            return (seeds);
                        }

                        @Override
                        public int getLeecherCount() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return ((Integer) getScrape()[1]);
                            }
                            int leechers = delegate.getLeecherCount();
                            if (leechers < 0) {
                                leechers = (Integer) getScrape()[1];
                            }
                            return (leechers);
                        }

                        @Override
                        public int getCompletedCount() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return ((Integer) getScrape()[4]);
                            }
                            int comp = delegate.getCompletedCount();
                            if (comp < 0) {
                                comp = (Integer) getScrape()[4];
                            }
                            return (comp);
                        }

                        @Override
                        public int getPeers() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return (-1);
                            }
                            return (delegate.getPeers());
                        }

                        @Override
                        public int getInterval() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                Object[] si = getScrape();
                                int last = (Integer) si[2];
                                int next = (Integer) si[3];
                                if (last > 0 && next < Integer.MAX_VALUE && last < next) {
                                    return (next - last);
                                }
                                return (-1);
                            }
                            return (delegate.getInterval());
                        }

                        @Override
                        public int getMinInterval() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return (-1);
                            }
                            return (delegate.getMinInterval());
                        }

                        @Override
                        public boolean isUpdating() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return (false);
                            }
                            return (delegate.isUpdating());
                        }

                        @Override
                        public int getLastUpdate() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return ((Integer) getScrape()[2]);
                            }
                            return (delegate.getLastUpdate());
                        }

                        @Override
                        public int getSecondsToUpdate() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                int next = (Integer) getScrape()[3];
                                if (next < Integer.MAX_VALUE) {
                                    return ((int) (next - (SystemTime.getCurrentTime() / 1000)));
                                }
                                return (Integer.MIN_VALUE);
                            }
                            return (delegate.getSecondsToUpdate());
                        }

                        @Override
                        public boolean canManuallyUpdate() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate == null) {
                                return (false);
                            }
                            return (delegate.canManuallyUpdate());
                        }

                        @Override
                        public void manualUpdate() {
                            TrackerPeerSource delegate = fixup();
                            if (delegate != null) {
                                delegate.manualUpdate();
                            }
                        }

                        @Override
                        public long[] getReportedStats() {
                            TrackerPeerSource delegate = fixup();
                            URL url = getURL();
                            long[] url_stats = stats.getTrackerReportedStats(url);
                            long session_up = 0;
                            long session_down = 0;
                            if (delegate != null) {
                                long[] session = delegate.getReportedStats();
                                if (session == null) {
                                    return (null);
                                }
                                session_up = session[0];
                                session_down = session[1];
                            }
                            return (new long[] { url_stats[0], url_stats[1], url_stats[2], url_stats[3], session_up, session_down });
                        }

                        @Override
                        public String getDetails() {
                            URL url = getURL();
                            String key = all_trackers.ingestURL(url);
                            if (torrent.getAnnounceURLGroup().getUID() != url_group_map_uid) {
                                buildURLGroupMap(torrent);
                            }
                            Map<String, Object[]> map = url_group_map;
                            Object[] entry = map.get(key);
                            if (entry != null) {
                                String str = MessageText.getString("wizard.multitracker.group");
                                long total_sent = 0;
                                long total_received = 0;
                                String sent_str = MessageText.getString("DHTView.transport.sent");
                                String recv_str = MessageText.getString("DHTView.transport.received");
                                for (Map.Entry<String, Object[]> e : map.entrySet()) {
                                    Object[] temp = e.getValue();
                                    if (temp[1] == entry[1]) {
                                        URL u = (URL) temp[0];
                                        long[] url_stats = stats.getTrackerReportedStats(u);
                                        long sent = url_stats[2];
                                        long received = url_stats[3];
                                        total_sent += sent;
                                        total_received += received;
                                        str += "\n\t" + u + ": " + sent_str + "=" + DisplayFormatters.formatByteCountToKiBEtc(sent) + ", " + recv_str + "=" + DisplayFormatters.formatByteCountToKiBEtc(received);
                                    }
                                }
                                str += "\n\t" + MessageText.getString("SpeedView.stats.total") + ": " + sent_str + "=" + DisplayFormatters.formatByteCountToKiBEtc(total_sent) + ", " + recv_str + "=" + DisplayFormatters.formatByteCountToKiBEtc(total_received);
                                return (str);
                            }
                            return (null);
                        }

                        @Override
                        public boolean canDelete() {
                            return (true);
                        }

                        @Override
                        public void delete() {
                            List<List<String>> lists = TorrentUtils.announceGroupsToList(t);
                            List<String> rem = new ArrayList<>();
                            for (URL u : urls) {
                                rem.add(u.toExternalForm());
                            }
                            lists = TorrentUtils.removeAnnounceURLs2(lists, rem, false);
                            TorrentUtils.listToAnnounceGroups(lists, t);
                        }
                    });
                }
                // cache peer source
                tps.add(new TrackerPeerSourceAdapter() {

                    private TrackerPeerSource _delegate;

                    private TRTrackerAnnouncer ta;

                    private boolean enabled;

                    private long ta_fixup;

                    private TrackerPeerSource fixup() {
                        long now = SystemTime.getMonotonousTime();
                        if (now - ta_fixup > 1000) {
                            TRTrackerAnnouncer current_ta = getTrackerClient();
                            if (current_ta == ta) {
                                if (current_ta != null && _delegate == null) {
                                    _delegate = current_ta.getCacheTrackerPeerSource();
                                }
                            } else {
                                if (current_ta == null) {
                                    _delegate = null;
                                } else {
                                    _delegate = current_ta.getCacheTrackerPeerSource();
                                }
                                ta = current_ta;
                            }
                            enabled = controller.isPeerSourceEnabled(PEPeerSource.PS_BT_TRACKER);
                            ta_fixup = now;
                        }
                        return (_delegate);
                    }

                    @Override
                    public int getType() {
                        return (TrackerPeerSource.TP_TRACKER);
                    }

                    @Override
                    public String getName() {
                        TrackerPeerSource delegate = fixup();
                        if (delegate == null) {
                            return (MessageText.getString("tps.tracker.cache"));
                        }
                        return (delegate.getName());
                    }

                    @Override
                    public URL getURL() {
                        TrackerPeerSource delegate = fixup();
                        if (delegate == null) {
                            return (null);
                        }
                        return (delegate.getURL());
                    }

                    @Override
                    public int getStatus() {
                        TrackerPeerSource delegate = fixup();
                        if (!enabled) {
                            return (ST_DISABLED);
                        }
                        if (delegate == null) {
                            return (ST_STOPPED);
                        }
                        return (ST_ONLINE);
                    }

                    @Override
                    public int getPeers() {
                        TrackerPeerSource delegate = fixup();
                        if (delegate == null || !enabled) {
                            return (-1);
                        }
                        return (delegate.getPeers());
                    }
                });
            }
            try {
                ExternalSeedPlugin esp = DownloadManagerController.getExternalSeedPlugin();
                if (esp != null) {
                    tps.add(esp.getTrackerPeerSource(plugin_download));
                }
            } catch (Throwable e) {
            }
            try {
                PluginInterface dht_pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass(DHTTrackerPlugin.class);
                if (dht_pi != null) {
                    tps.add(((DHTTrackerPlugin) dht_pi.getPlugin()).getTrackerPeerSource(plugin_download));
                }
            } catch (Throwable e) {
            }
            try {
                PluginInterface lt_pi = CoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass(LocalTrackerPlugin.class);
                if (lt_pi != null) {
                    tps.add(((LocalTrackerPlugin) lt_pi.getPlugin()).getTrackerPeerSource(plugin_download));
                }
            } catch (Throwable e) {
            }
            try {
                tps.addAll(Arrays.asList(((DownloadImpl) plugin_download).getTrackerPeerSources()));
            } catch (Throwable e) {
            }
            // PEX...
            tps.add(new TrackerPeerSourceAdapter() {

                private PEPeerManager _pm;

                private TrackerPeerSource _delegate;

                private TrackerPeerSource fixup() {
                    PEPeerManager pm = getPeerManager();
                    if (pm == null) {
                        _delegate = null;
                        _pm = null;
                    } else if (pm != _pm) {
                        _pm = pm;
                        _delegate = pm.getTrackerPeerSource();
                    }
                    return (_delegate);
                }

                @Override
                public int getType() {
                    return (TP_PEX);
                }

                @Override
                public int getStatus() {
                    TrackerPeerSource delegate = fixup();
                    if (delegate == null) {
                        return (ST_STOPPED);
                    } else {
                        return (delegate.getStatus());
                    }
                }

                @Override
                public String getName() {
                    TrackerPeerSource delegate = fixup();
                    if (delegate == null) {
                        return ("");
                    } else {
                        return (delegate.getName());
                    }
                }

                @Override
                public String getStatusString() {
                    if (getStatus() == TrackerPeerSource.ST_DISABLED) {
                        try {
                            if (torrent.getPrivate()) {
                                return (MessageText.getString("label.private"));
                            }
                        } catch (Throwable e) {
                        }
                    }
                    return (null);
                }

                @Override
                public int getPeers() {
                    TrackerPeerSource delegate = fixup();
                    if (delegate == null) {
                        return (-1);
                    } else {
                        return (delegate.getPeers());
                    }
                }
            });
            // incoming
            tps.add(new TrackerPeerSourceAdapter() {

                private long fixup_time;

                private PEPeerManager _pm;

                private int tcp;

                private int udp;

                private int utp;

                private int total;

                private boolean enabled;

                private PEPeerManager fixup() {
                    long now = SystemTime.getMonotonousTime();
                    if (now - fixup_time > 1000) {
                        PEPeerManager pm = _pm = getPeerManager();
                        if (pm != null) {
                            tcp = pm.getNbRemoteTCPConnections();
                            udp = pm.getNbRemoteUDPConnections();
                            utp = pm.getNbRemoteUTPConnections();
                            total = pm.getStats().getTotalIncomingConnections();
                        }
                        enabled = controller.isPeerSourceEnabled(PEPeerSource.PS_INCOMING);
                        fixup_time = now;
                    }
                    return (_pm);
                }

                @Override
                public int getType() {
                    return (TP_INCOMING);
                }

                @Override
                public int getStatus() {
                    if (!enabled) {
                        return (ST_DISABLED);
                    }
                    PEPeerManager delegate = fixup();
                    if (delegate == null) {
                        if (_tracker_client_for_queued_download == null) {
                            return (ST_STOPPED);
                        } else {
                            return (ST_ONLINE);
                        }
                    } else {
                        return (ST_ONLINE);
                    }
                }

                @Override
                public String getName() {
                    PEPeerManager delegate = fixup();
                    if (delegate == null || !enabled) {
                        return ("");
                    } else {
                        return (MessageText.getString("tps.incoming.details", new String[] { String.valueOf(tcp), String.valueOf(udp + utp), String.valueOf(total) }));
                    }
                }

                @Override
                public int getPeers() {
                    PEPeerManager delegate = fixup();
                    if (delegate == null || !enabled) {
                        return (-1);
                    } else {
                        return (tcp + udp);
                    }
                }
            });
        } else {
            tps = (List<TrackerPeerSource>) tps_data[0];
        }
        return (tps);
    } finally {
        this_mon.exit();
    }
}
Also used : TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource) DownloadImpl(com.biglybt.pifimpl.local.download.DownloadImpl) URL(java.net.URL) Download(com.biglybt.pif.download.Download) TrackerPeerSourceAdapter(com.biglybt.core.tracker.TrackerPeerSourceAdapter) PluginInterface(com.biglybt.pif.PluginInterface) ExternalSeedPlugin(com.biglybt.plugin.extseed.ExternalSeedPlugin)

Example 13 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class TagDownloadWithState method performOperation.

private void performOperation(int op, Set<DownloadManager> dms) {
    for (final DownloadManager dm : dms) {
        int dm_state = dm.getState();
        if (op == TagFeatureRunState.RSC_START) {
            if (dm_state == DownloadManager.STATE_STOPPED || dm_state == DownloadManager.STATE_ERROR) {
                rs_async.dispatch(new AERunnable() {

                    @Override
                    public void runSupport() {
                        dm.setStateQueued();
                    }
                });
            }
        } else if (op == TagFeatureRunState.RSC_STOP) {
            if (dm_state != DownloadManager.STATE_STOPPED && dm_state != DownloadManager.STATE_STOPPING && dm_state != DownloadManager.STATE_ERROR) {
                rs_async.dispatch(new AERunnable() {

                    @Override
                    public void runSupport() {
                        dm.stopIt(DownloadManager.STATE_STOPPED, false, false);
                        // recheck here in case it is an 'archive' action that requires
                        // download to be stopped
                        checkMaximumTaggables();
                    }
                });
            }
        } else if (op == TagFeatureRunState.RSC_PAUSE) {
            if (dm_state != DownloadManager.STATE_STOPPED && dm_state != DownloadManager.STATE_STOPPING && dm_state != DownloadManager.STATE_ERROR) {
                rs_async.dispatch(new AERunnable() {

                    @Override
                    public void runSupport() {
                        dm.pause(true);
                    }
                });
            }
        } else if (op == TagFeatureRunState.RSC_RESUME) {
            if (dm.isPaused()) {
                rs_async.dispatch(new AERunnable() {

                    @Override
                    public void runSupport() {
                        dm.resume();
                    }
                });
            }
        } else {
            rs_async.dispatch(new AERunnable() {

                @Override
                public void runSupport() {
                    int dm_state = dm.getState();
                    if (dm_state != DownloadManager.STATE_STOPPED && dm_state != DownloadManager.STATE_ERROR) {
                        dm.stopIt(DownloadManager.STATE_STOPPED, false, false);
                    }
                    try {
                        if (op == TagFeatureRunState.RSC_ARCHIVE) {
                            Download download = PluginCoreUtils.wrap(dm);
                            if (download.canStubbify()) {
                                // have to remove from tag otherwise when it is restored it will no doubt get re-archived!
                                removeTaggable(dm);
                                download.stubbify();
                            }
                        } else if (op == TagFeatureRunState.RSC_REMOVE_FROM_LIBRARY) {
                            dm.getGlobalManager().removeDownloadManager(dm, false, false);
                        } else if (op == TagFeatureRunState.RSC_REMOVE_FROM_COMPUTER) {
                            boolean reallyDeleteData = !dm.getDownloadState().getFlag(Download.FLAG_DO_NOT_DELETE_DATA_ON_REMOVE);
                            dm.getGlobalManager().removeDownloadManager(dm, true, reallyDeleteData);
                        }
                    } catch (Throwable e) {
                        Debug.out(e);
                    }
                }
            });
        }
    }
}
Also used : DownloadManager(com.biglybt.core.download.DownloadManager) Download(com.biglybt.pif.download.Download)

Example 14 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class SimpleAPIPlugin method evalScript.

public Object evalScript(Map<String, Object> eval_args) throws IPCException {
    String intent = (String) eval_args.get("intent");
    Download download = (Download) eval_args.get("download");
    String scripts = (String) eval_args.get("script");
    scripts = scripts.trim();
    if (scripts.length() > 2 && GeneralUtils.startsWithDoubleQuote(scripts) && GeneralUtils.endsWithDoubleQuote(scripts)) {
        scripts = scripts.substring(1, scripts.length() - 1);
        scripts = scripts.trim();
    }
    log_channel.log(intent + " - " + scripts);
    String[] script_strs = scripts.split(";");
    List<String> results = new ArrayList<>();
    for (String script : script_strs) {
        script = script.trim();
        if (script.isEmpty()) {
            continue;
        }
        Map<String, String> args = new HashMap<>();
        Map<String, List<String>> multi_args = new HashMap<>();
        String[] arg_strs = script.split("&");
        for (String arg_str : arg_strs) {
            String[] bits = arg_str.split("=");
            String name = bits[0].toLowerCase(Locale.US);
            String value;
            if (bits.length == 2) {
                value = UrlUtils.decode(bits[1]);
            } else {
                value = "";
            }
            args.put(name, value);
            List<String> multi_value = multi_args.get(name);
            if (multi_value == null) {
                multi_value = new ArrayList<>();
                multi_args.put(name, multi_value);
            }
            multi_value.add(value);
        }
        args.put("apikey,", api_key.getValue());
        args.put("hash", ByteFormatter.encodeString(download.getTorrentHash()));
        try {
            String result = process(args, multi_args);
            if (result != null) {
                results.add(result);
            }
        } catch (Throwable e) {
            log_channel.log("    error: " + Debug.getNestedExceptionMessage(e));
            throw (new IPCException(e));
        }
    }
    if (results.isEmpty()) {
        return (null);
    } else {
        String str = "";
        for (String result : results) {
            str += (str.isEmpty() ? "" : ";") + result;
        }
        return (str);
    }
}
Also used : IPCException(com.biglybt.pif.ipc.IPCException) Download(com.biglybt.pif.download.Download)

Example 15 with Download

use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.

the class DownloadingRankColumnListener method refresh.

@Override
public void refresh(TableCell cell) {
    Download dl = (Download) cell.getDataSource();
    if (dl == null)
        return;
    DefaultRankCalculator dlData = null;
    Object o = cell.getSortValue();
    if (o instanceof DefaultRankCalculator)
        dlData = (DefaultRankCalculator) o;
    else {
        dlData = StartStopRulesDefaultPlugin.getRankCalculator(dl);
    }
    if (dlData == null)
        return;
    int position = dlData.getPosition();
    cell.setSortValue(position);
    cell.setText("" + position);
    if (plugin.bDebugLog) {
        String dlr = dlData.getDLRTrace();
        if (dlr.length() > 0) {
            dlr = "AR: " + dlr + "\n";
        }
        cell.setToolTip(dlr + "TRACE:\n" + dlData.getTrace());
    } else {
        cell.setToolTip(null);
    }
}
Also used : Download(com.biglybt.pif.download.Download)

Aggregations

Download (com.biglybt.pif.download.Download)80 DownloadManager (com.biglybt.core.download.DownloadManager)22 Torrent (com.biglybt.pif.torrent.Torrent)17 DiskManagerFileInfo (com.biglybt.pif.disk.DiskManagerFileInfo)12 File (java.io.File)12 TOTorrent (com.biglybt.core.torrent.TOTorrent)11 PluginInterface (com.biglybt.pif.PluginInterface)11 URL (java.net.URL)10 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)8 PEPeerManager (com.biglybt.core.peer.PEPeerManager)8 List (java.util.List)7 Tag (com.biglybt.core.tag.Tag)6 MenuItem (com.biglybt.pif.ui.menus.MenuItem)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 DownloadException (com.biglybt.pif.download.DownloadException)5 DiskManager (com.biglybt.core.disk.DiskManager)4 DownloadManager (com.biglybt.pif.download.DownloadManager)4 DownloadScrapeResult (com.biglybt.pif.download.DownloadScrapeResult)4 Peer (com.biglybt.pif.peers.Peer)4