Search in sources :

Example 6 with TOTorrentAnnounceURLSet

use of com.biglybt.core.torrent.TOTorrentAnnounceURLSet in project BiglyBT by BiglySoftware.

the class TRTrackerAnnouncerMuxer method create.

private TRTrackerAnnouncerHelper create(TOTorrent torrent, String[] networks, TOTorrentAnnounceURLSet[] sets) throws TRTrackerAnnouncerException {
    TRTrackerAnnouncerHelper announcer;
    boolean decentralised;
    if (sets.length == 0) {
        decentralised = TorrentUtils.isDecentralised(torrent.getAnnounceURL());
    } else {
        decentralised = TorrentUtils.isDecentralised(sets[0].getAnnounceURLs()[0]);
    }
    if (decentralised) {
        announcer = new TRTrackerDHTAnnouncerImpl(torrent, networks, is_manual, getHelper());
    } else {
        announcer = new TRTrackerBTAnnouncerImpl(torrent, sets, networks, is_manual, getHelper());
    }
    for (TOTorrentAnnounceURLSet set : sets) {
        URL[] urls = set.getAnnounceURLs();
        for (URL u : urls) {
            String key = u.toExternalForm();
            StatusSummary summary = recent_responses.get(key);
            if (summary == null) {
                summary = new StatusSummary(announcer, u);
                recent_responses.put(key, summary);
            } else {
                summary.setHelper(announcer);
            }
        }
    }
    if (provider != null) {
        announcer.setAnnounceDataProvider(provider);
    }
    if (ip_override != null) {
        announcer.setIPOverride(ip_override);
    }
    return (announcer);
}
Also used : TRTrackerBTAnnouncerImpl(com.biglybt.core.tracker.client.impl.bt.TRTrackerBTAnnouncerImpl) TRTrackerDHTAnnouncerImpl(com.biglybt.core.tracker.client.impl.dht.TRTrackerDHTAnnouncerImpl) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet) URL(java.net.URL)

Example 7 with TOTorrentAnnounceURLSet

use of com.biglybt.core.torrent.TOTorrentAnnounceURLSet in project BiglyBT by BiglySoftware.

the class MagnetPlugin method addTrackersAndWebSeedsEtc.

private byte[] addTrackersAndWebSeedsEtc(byte[] torrent_data, String args, Set<String> networks) {
    List<String> new_web_seeds = new ArrayList<>();
    List<String> new_trackers = new ArrayList<>();
    Set<String> tags = new HashSet<>();
    if (args != null) {
        String[] bits = args.split("&");
        for (String bit : bits) {
            String[] x = bit.split("=");
            if (x.length == 2) {
                String lhs = x[0].toLowerCase();
                if (lhs.equals("ws")) {
                    try {
                        new_web_seeds.add(new URL(UrlUtils.decode(x[1])).toExternalForm());
                    } catch (Throwable e) {
                    }
                } else if (lhs.equals("tr")) {
                    try {
                        new_trackers.add(new URL(UrlUtils.decode(x[1])).toExternalForm());
                    } catch (Throwable e) {
                    }
                } else if (lhs.equals("tag")) {
                    tags.add(UrlUtils.decode(x[1]));
                }
            }
        }
    }
    if (new_web_seeds.size() > 0 || new_trackers.size() > 0 || networks.size() > 0) {
        try {
            TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedByteArray(torrent_data);
            boolean update_torrent = false;
            if (new_web_seeds.size() > 0) {
                Object obj = torrent.getAdditionalProperty("url-list");
                List<String> existing = new ArrayList<>();
                if (obj instanceof byte[]) {
                    try {
                        new_web_seeds.remove(new URL(new String((byte[]) obj, "UTF-8")).toExternalForm());
                    } catch (Throwable e) {
                    }
                } else if (obj instanceof List) {
                    List<byte[]> l = (List<byte[]>) obj;
                    for (byte[] b : l) {
                        try {
                            existing.add(new URL(new String((byte[]) b, "UTF-8")).toExternalForm());
                        } catch (Throwable e) {
                        }
                    }
                }
                boolean update_ws = false;
                for (String e : new_web_seeds) {
                    if (!existing.contains(e)) {
                        existing.add(e);
                        update_ws = true;
                    }
                }
                if (update_ws) {
                    List<byte[]> l = new ArrayList<>();
                    for (String s : existing) {
                        l.add(s.getBytes("UTF-8"));
                    }
                    torrent.setAdditionalProperty("url-list", l);
                    update_torrent = true;
                }
            }
            if (new_trackers.size() > 0) {
                URL announce_url = torrent.getAnnounceURL();
                new_trackers.remove(announce_url.toExternalForm());
                TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
                TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
                for (TOTorrentAnnounceURLSet set : sets) {
                    URL[] set_urls = set.getAnnounceURLs();
                    for (URL set_url : set_urls) {
                        new_trackers.remove(set_url.toExternalForm());
                    }
                }
                if (new_trackers.size() > 0) {
                    TOTorrentAnnounceURLSet[] new_sets = new TOTorrentAnnounceURLSet[sets.length + new_trackers.size()];
                    System.arraycopy(sets, 0, new_sets, 0, sets.length);
                    for (int i = 0; i < new_trackers.size(); i++) {
                        TOTorrentAnnounceURLSet new_set = group.createAnnounceURLSet(new URL[] { new URL(new_trackers.get(i)) });
                        new_sets[i + sets.length] = new_set;
                    }
                    group.setAnnounceURLSets(new_sets);
                    update_torrent = true;
                }
            }
            if (networks.size() > 0) {
                TorrentUtils.setNetworkCache(torrent, new ArrayList<>(networks));
                update_torrent = true;
            }
            if (tags.size() > 0) {
                TorrentUtils.setTagCache(torrent, new ArrayList<>(tags));
                update_torrent = true;
            }
            if (update_torrent) {
                torrent_data = BEncoder.encode(torrent.serialiseToMap());
            }
        } catch (Throwable e) {
        }
    }
    return (torrent_data);
}
Also used : URL(java.net.URL) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) TOTorrent(com.biglybt.core.torrent.TOTorrent) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet)

Example 8 with TOTorrentAnnounceURLSet

use of com.biglybt.core.torrent.TOTorrentAnnounceURLSet in project BiglyBT by BiglySoftware.

the class MenuFactory method handleTorrentView.

private static void handleTorrentView() {
    final Shell shell = Utils.findAnyShell();
    try {
        FileDialog dialog = new FileDialog(shell, SWT.SYSTEM_MODAL | SWT.OPEN);
        dialog.setFilterExtensions(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD });
        dialog.setFilterNames(new String[] { "*.torrent", "*.tor", Constants.FILE_WILDCARD });
        dialog.setFilterPath(TorrentOpener.getFilterPathTorrent());
        dialog.setText(MessageText.getString("torrent.fix.corrupt.browse"));
        String str = dialog.open();
        if (str != null) {
            TorrentOpener.setFilterPathTorrent(str);
            File file = new File(str);
            StringBuilder content = new StringBuilder();
            String NL = "\r\n";
            try {
                TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedFile(file);
                LocaleUtilDecoder locale_decoder = LocaleTorrentUtil.getTorrentEncoding(torrent);
                content.append("Character Encoding:\t").append(locale_decoder.getName()).append(NL);
                String display_name = locale_decoder.decodeString(torrent.getName());
                content.append("Name:\t").append(display_name).append(NL);
                byte[] hash = torrent.getHash();
                content.append("Hash:\t").append(ByteFormatter.encodeString(hash)).append(NL);
                content.append("Size:\t").append(DisplayFormatters.formatByteCountToKiBEtc(torrent.getSize())).append(", piece size=").append(DisplayFormatters.formatByteCountToKiBEtc(torrent.getPieceLength())).append(", piece count=").append(torrent.getPieces().length).append(NL);
                if (torrent.getPrivate()) {
                    content.append("Private Torrent").append(NL);
                }
                URL announce_url = torrent.getAnnounceURL();
                if (announce_url != null) {
                    content.append("Announce URL:\t").append(announce_url).append(NL);
                }
                TOTorrentAnnounceURLSet[] sets = torrent.getAnnounceURLGroup().getAnnounceURLSets();
                if (sets.length > 0) {
                    content.append("Announce List").append(NL);
                    for (TOTorrentAnnounceURLSet set : sets) {
                        String x = "";
                        URL[] urls = set.getAnnounceURLs();
                        for (URL u : urls) {
                            x += (x.length() == 0 ? "" : ", ") + u;
                        }
                        content.append("\t").append(x).append(NL);
                    }
                }
                content.append("Magnet URI:\t").append(UrlUtils.getMagnetURI(display_name, PluginCoreUtils.wrap(torrent))).append(NL);
                long c_date = torrent.getCreationDate();
                if (c_date > 0) {
                    content.append("Created On:\t").append(DisplayFormatters.formatDate(c_date * 1000)).append(NL);
                }
                byte[] created_by = torrent.getCreatedBy();
                if (created_by != null) {
                    content.append("Created By:\t").append(locale_decoder.decodeString(created_by)).append(NL);
                }
                byte[] comment = torrent.getComment();
                if (comment != null) {
                    content.append("Comment:\t").append(locale_decoder.decodeString(comment)).append(NL);
                }
                TOTorrentFile[] files = torrent.getFiles();
                content.append("Files:\t").append(files.length).append(" - simple=").append(torrent.isSimpleTorrent()).append(NL);
                for (TOTorrentFile tf : files) {
                    byte[][] comps = tf.getPathComponents();
                    String f_name = "";
                    for (byte[] comp : comps) {
                        f_name += (f_name.length() == 0 ? "" : File.separator) + locale_decoder.decodeString(comp);
                    }
                    content.append("\t").append(f_name).append("\t\t").append(DisplayFormatters.formatByteCountToKiBEtc(tf.getLength())).append(NL);
                }
            } catch (Throwable e) {
                content.append(Debug.getNestedExceptionMessage(e));
            }
            new TextViewerWindow(MessageText.getString("MainWindow.menu.quick_view") + ": " + file.getName(), null, content.toString(), false);
        }
    } catch (Throwable e) {
        Debug.out(e);
    }
}
Also used : URL(java.net.URL) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell) LocaleUtilDecoder(com.biglybt.core.internat.LocaleUtilDecoder) TOTorrent(com.biglybt.core.torrent.TOTorrent) TOTorrentFile(com.biglybt.core.torrent.TOTorrentFile) File(java.io.File) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet)

Example 9 with TOTorrentAnnounceURLSet

use of com.biglybt.core.torrent.TOTorrentAnnounceURLSet in project BiglyBT by BiglySoftware.

the class TorrentInfoView method initialize.

private void initialize(Composite composite) {
    this.parent = composite;
    if (download_manager == null) {
        return;
    }
    // I don't want to waste my time :) [tux]
    if (sc != null && !sc.isDisposed()) {
        sc.dispose();
    }
    sc = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL);
    sc.getVerticalBar().setIncrement(16);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
    Utils.setLayoutData(sc, gridData);
    outer_panel = sc;
    Composite panel = new Composite(sc, SWT.NULL);
    sc.setContent(panel);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 1;
    panel.setLayout(layout);
    // int userMode = COConfigurationManager.getIntParameter("User Mode");
    // header
    Composite cHeader = new Composite(panel, SWT.BORDER);
    GridLayout configLayout = new GridLayout();
    configLayout.marginHeight = 3;
    configLayout.marginWidth = 0;
    cHeader.setLayout(configLayout);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    Utils.setLayoutData(cHeader, gridData);
    Display d = panel.getDisplay();
    cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
    cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
    Label lHeader = new Label(cHeader, SWT.NULL);
    lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
    lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
    FontData[] fontData = lHeader.getFont().getFontData();
    fontData[0].setStyle(SWT.BOLD);
    int fontHeight = (int) (fontData[0].getHeight() * 1.2);
    fontData[0].setHeight(fontHeight);
    headerFont = new Font(d, fontData);
    lHeader.setFont(headerFont);
    lHeader.setText(" " + MessageText.getString("authenticator.torrent") + " : " + download_manager.getDisplayName().replaceAll("&", "&&"));
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    Utils.setLayoutData(lHeader, gridData);
    Composite gTorrentInfo = new Composite(panel, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(gTorrentInfo, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    gTorrentInfo.setLayout(layout);
    // torrent encoding
    Label label = new Label(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(label, gridData);
    label.setText(MessageText.getString("TorrentInfoView.torrent.encoding") + ": ");
    TOTorrent torrent = download_manager.getTorrent();
    BufferedLabel blabel = new BufferedLabel(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(blabel, gridData);
    blabel.setText(torrent == null ? "" : LocaleTorrentUtil.getCurrentTorrentEncoding(torrent));
    // trackers
    label = new Label(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(label, gridData);
    label.setText(MessageText.getString("label.tracker") + ": ");
    String trackers = "";
    if (torrent != null) {
        TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
        TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
        List<String> tracker_list = new ArrayList<>();
        URL url = torrent.getAnnounceURL();
        tracker_list.add(url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort())));
        for (int i = 0; i < sets.length; i++) {
            TOTorrentAnnounceURLSet set = sets[i];
            URL[] urls = set.getAnnounceURLs();
            for (int j = 0; j < urls.length; j++) {
                url = urls[j];
                String str = url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort()));
                if (!tracker_list.contains(str)) {
                    tracker_list.add(str);
                }
            }
        }
        TRTrackerAnnouncer announcer = download_manager.getTrackerClient();
        URL active_url = null;
        if (announcer != null) {
            active_url = announcer.getTrackerURL();
        } else {
            TRTrackerScraperResponse scrape = download_manager.getTrackerScrapeResponse();
            if (scrape != null) {
                active_url = scrape.getURL();
            }
        }
        if (active_url == null) {
            active_url = torrent.getAnnounceURL();
        }
        trackers = active_url.getHost() + (active_url.getPort() == -1 ? "" : (":" + active_url.getPort()));
        tracker_list.remove(trackers);
        if (tracker_list.size() > 0) {
            trackers += " (";
            for (int i = 0; i < tracker_list.size(); i++) {
                trackers += (i == 0 ? "" : ", ") + tracker_list.get(i);
            }
            trackers += ")";
        }
    }
    blabel = new BufferedLabel(gTorrentInfo, SWT.WRAP);
    Utils.setLayoutData(blabel, Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL));
    blabel.setText(trackers);
    // columns
    Group gColumns = new Group(panel, SWT.NULL);
    Messages.setLanguageText(gColumns, "TorrentInfoView.columns");
    gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(gColumns, gridData);
    layout = new GridLayout();
    layout.numColumns = 4;
    gColumns.setLayout(layout);
    Map<String, FakeTableCell> usable_cols = new HashMap<>();
    TableColumnManager col_man = TableColumnManager.getInstance();
    TableColumnCore[][] cols_sets = { col_man.getAllTableColumnCoreAsArray(DownloadTypeIncomplete.class, TableManager.TABLE_MYTORRENTS_INCOMPLETE), col_man.getAllTableColumnCoreAsArray(DownloadTypeComplete.class, TableManager.TABLE_MYTORRENTS_COMPLETE) };
    for (int i = 0; i < cols_sets.length; i++) {
        TableColumnCore[] cols = cols_sets[i];
        for (int j = 0; j < cols.length; j++) {
            TableColumnCore col = cols[j];
            String id = col.getName();
            if (usable_cols.containsKey(id)) {
                continue;
            }
            FakeTableCell fakeTableCell = null;
            try {
                fakeTableCell = new FakeTableCell(col, download_manager);
                fakeTableCell.setOrentation(SWT.LEFT);
                fakeTableCell.setWrapText(false);
                col.invokeCellAddedListeners(fakeTableCell);
                // One refresh to see if it throws up
                fakeTableCell.refresh();
                usable_cols.put(id, fakeTableCell);
            } catch (Throwable t) {
                // System.out.println("not usable col: " + id + " - " + Debug.getCompressedStackTrace());
                try {
                    if (fakeTableCell != null) {
                        fakeTableCell.dispose();
                    }
                } catch (Throwable t2) {
                // ignore;
                }
            }
        }
    }
    Collection<FakeTableCell> values = usable_cols.values();
    cells = new FakeTableCell[values.size()];
    values.toArray(cells);
    Arrays.sort(cells, new Comparator<FakeTableCell>() {

        @Override
        public int compare(FakeTableCell o1, FakeTableCell o2) {
            TableColumnCore c1 = (TableColumnCore) o1.getTableColumn();
            TableColumnCore c2 = (TableColumnCore) o2.getTableColumn();
            String key1 = MessageText.getString(c1.getTitleLanguageKey());
            String key2 = MessageText.getString(c2.getTitleLanguageKey());
            return key1.compareToIgnoreCase(key2);
        }
    });
    for (int i = 0; i < cells.length; i++) {
        final FakeTableCell cell = cells[i];
        label = new Label(gColumns, SWT.NULL);
        gridData = new GridData();
        if (i % 2 == 1) {
            gridData.horizontalIndent = 16;
        }
        Utils.setLayoutData(label, gridData);
        String key = ((TableColumnCore) cell.getTableColumn()).getTitleLanguageKey();
        label.setText(MessageText.getString(key) + ": ");
        label.setToolTipText(MessageText.getString(key + ".info", ""));
        final Composite c = new Composite(gColumns, SWT.DOUBLE_BUFFERED);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.heightHint = 16;
        Utils.setLayoutData(c, gridData);
        cell.setControl(c);
        cell.invalidate();
        cell.refresh();
        c.addListener(SWT.MouseHover, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Object toolTip = cell.getToolTip();
                if (toolTip instanceof String) {
                    String s = (String) toolTip;
                    c.setToolTipText(s);
                }
            }
        });
    }
    refresh();
    sc.setMinSize(panel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
Also used : TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) FakeTableCell(com.biglybt.ui.swt.views.table.impl.FakeTableCell) Font(org.eclipse.swt.graphics.Font) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) URL(java.net.URL) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) GridLayout(org.eclipse.swt.layout.GridLayout) TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FontData(org.eclipse.swt.graphics.FontData) DownloadTypeComplete(com.biglybt.pif.download.DownloadTypeComplete) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) TOTorrent(com.biglybt.core.torrent.TOTorrent) GridData(org.eclipse.swt.layout.GridData) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) DownloadTypeIncomplete(com.biglybt.pif.download.DownloadTypeIncomplete) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet)

Example 10 with TOTorrentAnnounceURLSet

use of com.biglybt.core.torrent.TOTorrentAnnounceURLSet in project BiglyBT by BiglySoftware.

the class MyTorrentsView method filterCheck.

@Override
public boolean filterCheck(DownloadManager dm, String sLastSearch, boolean bRegexSearch) {
    if (dm == null) {
        return (false);
    }
    boolean bOurs;
    if (sLastSearch.length() > 0) {
        try {
            String comment = dm.getDownloadState().getUserComment();
            if (comment == null) {
                comment = "";
            }
            String[][] name_mapping = { { "", dm.getDisplayName() }, { "t:", // defer (index = 1)this as costly dm.getTorrent().getAnnounceURL().getHost()
            "" }, { "st:", "" + dm.getState() }, { "c:", comment }, { "f:", // defer (index = 4)
            "" }, { "tag:", "" } };
            Object o_name = name_mapping[0][1];
            String tmpSearch = sLastSearch;
            for (int i = 1; i < name_mapping.length; i++) {
                if (tmpSearch.startsWith(name_mapping[i][0])) {
                    tmpSearch = tmpSearch.substring(name_mapping[i][0].length());
                    if (i == 1) {
                        List<String> names = new ArrayList<>();
                        o_name = names;
                        TOTorrent t = dm.getTorrent();
                        if (t != null) {
                            names.add(t.getAnnounceURL().getHost());
                            TOTorrentAnnounceURLSet[] sets = t.getAnnounceURLGroup().getAnnounceURLSets();
                            for (TOTorrentAnnounceURLSet set : sets) {
                                URL[] urls = set.getAnnounceURLs();
                                for (URL u : urls) {
                                    names.add(u.getHost());
                                }
                            }
                            try {
                                byte[] hash = t.getHash();
                                names.add(ByteFormatter.encodeString(hash));
                                names.add(Base32.encode(hash));
                            } catch (Throwable e) {
                            }
                        }
                    } else if (i == 4) {
                        List<String> names = new ArrayList<>();
                        o_name = names;
                        DiskManagerFileInfoSet file_set = dm.getDiskManagerFileInfoSet();
                        DiskManagerFileInfo[] files = file_set.getFiles();
                        for (DiskManagerFileInfo f : files) {
                            File file = f.getFile(true);
                            String name = tmpSearch.contains(File.separator) ? file.getAbsolutePath() : file.getName();
                            names.add(name);
                        }
                    } else if (i == 5) {
                        List<String> names = new ArrayList<String>();
                        o_name = names;
                        TagManager tagManager = TagManagerFactory.getTagManager();
                        List<Tag> tags = tagManager.getTagsForTaggable(TagType.TT_DOWNLOAD_MANUAL, dm);
                        if (tags.size() > 0) {
                            tags = TagUIUtils.sortTags(tags);
                            for (Tag t : tags) {
                                String str = t.getTagName(true);
                                names.add(str);
                            }
                        }
                    } else {
                        o_name = name_mapping[i][1];
                    }
                }
            }
            String s = bRegexSearch ? tmpSearch : "\\Q" + tmpSearch.replaceAll("[|;]", "\\\\E|\\\\Q") + "\\E";
            boolean match_result = true;
            if (bRegexSearch && s.startsWith("!")) {
                s = s.substring(1);
                match_result = false;
            }
            Pattern pattern = RegExUtil.getCachedPattern("tv:search", s, Pattern.CASE_INSENSITIVE);
            if (o_name instanceof String) {
                bOurs = pattern.matcher((String) o_name).find() == match_result;
            } else {
                List<String> names = (List<String>) o_name;
                // match_result: true -> at least one match; false -> any fail
                bOurs = !match_result;
                for (String name : names) {
                    if (pattern.matcher(name).find()) {
                        bOurs = match_result;
                        break;
                    }
                }
            }
        } catch (Exception e) {
            // Future: report PatternSyntaxException message to user.
            bOurs = true;
        }
    } else {
        bOurs = true;
    }
    return bOurs;
}
Also used : Pattern(java.util.regex.Pattern) DiskManagerFileInfo(com.biglybt.core.disk.DiskManagerFileInfo) DiskManagerFileInfoSet(com.biglybt.core.disk.DiskManagerFileInfoSet) URL(java.net.URL) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) TOTorrent(com.biglybt.core.torrent.TOTorrent) List(java.util.List) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet) File(java.io.File)

Aggregations

TOTorrentAnnounceURLSet (com.biglybt.core.torrent.TOTorrentAnnounceURLSet)16 URL (java.net.URL)14 TOTorrent (com.biglybt.core.torrent.TOTorrent)7 TOTorrentAnnounceURLGroup (com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)7 File (java.io.File)3 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)2 TRTrackerBTAnnouncerImpl (com.biglybt.core.tracker.client.impl.bt.TRTrackerBTAnnouncerImpl)2 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 DiskManagerFileInfoSet (com.biglybt.core.disk.DiskManagerFileInfoSet)1 LocaleUtilDecoder (com.biglybt.core.internat.LocaleUtilDecoder)1 LogAlert (com.biglybt.core.logging.LogAlert)1 LogEvent (com.biglybt.core.logging.LogEvent)1 TOTorrentCreator (com.biglybt.core.torrent.TOTorrentCreator)1 TOTorrentFile (com.biglybt.core.torrent.TOTorrentFile)1 TOTorrentProgressListener (com.biglybt.core.torrent.TOTorrentProgressListener)1 TRTrackerAnnouncer (com.biglybt.core.tracker.client.TRTrackerAnnouncer)1 TRTrackerScraperResponse (com.biglybt.core.tracker.client.TRTrackerScraperResponse)1 TRTrackerDHTAnnouncerImpl (com.biglybt.core.tracker.client.impl.dht.TRTrackerDHTAnnouncerImpl)1 DownloadTypeComplete (com.biglybt.pif.download.DownloadTypeComplete)1 DownloadTypeIncomplete (com.biglybt.pif.download.DownloadTypeIncomplete)1