Ejemplo n.º 1
0
        public bool Check(SearchResult result)
        {
            if (!FilterValid) {
                return true;
            }

            FilterType resultFilterType = (result.Type == SearchResultType.Directory) ? FilterType.Folder : FileTypeToFilterType(result.FileListing.Type);

            if (fileTypeFilterFields[resultFilterType].Contains(this.Field) ||
                fileTypeFilterFields[FilterType.Other].Contains(this.Field))
            {
                switch (this.Field) {
                    case FileSearchFilterField.FileName:
                        switch (this.Comparison) {
                            case FileSearchFilterComparison.Contains:
                                return (result.Name.ToLower().IndexOf(this.Text.ToLower()) > -1);
                            case FileSearchFilterComparison.DoesntContain:
                                return (result.Name.ToLower().IndexOf(this.Text.ToLower()) == -1);
                            case FileSearchFilterComparison.Regexp:
                                return Regex.IsMatch(result.Name, this.text);
                        }
                        break;
                    case FileSearchFilterField.Size:
                        ulong filterSize = Common.SizeStringToBytes(this.Text);
                        switch (this.Comparison) {
                            case FileSearchFilterComparison.Equals:
                                return ((ulong)result.Size == filterSize);
                            case FileSearchFilterComparison.LessThanOrEqualTo:
                                return ((ulong)result.Size <= filterSize);
                            case FileSearchFilterComparison.GreaterOrEqualTo:
                                return ((ulong)result.Size >= filterSize);
                            default:
                                throw new Exception("Invalid filter.");
                        }
                }
            } else {
                // Ignore this filter for this result
                return true;
            }
            return true;
        }
Ejemplo n.º 2
0
 public bool CheckAllFilters(SearchResult result)
 {
     foreach (FileSearchFilter filter in filters) {
         if (!filter.Check(result)) {
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 private void AppendResults(SearchResult[] results)
 {
     // XXX: This won't group same files from multiple nodes!
     foreach (SearchResult result in results) {
         resultsStore.AppendValues(result);
     }
 }
Ejemplo n.º 4
0
        public void AppendResults(Node node, SearchResultInfo resultInfo)
        {
            List<SearchResult> newResults = new List<SearchResult>();

            if (resultInfo.SearchId != id) {
                throw new ArgumentException("Results are for a different search.");
            }

            foreach (string dir in resultInfo.Directories) {
                SearchResult directoryResult = new SearchResult(this, node, dir);
                results.Add(directoryResult);
                newResults.Add(directoryResult);
            }

            foreach (SharedFileListing file in resultInfo.Files) {
                SearchResult result = new SearchResult(this, node, file);
                results.Add(result);
                newResults.Add(result);

                if (!allFileResults.ContainsKey(file.InfoHash)) {
                    allFileResults[file.InfoHash] = new List<SearchResult>();
                }
                allFileResults[file.InfoHash].Add(result);
            }

            if (NewResults != null) {
                NewResults(this, newResults.ToArray());
            }
        }
Ejemplo n.º 5
0
        public void search_NewResults(FileSearch sender, SearchResult[] newResults)
        {
            AppendResults(newResults);

            RecountTypes();
            Gui.MainWindow.RefreshCounts();
        }