Search in sources :

Example 41 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class MainWindowImpl method _init.

/**
 * Called only on STARTUP_UIFIRST
 */
private void _init(Core core) {
    // System.out.println("MainWindow: init(core)");
    this.core = core;
    disposedOrDisposing = false;
    StimulusRPC.hookListeners(core, this);
    if (uiSWTInstanceImpl == null) {
        uiSWTInstanceImpl = new UISWTInstanceImpl();
        uiSWTInstanceImpl.init(uiInitializer);
    }
    postPluginSetup(core);
    // When a download is added, check for new meta data and
    // un-"wait state" the rating
    GlobalManager gm = core.getGlobalManager();
    dms_Startup = gm.getDownloadManagers().toArray(new DownloadManager[0]);
    gmListener = new MainWindowGMListener();
    gm.addListener(gmListener, false);
    Alerts.addListener(new MainWindowAlertListener());
    core.triggerLifeCycleComponentCreated(uiFunctions);
    processStartupDMS();
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) DownloadManager(com.biglybt.core.download.DownloadManager) UISWTInstanceImpl(com.biglybt.ui.swt.pifimpl.UISWTInstanceImpl)

Example 42 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class UIFunctionsImpl method addTorrentWithOptions.

@Override
public boolean addTorrentWithOptions(final TorrentOpenOptions torrentOptions, Map<String, Object> addOptions) {
    Boolean is_silent = (Boolean) addOptions.get(UIFunctions.OTO_SILENT);
    if (is_silent == null) {
        is_silent = UIFunctions.OTO_SILENT_DEFAULT;
    }
    if (CoreFactory.isCoreRunning()) {
        Core core = CoreFactory.getSingleton();
        GlobalManager gm = core.getGlobalManager();
        // Check if torrent already exists in gm, and add if not
        TOTorrent torrent = torrentOptions.getTorrent();
        DownloadManager existingDownload = gm.getDownloadManager(torrent);
        if (existingDownload != null) {
            if (!is_silent) {
                final String fExistingName = existingDownload.getDisplayName();
                final DownloadManager fExistingDownload = existingDownload;
                fExistingDownload.fireGlobalManagerEvent(GlobalManagerEvent.ET_REQUEST_ATTENTION);
                Utils.execSWTThread(new AERunnable() {

                    @Override
                    public void runSupport() {
                        boolean can_merge = TorrentUtils.canMergeAnnounceURLs(torrentOptions.getTorrent(), fExistingDownload.getTorrent());
                        long existed_for = SystemTime.getCurrentTime() - fExistingDownload.getCreationTime();
                        Shell mainShell = UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell();
                        if ((Display.getDefault().getActiveShell() == null || !mainShell.isVisible() || mainShell.getMinimized()) && (!can_merge)) {
                            if (existed_for > 15 * 1000) {
                                new MessageSlideShell(Display.getCurrent(), SWT.ICON_INFORMATION, MSG_ALREADY_EXISTS, null, new String[] { // : prefix is deliberate to disable click on ref in message as might be an unwanted action
                                ":" + torrentOptions.sOriginatingLocation, fExistingName, MessageText.getString(MSG_ALREADY_EXISTS_NAME) }, new Object[] { fExistingDownload }, -1);
                            }
                        } else {
                            if (can_merge) {
                                String text = MessageText.getString(MSG_ALREADY_EXISTS + ".text", new String[] { ":" + torrentOptions.sOriginatingLocation, fExistingName, MessageText.getString(MSG_ALREADY_EXISTS_NAME) });
                                text += "\n\n" + MessageText.getString("openTorrentWindow.mb.alreadyExists.merge");
                                MessageBoxShell mb = new MessageBoxShell(SWT.YES | SWT.NO, MessageText.getString(MSG_ALREADY_EXISTS + ".title"), text);
                                mb.open(new UserPrompterResultListener() {

                                    @Override
                                    public void prompterClosed(int result) {
                                        if (result == SWT.YES) {
                                            TorrentUtils.mergeAnnounceURLs(torrentOptions.getTorrent(), fExistingDownload.getTorrent());
                                        }
                                    }
                                });
                            } else {
                                if (existed_for > 15 * 1000) {
                                    MessageBoxShell mb = new MessageBoxShell(SWT.OK, MSG_ALREADY_EXISTS, new String[] { ":" + torrentOptions.sOriginatingLocation, fExistingName, MessageText.getString(MSG_ALREADY_EXISTS_NAME) });
                                    mb.open(null);
                                }
                            }
                        }
                    }
                });
            }
            if (torrentOptions.getDeleteFileOnCancel()) {
                File torrentFile = new File(torrentOptions.sFileName);
                torrentFile.delete();
            }
            return (true);
        } else {
            try {
                final DownloadStub archived = core.getPluginManager().getDefaultPluginInterface().getDownloadManager().lookupDownloadStub(torrent.getHash());
                if (archived != null) {
                    if (is_silent) {
                        // restore it for them
                        archived.destubbify();
                        if (torrentOptions.getDeleteFileOnCancel()) {
                            File torrentFile = new File(torrentOptions.sFileName);
                            torrentFile.delete();
                        }
                        return (true);
                    } else {
                        Utils.execSWTThread(new AERunnable() {

                            @Override
                            public void runSupport() {
                                Shell mainShell = UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell();
                                String existingName = archived.getName();
                                if (Display.getDefault().getActiveShell() == null || !mainShell.isVisible() || mainShell.getMinimized()) {
                                    new MessageSlideShell(Display.getCurrent(), SWT.ICON_INFORMATION, "OpenTorrentWindow.mb.inArchive", null, new String[] { existingName }, new Object[0], -1);
                                } else {
                                    MessageBoxShell mb = new MessageBoxShell(SWT.OK, "OpenTorrentWindow.mb.inArchive", new String[] { existingName });
                                    mb.open(null);
                                }
                            }
                        });
                        return (true);
                    }
                }
            } catch (Throwable e) {
                Debug.out(e);
            }
            if (!is_silent) {
                try {
                    DownloadHistoryManager dlm = (DownloadHistoryManager) core.getGlobalManager().getDownloadHistoryManager();
                    final long[] existing = dlm.getDates(torrentOptions.getTorrent().getHash());
                    if (existing != null) {
                        long redownloaded = existing[3];
                        if (SystemTime.getCurrentTime() - redownloaded > 60 * 10 * 1000) {
                            Utils.execSWTThread(new AERunnable() {

                                @Override
                                public void runSupport() {
                                    Shell mainShell = UIFunctionsManagerSWT.getUIFunctionsSWT().getMainShell();
                                    if (mainShell != null && !mainShell.isDisposed()) {
                                        new MessageSlideShell(mainShell.getDisplay(), SWT.ICON_INFORMATION, "OpenTorrentWindow.mb.inHistory", null, new String[] { torrentOptions.getTorrentName(), new SimpleDateFormat().format(new Date(existing[0])) }, new Object[] {}, -1);
                                    }
                                }
                            });
                        }
                    }
                } catch (Throwable e) {
                    Debug.out(e);
                }
            }
        }
    }
    Boolean force = (Boolean) addOptions.get(UIFunctions.OTO_FORCE_OPEN);
    if (force == null) {
        force = UIFunctions.OTO_FORCE_OPEN_DEFAULT;
    }
    if (!force) {
        TOTorrent torrent = torrentOptions.getTorrent();
        boolean is_featured = torrent != null && PlatformTorrentUtils.isFeaturedContent(torrent);
        String showAgainMode = COConfigurationManager.getStringParameter(ConfigurationDefaults.CFG_TORRENTADD_OPENOPTIONS);
        if (is_featured || is_silent || (showAgainMode != null && ((showAgainMode.equals(ConfigurationDefaults.CFG_TORRENTADD_OPENOPTIONS_NEVER)) || (showAgainMode.equals(ConfigurationDefaults.CFG_TORRENTADD_OPENOPTIONS_MANY) && torrentOptions.getFiles() != null && torrentOptions.getFiles().length == 1)))) {
            // we're about to silently add the download - ensure that it is going to be saved somewhere vaguely sensible
            // as the current save location is simply taken from the 'default download' config which can be blank (for example)
            boolean looks_good = false;
            String save_loc = torrentOptions.getParentDir().trim();
            if (save_loc.length() == 0) {
            // blank :(
            } else if (save_loc.startsWith(".")) {
            // relative to who knows where
            } else {
                File f = new File(save_loc);
                if (!f.exists()) {
                    f.mkdirs();
                }
                if (f.isDirectory() && FileUtil.canWriteToDirectory(f)) {
                    if (!f.equals(AETemporaryFileHandler.getTempDirectory())) {
                        looks_good = true;
                    }
                }
            }
            if (looks_good) {
                TorrentManagerImpl t_man = TorrentManagerImpl.getSingleton();
                t_man.optionsAdded(torrentOptions);
                t_man.optionsAccepted(torrentOptions);
                boolean ok = TorrentOpener.addTorrent(torrentOptions);
                t_man.optionsRemoved(torrentOptions);
                return (ok);
            }
            torrentOptions.setParentDir("");
            if (is_silent) {
                return (false);
            } else {
                MessageBoxShell mb = new MessageBoxShell(SWT.OK | SWT.ICON_ERROR, "OpenTorrentWindow.mb.invaliddefsave", new String[] { save_loc });
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int result) {
                        OpenTorrentOptionsWindow.addTorrent(torrentOptions);
                    }
                });
            }
            return (true);
        }
    }
    if (is_silent) {
        return (false);
    } else {
        OpenTorrentOptionsWindow.addTorrent(torrentOptions);
        return (true);
    }
}
Also used : DownloadHistoryManager(com.biglybt.core.history.DownloadHistoryManager) MessageSlideShell(com.biglybt.ui.swt.shells.MessageSlideShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) TorrentManagerImpl(com.biglybt.pifimpl.local.torrent.TorrentManagerImpl) DownloadManager(com.biglybt.core.download.DownloadManager) Date(java.util.Date) Point(org.eclipse.swt.graphics.Point) DownloadStub(com.biglybt.pif.download.DownloadStub) MessageSlideShell(com.biglybt.ui.swt.shells.MessageSlideShell) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) GlobalManager(com.biglybt.core.global.GlobalManager) TOTorrent(com.biglybt.core.torrent.TOTorrent) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat) UISWTViewCore(com.biglybt.ui.swt.pifimpl.UISWTViewCore) Core(com.biglybt.core.Core)

Example 43 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class ClientIDPlugin method getProperty.

@Override
public Object getProperty(byte[] hash, String property_name) {
    if (property_name == ClientIDGenerator.PR_CLIENT_NAME) {
        if (client.equals(BIGLYBT_CLIENT_NAME)) {
            try {
                GlobalManager gm = core.getGlobalManager();
                DownloadManager dm = gm.getDownloadManager(new HashWrapper(hash));
                if (dm != null && gm.isSwarmMerging(dm) != null) {
                    return (use_main_version ? ML_BIGLYBT_CLIENT_NAME_SM : BIGLYBT_CLIENT_NAME_SM);
                }
            } catch (Throwable e) {
            }
            return (use_main_version ? ML_BIGLYBT_CLIENT_NAME : BIGLYBT_CLIENT_NAME);
        } else {
            return (VUZE_5750);
        }
    } else if (property_name == ClientIDGenerator.PR_MESSAGING_MODE) {
        if (client.equals(BIGLYBT_CLIENT_NAME)) {
            return (BTHandshake.AZ_RESERVED_MODE);
        } else {
            return (BTHandshake.AZ_RESERVED_MODE);
        }
    } else {
        return (null);
    }
}
Also used : GlobalManager(com.biglybt.core.global.GlobalManager) HashWrapper(com.biglybt.core.util.HashWrapper) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 44 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class Initializer method run.

@Override
public void run() {
    DelayedTask delayed_task = UtilitiesImpl.addDelayedTask("SWT Initialisation", new Runnable() {

        @Override
        public void run() {
            init_task.reserve();
        }
    });
    delayed_task.queueFirst();
    // initialise the SWT locale util
    long startTime = SystemTime.getCurrentTime();
    new LocaleUtilSWT(core);
    final Display display = Utils.getDisplay();
    new UIMagnetHandler(core);
    if (!STARTUP_UIFIRST) {
        // Ensure colors initialized
        Colors.getInstance();
        UIConfigDefaultsSWT.initialize();
        UIConfigDefaultsSWTv3.initialize(core);
    } else {
        COConfigurationManager.setBooleanDefault("Show Splash", false);
    }
    if (COConfigurationManager.getBooleanParameter("Show Splash")) {
        display.asyncExec(new AERunnable() {

            @Override
            public void runSupport() {
                new SplashWindow(display, Initializer.this);
            }
        });
    }
    System.out.println("Locale Initializing took " + (SystemTime.getCurrentTime() - startTime) + "ms");
    startTime = SystemTime.getCurrentTime();
    core.addLifecycleListener(new CoreLifecycleAdapter() {

        @Override
        public void componentCreated(Core core, CoreComponent component) {
            Initializer.this.reportPercent(curPercent + 1);
            if (component instanceof GlobalManager) {
                reportCurrentTaskByKey("splash.initializePlugins");
                InitialisationFunctions.earlyInitialisation(core);
            } else if (component instanceof PluginInterface) {
                PluginInterface pi = (PluginInterface) component;
                String name = pi.getPluginName();
                String version = pi.getPluginVersion();
                // text says initializing, but it's actually initialized.  close enough
                String s = MessageText.getString("splash.plugin.init") + " " + name + (version == null ? "" : (" v" + version));
                reportCurrentTask(s);
            }
        }

        // @see com.biglybt.core.CoreLifecycleAdapter#started(com.biglybt.core.Core)
        @Override
        public void started(Core core) {
            handleCoreStarted(core);
        }

        @Override
        public void stopping(Core core) {
            Alerts.stopInitiated();
        }

        @Override
        public void stopped(Core core) {
        }

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

        @Override
        public boolean requiresPluginInitCompleteBeforeStartedEvent() {
            return (false);
        }

        @Override
        public boolean stopRequested(Core _core) throws CoreException {
            return handleStopRestart(false);
        }

        @Override
        public boolean restartRequested(final Core core) {
            return handleStopRestart(true);
        }
    });
    reportCurrentTaskByKey("splash.initializeCore");
    boolean uiClassic = COConfigurationManager.getStringParameter("ui").equals("az2");
    try {
        new SearchUI();
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    try {
        subscriptionManagerUI = new SubscriptionManagerUI();
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
    if (!uiClassic) {
        try {
            deviceManagerUI = new DeviceManagerUI(core);
        } catch (Throwable e) {
            Debug.printStackTrace(e);
        }
    }
    if (core.canStart()) {
        // Other UIs could start the core before us
        if (!core.isStarted()) {
            core.start();
        } else {
            handleCoreStarted(core);
        }
        reportPercent(50);
        System.out.println("Core Initializing took " + (SystemTime.getCurrentTime() - startTime) + "ms");
        startTime = SystemTime.getCurrentTime();
        reportCurrentTaskByKey("splash.initializeUIElements");
        // Ensure colors initialized
        Colors.getInstance();
        reportPercent(curPercent + 1);
        Alerts.init();
        reportPercent(curPercent + 1);
        ProgressWindow.register(core);
        reportPercent(curPercent + 1);
        new SWTNetworkSelection();
        reportPercent(curPercent + 1);
        new AuthenticatorWindow();
        new CryptoWindow();
        reportPercent(curPercent + 1);
        new CertificateTrustWindow();
        core.getPluginManager().getPluginInstaller().addListener(new PluginInstallerListener() {

            @Override
            public boolean installRequest(final String reason, final InstallablePlugin plugin) throws PluginException {
                if (plugin instanceof StandardPlugin) {
                    Map<Integer, Object> properties = new HashMap<>();
                    properties.put(UpdateCheckInstance.PT_UI_EXTRA_MESSAGE, reason);
                    plugin.install(false, false, false, properties);
                    return (true);
                } else {
                    return (false);
                }
            }
        });
    } else {
        CoreWaiterSWT.startupAbandoned();
        final AESemaphore sem = new AESemaphore("waiter");
        Utils.execSWTThread(new Runnable() {

            @Override
            public void run() {
                MessageBoxShell mb = new MessageBoxShell(MessageText.getString("msgbox.force.close.title"), MessageText.getString("msgbox.force.close.text", new String[] { core.getLockFile().getAbsolutePath() }), new String[] { MessageText.getString("Button.ok") }, 0);
                mb.setIconResource("error");
                mb.setModal(true);
                mb.open(new UserPrompterResultListener() {

                    @Override
                    public void prompterClosed(int result) {
                        sem.releaseForever();
                    }
                });
            }
        });
        sem.reserve();
        SESecurityManager.exitVM(1);
    }
}
Also used : DeviceManagerUI(com.biglybt.ui.swt.devices.DeviceManagerUI) PluginInstallerListener(com.biglybt.pif.installer.PluginInstallerListener) AuthenticatorWindow(com.biglybt.ui.swt.auth.AuthenticatorWindow) SearchUI(com.biglybt.ui.swt.search.SearchUI) CertificateTrustWindow(com.biglybt.ui.swt.auth.CertificateTrustWindow) GlobalManager(com.biglybt.core.global.GlobalManager) DelayedTask(com.biglybt.pif.utils.DelayedTask) SubscriptionManagerUI(com.biglybt.ui.swt.subscriptions.SubscriptionManagerUI) PluginInterface(com.biglybt.pif.PluginInterface) PluginException(com.biglybt.pif.PluginException) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) StandardPlugin(com.biglybt.pif.installer.StandardPlugin) InstallablePlugin(com.biglybt.pif.installer.InstallablePlugin) UserPrompterResultListener(com.biglybt.ui.UserPrompterResultListener) CryptoWindow(com.biglybt.ui.swt.auth.CryptoWindow) SWTNetworkSelection(com.biglybt.ui.swt.networks.SWTNetworkSelection) Map(java.util.Map) HashMap(java.util.HashMap) Display(org.eclipse.swt.widgets.Display)

Example 45 with GlobalManager

use of com.biglybt.core.global.GlobalManager in project BiglyBT by BiglySoftware.

the class Show method execute.

@Override
public void execute(String commandName, ConsoleInput ci, List args) {
    if (args.isEmpty()) {
        printHelp(ci.out, args);
        return;
    }
    String subCommand = (String) args.remove(0);
    if (subCommand.equalsIgnoreCase("options") || subCommand.equalsIgnoreCase("o")) {
        ci.invokeCommand("set", null);
    } else if (subCommand.equalsIgnoreCase("files") || subCommand.equalsIgnoreCase("f")) {
        ci.invokeCommand("add", Arrays.asList(new String[] { "--list" }));
    } else if (subCommand.equalsIgnoreCase("torrents") || subCommand.equalsIgnoreCase("t")) {
        ci.out.println("> -----");
        ci.torrents.clear();
        ci.torrents.addAll(ci.getGlobalManager().getDownloadManagers());
        Collections.sort(ci.torrents, new TorrentComparator());
        if (ci.torrents.isEmpty()) {
            ci.out.println("No Torrents");
            ci.out.println("> -----");
            return;
        }
        long totalReceived = 0;
        long totalSent = 0;
        long totalDiscarded = 0;
        int connectedSeeds = 0;
        int connectedPeers = 0;
        PEPeerManagerStats ps;
        boolean bShowOnlyActive = false;
        boolean bShowOnlyComplete = false;
        boolean bShowOnlyIncomplete = false;
        boolean bShowOnlyTransferring = false;
        int bShowDeadForDays = 0;
        for (ListIterator<String> iter = args.listIterator(); iter.hasNext(); ) {
            String arg = (String) iter.next();
            if ("active".equalsIgnoreCase(arg) || "a".equalsIgnoreCase(arg)) {
                bShowOnlyActive = true;
                iter.remove();
            } else if ("complete".equalsIgnoreCase(arg) || "c".equalsIgnoreCase(arg)) {
                bShowOnlyComplete = true;
                iter.remove();
            } else if ("incomplete".equalsIgnoreCase(arg) || "i".equalsIgnoreCase(arg)) {
                bShowOnlyIncomplete = true;
                iter.remove();
            } else if ("transferring".equalsIgnoreCase(arg) || "x".equalsIgnoreCase(arg)) {
                bShowOnlyTransferring = true;
                bShowOnlyActive = true;
                iter.remove();
            } else if ("dead".equalsIgnoreCase(arg) || "d".equalsIgnoreCase(arg)) {
                iter.remove();
                // default 1 week
                bShowDeadForDays = 7;
                if (iter.hasNext()) {
                    String days = iter.next();
                    try {
                        bShowDeadForDays = Integer.parseInt(days);
                        iter.remove();
                    } catch (Throwable e) {
                        iter.previous();
                    }
                }
            }
        }
        Iterator torrent;
        if (args.size() > 0) {
            List matchedTorrents = new TorrentFilter().getTorrents(ci.torrents, args);
            torrent = matchedTorrents.iterator();
        } else
            torrent = ci.torrents.iterator();
        List shown_torrents = new ArrayList();
        while (torrent.hasNext()) {
            DownloadManager dm = (DownloadManager) torrent.next();
            DownloadManagerStats stats = dm.getStats();
            boolean bDownloadCompleted = stats.getDownloadCompleted(false) == 1000;
            boolean bCanShow = ((bShowOnlyComplete == bShowOnlyIncomplete) || (bDownloadCompleted && bShowOnlyComplete) || (!bDownloadCompleted && bShowOnlyIncomplete));
            if (bCanShow && bShowOnlyActive) {
                int dmstate = dm.getState();
                bCanShow = (dmstate == DownloadManager.STATE_SEEDING) || (dmstate == DownloadManager.STATE_DOWNLOADING) || (dmstate == DownloadManager.STATE_CHECKING) || (dmstate == DownloadManager.STATE_INITIALIZING) || (dmstate == DownloadManager.STATE_ALLOCATING);
            }
            if (bCanShow && bShowOnlyTransferring) {
                try {
                    ps = dm.getPeerManager().getStats();
                    bCanShow = ps.getDataSendRate() > 0 || ps.getDataReceiveRate() > 0;
                } catch (Exception e) {
                }
            }
            if (bCanShow && bShowDeadForDays > 0) {
                int dmstate = dm.getState();
                bCanShow = false;
                if (dmstate == DownloadManager.STATE_SEEDING || (bDownloadCompleted && (dmstate == DownloadManager.STATE_QUEUED || dmstate == DownloadManager.STATE_STOPPED))) {
                    long seeding_secs = stats.getSecondsOnlySeeding();
                    long seeding_days = seeding_secs / (24 * 60 * 60);
                    if (seeding_days >= bShowDeadForDays) {
                        int secs_since_last_up = stats.getTimeSinceLastDataSentInSeconds();
                        if (secs_since_last_up == -1) {
                            // never uploaded
                            bCanShow = true;
                        } else {
                            int days_since_last_up = secs_since_last_up / (24 * 60 * 60);
                            if (days_since_last_up >= bShowDeadForDays) {
                                bCanShow = true;
                            }
                        }
                    }
                }
            }
            if (bCanShow) {
                shown_torrents.add(dm);
                try {
                    PEPeerManager pm = dm.getPeerManager();
                    ps = pm == null ? null : pm.getStats();
                } catch (Exception e) {
                    ps = null;
                }
                if (ps != null) {
                    totalReceived += dm.getStats().getTotalDataBytesReceived();
                    totalSent += dm.getStats().getTotalDataBytesSent();
                    totalDiscarded += ps.getTotalDiscarded();
                    connectedSeeds += dm.getNbSeeds();
                    connectedPeers += dm.getNbPeers();
                }
                ci.out.print(((shown_torrents.size() < 10) ? " " : "") + shown_torrents.size() + " ");
                ci.out.println(getTorrentSummary(dm));
                ci.out.println();
            }
        }
        ci.torrents.clear();
        ci.torrents.addAll(shown_torrents);
        GlobalManager gm = ci.getGlobalManager();
        ci.out.println("Total Speed (down/up): " + DisplayFormatters.formatByteCountToKiBEtcPerSec(gm.getStats().getDataReceiveRate() + gm.getStats().getProtocolReceiveRate()) + " / " + DisplayFormatters.formatByteCountToKiBEtcPerSec(gm.getStats().getDataSendRate() + gm.getStats().getProtocolSendRate()));
        ci.out.println("Transferred Volume (down/up/discarded): " + DisplayFormatters.formatByteCountToKiBEtc(totalReceived) + " / " + DisplayFormatters.formatByteCountToKiBEtc(totalSent) + " / " + DisplayFormatters.formatByteCountToKiBEtc(totalDiscarded));
        ci.out.println("Total Connected Peers (seeds/peers): " + Integer.toString(connectedSeeds) + " / " + Integer.toString(connectedPeers));
        ci.out.println("> -----");
    } else if (subCommand.equalsIgnoreCase("dht") || subCommand.equalsIgnoreCase("d")) {
        showDHTStats(ci);
    } else if (subCommand.equalsIgnoreCase("nat") || subCommand.equalsIgnoreCase("n")) {
        IndentWriter iw = new IndentWriter(new PrintWriter(ci.out));
        iw.setForce(true);
        NetworkAdmin.getSingleton().logNATStatus(iw);
    } else if (subCommand.equalsIgnoreCase("stats") || subCommand.equalsIgnoreCase("s")) {
        String pattern = CoreStats.ST_ALL;
        if (args.size() > 0) {
            pattern = (String) args.get(0);
            if (pattern.equals("*")) {
                pattern = ".*";
            }
        }
        if (args.size() > 1) {
            CoreStats.setEnableAverages(((String) args.get(1)).equalsIgnoreCase("on"));
        }
        java.util.Set types = new HashSet();
        types.add(pattern);
        Map reply = CoreStats.getStats(types);
        Iterator it = reply.entrySet().iterator();
        List lines = new ArrayList();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            lines.add(entry.getKey() + " -> " + entry.getValue());
        }
        Collections.sort(lines);
        for (int i = 0; i < lines.size(); i++) {
            ci.out.println(lines.get(i));
        }
    } else if (subCommand.equalsIgnoreCase("diag") || subCommand.equalsIgnoreCase("z")) {
        try {
            ci.out.println("Writing diagnostics to file 'az.diag'");
            FileWriter fw = new FileWriter("az.diag");
            PrintWriter pw = new PrintWriter(fw);
            AEDiagnostics.generateEvidence(pw);
            pw.flush();
            fw.close();
        } catch (Throwable e) {
            ci.out.println(e);
        }
    } else {
        if ((ci.torrents == null) || (ci.torrents != null) && ci.torrents.isEmpty()) {
            ci.out.println("> Command 'show': No torrents in list (try 'show torrents' first).");
            return;
        }
        try {
            int number = Integer.parseInt(subCommand);
            if ((number == 0) || (number > ci.torrents.size())) {
                ci.out.println("> Command 'show': Torrent #" + number + " unknown.");
                return;
            }
            DownloadManager dm = (DownloadManager) ci.torrents.get(number - 1);
            printTorrentDetails(ci.out, dm, number, args);
        } catch (Exception e) {
            ci.out.println("> Command 'show': Subcommand '" + subCommand + "' unknown.");
            return;
        }
    }
}
Also used : IndentWriter(com.biglybt.core.util.IndentWriter) HashSet(java.util.HashSet) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) DownloadManager(com.biglybt.core.download.DownloadManager) GlobalManager(com.biglybt.core.global.GlobalManager) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) DownloadManagerStats(com.biglybt.core.download.DownloadManagerStats) PrintWriter(java.io.PrintWriter) HashSet(java.util.HashSet) PEPeerManagerStats(com.biglybt.core.peer.PEPeerManagerStats) PEPeerManager(com.biglybt.core.peer.PEPeerManager) Map(java.util.Map)

Aggregations

GlobalManager (com.biglybt.core.global.GlobalManager)48 DownloadManager (com.biglybt.core.download.DownloadManager)33 Core (com.biglybt.core.Core)10 TOTorrent (com.biglybt.core.torrent.TOTorrent)10 List (java.util.List)7 CoreRunningListener (com.biglybt.core.CoreRunningListener)6 File (java.io.File)6 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 UIFunctions (com.biglybt.ui.UIFunctions)5 GlobalManagerStats (com.biglybt.core.global.GlobalManagerStats)4 PEPeerManager (com.biglybt.core.peer.PEPeerManager)4 HashWrapper (com.biglybt.core.util.HashWrapper)4 PluginInterface (com.biglybt.pif.PluginInterface)4 Menu (org.eclipse.swt.widgets.Menu)4 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)3 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)3 PEPeer (com.biglybt.core.peer.PEPeer)3 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)3 PluginException (com.biglybt.pif.PluginException)3 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)3