Search in sources :

Example 1 with IndentWriter

use of com.biglybt.core.util.IndentWriter in project BiglyBT by BiglySoftware.

the class ConfigSectionLogging method configSectionCreate.

@Override
public Composite configSectionCreate(final Composite parent) {
    ImageLoader imageLoader = ImageLoader.getInstance();
    Image imgOpenFolder = imageLoader.getImage("openFolderButton");
    GridData gridData;
    GridLayout layout;
    Composite gLogging = new Composite(parent, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(gLogging, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    gLogging.setLayout(layout);
    int userMode = COConfigurationManager.getIntParameter("User Mode");
    BooleanParameter enable_logger = new BooleanParameter(gLogging, "Logger.Enabled", "ConfigView.section.logging.loggerenable");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    enable_logger.setLayoutData(gridData);
    // row
    final BooleanParameter enableLogging = new BooleanParameter(gLogging, "Logging Enable", "ConfigView.section.logging.enable");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    enableLogging.setLayoutData(gridData);
    Composite cArea = new Composite(gLogging, SWT.NULL);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 3;
    cArea.setLayout(layout);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.horizontalSpan = 2;
    cArea.setLayoutData(gridData);
    // row
    Label lStatsPath = new Label(cArea, SWT.NULL);
    // $NON-NLS-1$
    Messages.setLanguageText(lStatsPath, "ConfigView.section.logging.logdir");
    gridData = new GridData();
    gridData.widthHint = 150;
    // $NON-NLS-1$ //$NON-NLS-2$
    final StringParameter pathParameter = new StringParameter(cArea, "Logging Dir");
    pathParameter.setLayoutData(gridData);
    Button browse = new Button(cArea, SWT.PUSH);
    browse.setImage(imgOpenFolder);
    imgOpenFolder.setBackground(browse.getBackground());
    browse.setToolTipText(MessageText.getString("ConfigView.button.browse"));
    browse.addListener(SWT.Selection, new Listener() {

        /* (non-Javadoc)
       * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
       */
        @Override
        public void handleEvent(Event event) {
            DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL);
            dialog.setFilterPath(pathParameter.getValue());
            // $NON-NLS-1$
            dialog.setText(MessageText.getString("ConfigView.section.logging.choosedefaultsavepath"));
            String path = dialog.open();
            if (path != null) {
                pathParameter.setValue(path);
            }
        }
    });
    Label lMaxLog = new Label(cArea, SWT.NULL);
    Messages.setLanguageText(lMaxLog, "ConfigView.section.logging.maxsize");
    final String[] lmLabels = new String[logFileSizes.length];
    final int[] lmValues = new int[logFileSizes.length];
    for (int i = 0; i < logFileSizes.length; i++) {
        int num = logFileSizes[i];
        lmLabels[i] = " " + num + " MB";
        lmValues[i] = num;
    }
    IntListParameter paramMaxSize = new IntListParameter(cArea, "Logging Max Size", lmLabels, lmValues);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    paramMaxSize.setLayoutData(gridData);
    if (userMode > 1) {
        Label timeStampLbl = new Label(cArea, SWT.NULL);
        Messages.setLanguageText(timeStampLbl, "ConfigView.section.logging.timestamp");
        Utils.setLayoutData(timeStampLbl, new GridData());
        StringParameter timeStamp = new StringParameter(cArea, "Logging Timestamp");
        gridData = new GridData();
        gridData.horizontalSpan = 2;
        gridData.widthHint = 150;
        timeStamp.setLayoutData(gridData);
    }
    /**
     * FileLogging filter, consisting of a List of types (info, warning, error)
     * and a checkbox Table of component IDs.
     */
    final String sFilterPrefix = "ConfigView.section.logging.filter";
    Group gLogIDs = new Group(gLogging, SWT.NULL);
    Messages.setLanguageText(gLogIDs, sFilterPrefix);
    layout = new GridLayout();
    layout.numColumns = 2;
    gLogIDs.setLayout(layout);
    gridData = new GridData(SWT.BEGINNING, SWT.BEGINNING, true, true);
    gridData.horizontalSpan = 2;
    Utils.setLayoutData(gLogIDs, gridData);
    final List listLogTypes = new List(gLogIDs, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL);
    gridData = new GridData(SWT.NULL, SWT.BEGINNING, false, false);
    listLogTypes.setLayoutData(gridData);
    final int[] logTypes = { LogEvent.LT_INFORMATION, LogEvent.LT_WARNING, LogEvent.LT_ERROR };
    for (int i = 0; i < logTypes.length; i++) listLogTypes.add(MessageText.getString("ConfigView.section.logging.log" + i + "type"));
    listLogTypes.select(0);
    final LogIDs[] logIDs = FileLogging.configurableLOGIDs;
    // Arrays.sort(logIDs);
    final Table tableLogIDs = new Table(gLogIDs, SWT.CHECK | SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
    gridData = new GridData(GridData.FILL_BOTH);
    tableLogIDs.setLayoutData(gridData);
    tableLogIDs.setLinesVisible(false);
    tableLogIDs.setHeaderVisible(false);
    TableColumn column = new TableColumn(tableLogIDs, SWT.NONE);
    for (int i = 0; i < logIDs.length; i++) {
        TableItem item = new TableItem(tableLogIDs, SWT.NULL);
        item.setText(0, MessageText.getString(sFilterPrefix + "." + logIDs[i], logIDs[i].toString()));
        item.setData(logIDs[i]);
        boolean checked = COConfigurationManager.getBooleanParameter("bLog." + logTypes[0] + "." + logIDs[i], true);
        item.setChecked(checked);
    }
    column.pack();
    // Update table when list selection changes
    listLogTypes.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int index = listLogTypes.getSelectionIndex();
            if (index < 0 || index >= logTypes.length)
                return;
            TableItem[] items = tableLogIDs.getItems();
            for (int i = 0; i < items.length; i++) {
                boolean checked = COConfigurationManager.getBooleanParameter("bLog." + logTypes[index] + "." + items[i].getData(), true);
                items[i].setChecked(checked);
            }
        }
    });
    // Save config when checkbox is clicked
    tableLogIDs.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (e.detail != SWT.CHECK)
                return;
            int index = listLogTypes.getSelectionIndex();
            if (index < 0 || index >= logTypes.length)
                return;
            TableItem item = (TableItem) e.item;
            COConfigurationManager.setParameter("bLog." + logTypes[index] + "." + item.getData(), item.getChecked());
        }
    });
    final Control[] controls_main = { cArea, gLogIDs };
    final ChangeSelectionActionPerformer perf2 = new ChangeSelectionActionPerformer(controls_main);
    enableLogging.setAdditionalActionPerformer(perf2);
    enable_logger.setAdditionalActionPerformer(new IAdditionalActionPerformer() {

        ChangeSelectionActionPerformer p1 = new ChangeSelectionActionPerformer(new Control[] { enableLogging.getControl() });

        @Override
        public void performAction() {
            p1.performAction();
        }

        @Override
        public void setSelected(boolean selected) {
            p1.setSelected(selected);
            if (!selected && enableLogging.isSelected())
                enableLogging.setSelected(false);
        }

        @Override
        public void setIntValue(int value) {
        /*nothing*/
        }

        @Override
        public void setStringValue(String value) {
        /*nothing*/
        }
    });
    if (userMode > 0) {
        Composite cDebugFiles = new Composite(gLogging, SWT.NULL);
        layout = new GridLayout();
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 3;
        cDebugFiles.setLayout(layout);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        cDebugFiles.setLayoutData(gridData);
        Label l_debug_file_size = new Label(cDebugFiles, SWT.NULL);
        Messages.setLanguageText(l_debug_file_size, "ConfigView.section.logging.debugfilesize");
        l_debug_file_size.setLayoutData(new GridData());
        new IntParameter(cDebugFiles, "Logger.DebugFiles.SizeKB", 10, Integer.MAX_VALUE);
        new Label(cDebugFiles, SWT.NULL).setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    }
    if (userMode > 1) {
        // advanced option
        Group cAO = new Group(gLogging, SWT.NULL);
        cAO.setText(MessageText.getString("dht.advanced.group"));
        layout = new GridLayout();
        layout.marginHeight = 0;
        layout.marginWidth = 0;
        layout.numColumns = 5;
        cAO.setLayout(layout);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.horizontalSpan = 2;
        cAO.setLayoutData(gridData);
        // name
        Label aoName = new Label(cAO, SWT.NULL);
        Messages.setLanguageText(aoName, "label.name");
        aoName.setLayoutData(new GridData());
        final StringParameter name = new StringParameter(cAO, "Advanced Option Name");
        gridData = new GridData();
        gridData.widthHint = 150;
        name.setLayoutData(gridData);
        // value
        Label aoValue = new Label(cAO, SWT.NULL);
        Messages.setLanguageText(aoValue, "label.value");
        aoName.setLayoutData(new GridData());
        final StringParameter value = new StringParameter(cAO, "Advanced Option Value");
        gridData = new GridData();
        gridData.widthHint = 150;
        value.setLayoutData(gridData);
        // set
        Button set_option = new Button(cAO, SWT.PUSH);
        Messages.setLanguageText(set_option, "Button.set");
        set_option.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                String key = name.getValue().trim();
                if ((key.startsWith("'") && key.endsWith("'")) || (key.startsWith("\"") && key.endsWith("\""))) {
                    key = key.substring(1, key.length() - 1);
                }
                if (key.length() > 0) {
                    if (key.startsWith("!")) {
                        key = key.substring(1);
                    } else {
                        key = "adv.setting." + key;
                    }
                    String val = value.getValue().trim();
                    boolean is_string = false;
                    if ((val.startsWith("'") && val.endsWith("'")) || (val.startsWith("\"") && val.endsWith("\""))) {
                        val = val.substring(1, val.length() - 1);
                        is_string = true;
                    }
                    if (val.length() == 0) {
                        COConfigurationManager.removeParameter(key);
                    } else {
                        if (is_string) {
                            COConfigurationManager.setParameter(key, val);
                        } else {
                            String lc_val = val.toLowerCase(Locale.US);
                            if (lc_val.equals("false") || lc_val.equals("true")) {
                                COConfigurationManager.setParameter(key, lc_val.startsWith("t"));
                            } else {
                                try {
                                    long l = Long.parseLong(val);
                                    COConfigurationManager.setParameter(key, l);
                                } catch (Throwable e) {
                                    COConfigurationManager.setParameter(key, val);
                                }
                            }
                        }
                    }
                    COConfigurationManager.save();
                }
            }
        });
    }
    // network diagnostics
    Label generate_net_info = new Label(gLogging, SWT.NULL);
    Messages.setLanguageText(generate_net_info, "ConfigView.section.logging.netinfo");
    Button generate_net_button = new Button(gLogging, SWT.PUSH);
    Messages.setLanguageText(generate_net_button, "ConfigView.section.logging.generatediagnostics");
    generate_net_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            new AEThread2("GenerateNetDiag", true) {

                @Override
                public void run() {
                    StringWriter sw = new StringWriter();
                    PrintWriter pw = new PrintWriter(sw);
                    IndentWriter iw = new IndentWriter(pw);
                    NetworkAdmin admin = NetworkAdmin.getSingleton();
                    admin.generateDiagnostics(iw);
                    pw.close();
                    final String info = sw.toString();
                    Logger.log(new LogEvent(LOGID, "Network Info:\n" + info));
                    Utils.execSWTThread(new Runnable() {

                        @Override
                        public void run() {
                            ClipboardCopy.copyToClipBoard(info);
                        }
                    });
                }
            }.start();
        }
    });
    // stats
    Label generate_stats_info = new Label(gLogging, SWT.NULL);
    Messages.setLanguageText(generate_stats_info, "ConfigView.section.logging.statsinfo");
    Button generate_stats_button = new Button(gLogging, SWT.PUSH);
    Messages.setLanguageText(generate_stats_button, "ConfigView.section.logging.generatediagnostics");
    generate_stats_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            java.util.Set types = new HashSet();
            types.add(CoreStats.ST_ALL);
            Map reply = CoreStats.getStats(types);
            Iterator it = reply.entrySet().iterator();
            StringBuilder buffer = new StringBuilder(16000);
            while (it.hasNext()) {
                Map.Entry entry = (Map.Entry) it.next();
                buffer.append(entry.getKey()).append(" -> ").append(entry.getValue()).append("\r\n");
            }
            String str = buffer.toString();
            ClipboardCopy.copyToClipBoard(str);
            Logger.log(new LogEvent(LOGID, "Stats Info:\n" + str));
        }
    });
    // diagnostics
    Label generate_info = new Label(gLogging, SWT.NULL);
    Messages.setLanguageText(generate_info, "ConfigView.section.logging.generatediagnostics.info");
    Button generate_button = new Button(gLogging, SWT.PUSH);
    Messages.setLanguageText(generate_button, "ConfigView.section.logging.generatediagnostics");
    generate_button.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            AEDiagnostics.generateEvidence(pw);
            pw.close();
            String evidence = sw.toString();
            ClipboardCopy.copyToClipBoard(evidence);
            Logger.log(new LogEvent(LOGID, "Evidence Generation:\n" + evidence));
        }
    });
    if (false) {
        Button test_button = new Button(gLogging, SWT.PUSH);
        test_button.setText("Test");
        test_button.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                try {
                    PluginInterface pi = CoreFactory.getSingleton().getPluginManager().getDefaultPluginInterface();
                    UpdateInstaller installer = pi.getUpdateManager().createInstaller();
                    installer.addMoveAction("C:\\temp\\file1", "C:\\temp\\file2");
                    installer.installNow(new UpdateInstallerListener() {

                        @Override
                        public void reportProgress(String str) {
                            System.out.println(str);
                        }

                        @Override
                        public void complete() {
                            System.out.println("complete");
                        }

                        @Override
                        public void failed(UpdateException e) {
                            System.out.println("failed");
                            e.printStackTrace();
                        }
                    });
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        });
    }
    return gLogging;
}
Also used : Image(org.eclipse.swt.graphics.Image) NetworkAdmin(com.biglybt.core.networkmanager.admin.NetworkAdmin) SelectionEvent(org.eclipse.swt.events.SelectionEvent) HashSet(java.util.HashSet) LogEvent(com.biglybt.core.logging.LogEvent) AEThread2(com.biglybt.core.util.AEThread2) UpdateInstaller(com.biglybt.pif.update.UpdateInstaller) Map(java.util.Map) IndentWriter(com.biglybt.core.util.IndentWriter) UpdateInstallerListener(com.biglybt.pif.update.UpdateInstallerListener) HashSet(java.util.HashSet) GridLayout(org.eclipse.swt.layout.GridLayout) StringWriter(java.io.StringWriter) Iterator(java.util.Iterator) UpdateException(com.biglybt.pif.update.UpdateException) PrintWriter(java.io.PrintWriter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) PluginInterface(com.biglybt.pif.PluginInterface) LogIDs(com.biglybt.core.logging.LogIDs) UpdateInstallerListener(com.biglybt.pif.update.UpdateInstallerListener) GridData(org.eclipse.swt.layout.GridData) LogEvent(com.biglybt.core.logging.LogEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ImageLoader(com.biglybt.ui.swt.imageloader.ImageLoader)

Example 2 with IndentWriter

use of com.biglybt.core.util.IndentWriter 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

IndentWriter (com.biglybt.core.util.IndentWriter)2 PrintWriter (java.io.PrintWriter)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 DownloadManager (com.biglybt.core.download.DownloadManager)1 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)1 GlobalManager (com.biglybt.core.global.GlobalManager)1 LogEvent (com.biglybt.core.logging.LogEvent)1 LogIDs (com.biglybt.core.logging.LogIDs)1 NetworkAdmin (com.biglybt.core.networkmanager.admin.NetworkAdmin)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 PEPeerManagerStats (com.biglybt.core.peer.PEPeerManagerStats)1 AEThread2 (com.biglybt.core.util.AEThread2)1 PluginInterface (com.biglybt.pif.PluginInterface)1 UpdateException (com.biglybt.pif.update.UpdateException)1 UpdateInstaller (com.biglybt.pif.update.UpdateInstaller)1 UpdateInstallerListener (com.biglybt.pif.update.UpdateInstallerListener)1 ImageLoader (com.biglybt.ui.swt.imageloader.ImageLoader)1 FileWriter (java.io.FileWriter)1