示例#1
0
        /// <summary>
        /// Occurs when a download link search found a new link.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void DownloadSearchEngineNewLink(object sender, EventArgs <Link> e)
        {
            if (Signature.IsActivated || !Regex.IsMatch(e.Data.Source.Site + e.Data.InfoURL + e.Data.FileURL, @"(?:sceneaccess|thegft)\.(?:[a-z]{2,3})/", RegexOptions.IgnoreCase))
            {
                _results.Add(new LinkItem(e.Data));
            }

            Dispatcher.Invoke((Action)(() =>
            {
                lock (DownloadLinksListViewItemCollection)
                {
                    var sel = listView.SelectedItem;

                    DownloadLinksListViewItemCollection.Clear();
                    DownloadLinksListViewItemCollection.AddRange(_results
                                                                 .OrderBy(link => FileNames.Parser.QualityCount - (int)link.Quality)
                                                                 .ThenBy(link => AutoDownloader.Parsers.IndexOf(link.Source.Name)));

                    if (sel != null)
                    {
                        listView.SelectedItem = sel;
                        listView.ScrollIntoView(sel);
                    }
                }
            }));
        }
示例#2
0
        /// <summary>
        /// Handles the Click event of the searchButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void SearchButtonClick(object sender = null, RoutedEventArgs e = null)
        {
            if (string.IsNullOrWhiteSpace(textBox.Text))
            {
                return;
            }

            if (_searching)
            {
                ActiveSearch.CancelAsync();
                DownloadSearchDone();
                return;
            }

            _results = new ConcurrentBag <LinkItem>();
            DownloadLinksListViewItemCollection.Clear();

            textBox.IsEnabled    = false;
            searchButton.Content = "Cancel";

            ActiveSearch = new DownloadSearch(AutoDownloader.ActiveSearchEngines, filterResults.IsChecked);

            ActiveSearch.DownloadSearchDone          += DownloadSearchDone;
            ActiveSearch.DownloadSearchEngineNewLink += DownloadSearchEngineNewLink;
            ActiveSearch.DownloadSearchEngineDone    += DownloadSearchEngineDone;
            ActiveSearch.DownloadSearchEngineError   += DownloadSearchEngineError;

            SetStatus("Searching for download links on " + (string.Join(", ", ActiveSearch.SearchEngines.Select(engine => engine.Name).ToArray())) + "...", true);

            _searching = true;

            ActiveSearch.SearchAsync(textBox.Text);

            Utils.Win7Taskbar(0, TaskbarProgressBarState.Normal);
        }
示例#3
0
        /// <summary>
        /// Called when a download link search is done on all engines.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void DownloadSearchDone(object sender = null, EventArgs e = null)
        {
            if (ActiveSearch != null)
            {
                ActiveSearch.DownloadSearchDone          -= DownloadSearchDone;
                ActiveSearch.DownloadSearchEngineNewLink -= DownloadSearchEngineNewLink;
                ActiveSearch.DownloadSearchEngineDone    -= DownloadSearchEngineDone;
                ActiveSearch.DownloadSearchEngineError   -= DownloadSearchEngineError;
                ActiveSearch = null;
            }

            if (!_searching)
            {
                return;
            }

            _searching = false;

            Utils.Win7Taskbar(state: TaskbarProgressBarState.NoProgress);

            Dispatcher.Invoke((Action)(() =>
            {
                textBox.IsEnabled = true;
                searchButton.Content = "Search";

                if (Signature.IsActivated && Settings.Get <bool>("One-Click Hoster Link Checker"))
                {
                    foreach (var item in DownloadLinksListViewItemCollection.Where(x => x.Source.Type == Types.DirectHTTP).ToList())
                    {
                        Task.Factory.StartNew(item.CheckLink);
                    }
                }

                if (DownloadLinksListViewItemCollection.Count != 0)
                {
                    SetStatus("Found " + Utils.FormatNumber(DownloadLinksListViewItemCollection.Count, "download link") + "!");
                }
                else
                {
                    SetStatus("Couldn't find any download links.");
                }
            }));
        }
示例#4
0
        /// <summary>
        /// Handles the Click event of the listView control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void ListViewSortClick(object sender, RoutedEventArgs e)
        {
            var header = e.OriginalSource as GridViewColumnHeader;

            if (header == null || header.Role == GridViewColumnHeaderRole.Padding || _results == null || _results.Count == 0)
            {
                return;
            }

            var direction = header != _lastClickedHeader
                            ? ListSortDirection.Ascending
                            : _lastSortDirection == ListSortDirection.Ascending
                                ? ListSortDirection.Descending
                                : ListSortDirection.Ascending;

            var links = new List <LinkItem>(_results);

            switch (header.Content.ToString())
            {
            case "Site":
                if (direction == ListSortDirection.Ascending)
                {
                    links = links
                            .OrderBy(link => AutoDownloader.Parsers.IndexOf(link.Source.Name))
                            .ThenBy(link => FileNames.Parser.QualityCount - (int)link.Quality)
                            .ToList();
                }
                else
                {
                    links = links
                            .OrderByDescending(link => AutoDownloader.Parsers.IndexOf(link.Source.Name))
                            .ThenBy(link => FileNames.Parser.QualityCount - (int)link.Quality)
                            .ToList();
                }
                break;

            case "Quality":
                if (direction == ListSortDirection.Ascending)
                {
                    links = links
                            .OrderBy(link => FileNames.Parser.QualityCount - (int)link.Quality)
                            .ThenBy(link => AutoDownloader.Parsers.IndexOf(link.Source.Name))
                            .ToList();
                }
                else
                {
                    links = links
                            .OrderByDescending(link => FileNames.Parser.QualityCount - (int)link.Quality)
                            .ThenBy(link => AutoDownloader.Parsers.IndexOf(link.Source.Name))
                            .ToList();
                }
                break;

            default:
                return;
            }

            _lastClickedHeader = header;
            _lastSortDirection = direction;

            DownloadLinksListViewItemCollection.Clear();
            DownloadLinksListViewItemCollection.AddRange(links);
        }