Пример #1
0
        public string ParseDirective(string key)
        {
            if (!AppContext.Instance.Options.EnableSearchDirective)
            {
                return(key);
            }

            if (key.IsNullOrEmpty())
            {
                return("");
            }

            if (key.IsIgnoreCaseEqualTo(_key))
            {
                return(_filteredKey);
            }
            _key = key;

            _excludeKey.Clear();
            _strictKey.Clear();
            _sizeDirective = null;

            _filteredKey = key.IsNullOrEmpty() ? "" : Regex.Replace(key, @"(?<=^|\s)([+\-><])([^\s]+)", _ =>
            {
                var op = _.Groups[1].Value;
                if (op == "+")
                {
                    _strictKey.SafeAdd(_.Groups[2].Value);
                    return(_.Groups[2].Value);
                }
                if (op == "-")
                {
                    _excludeKey.SafeAdd(_.Groups[2].Value);
                    return("");
                }
                if (op == ">" || op == "<")
                {
                    var size = EngineUtility.ToSize(_.Groups[2].Value);
                    if (size > 0L)
                    {
                        _greater       = op == ">";
                        _sizeDirective = _.Value;
                        _sizeFilter    = size;

                        return("");
                    }
                }

                return(_.Groups[2].Value);
            });
            _filteredKey = Regex.Replace(_filteredKey, @"\s\s+", " ");

            return(_filteredKey);
        }
Пример #2
0
        /// <summary>
        /// Compare two sub-items.
        /// </summary>
        /// <param name="subItemA">First sub-item to compare.</param><param name="subItemB">Second sub-item to compare.</param><param name="sortMethod">Item comparison method.</param><param name="order">Sort order.</param>
        /// <returns>
        /// Comparison result.
        /// </returns>
        protected override int CompareSubItems(BetterListViewSubItem subItemA, BetterListViewSubItem subItemB, BetterListViewSortMethod sortMethod, int order)
        {
            if (SuspendSort)
            {
                return(0);
            }

            var lx = subItemA.Item as ResourceListViewItem;
            var ly = subItemB.Item as ResourceListViewItem;

            if (lx.ParentItem != null && ly.ParentItem != null)
            {
                return(lx.Resource.CompareTo(ly.Resource));
            }

            //do not compare subitems

            if (lx.ParentItem != null || ly.ParentItem != null)
            {
                return(0);
            }

            var sx = lx.Resource;
            var sy = ly.Resource;


            if (sx.MatchWeight != sy.MatchWeight)
            {
                return(sy.MatchWeight - sx.MatchWeight);
            }


            var opt    = AppContext.Instance.Options;
            var weight = order;

            switch (opt.SortType)
            {
            case SortType.Default:
                return(0);                              //默认就是按照网站显示的顺序,不排序

            case SortType.Title:
                return(string.Compare(sx.Title, sy.Title, StringComparison.OrdinalIgnoreCase) * weight);

            case SortType.PubDate:
                if (sx.UpdateTime == null && sy.UpdateTime == null)
                {
                    return(0);
                }
                if (sx.UpdateTime == null ^ sy.UpdateTime == null)
                {
                    return((sx.UpdateTime == null ? -1 : 1) * weight);
                }
                return((int)((sx.UpdateTime.Value - sy.UpdateTime.Value).TotalMinutes) * -1);

            //case BtResourceGrabber.Entities.SortType.TorrentSize:
            //	break;
            case SortType.FileSize:
                var s1 = sx.DownloadSizeValue ?? EngineUtility.ToSize(sx.DownloadSize);
                var s2 = sy.DownloadSizeValue ?? EngineUtility.ToSize(sy.DownloadSize);

                return((s1 == s2 ? 0 : s1 < s2 ? -1 : 1) * weight);

            //case BtResourceGrabber.Entities.SortType.LeechCount:
            //	break;
            //case BtResourceGrabber.Entities.SortType.SeederCount:
            //	break;
            default:
                break;
            }

            return(0);
        }