Пример #1
0
        private async void AppendAsync(string content)
        {
            if (content.Trim().StartsWith("http://") || content.Trim().StartsWith("https://"))
            {
                DownloaderHelper.ProcessOthers(content.Trim());
                return;
            }

            try
            {
                List <HitomiIndexMetadata> result;

                int start_element = 0;
                int count_element = 0;

                if (content.Split(' ').Any(x => x.StartsWith("/")))
                {
                    var elem = content.Split(' ').Where(x => x.StartsWith("/")).ElementAt(0);
                    start_element = Convert.ToInt32(elem.Substring(1));
                    content       = content.Replace(elem, " ");
                }

                if (content.Split(' ').Any(x => x.StartsWith("?")))
                {
                    var elem = content.Split(' ').Where(x => x.StartsWith("?")).ElementAt(0);
                    count_element = Convert.ToInt32(elem.Substring(1));
                    content       = content.Replace(elem, " ");
                }

                if (!Settings.Instance.Hitomi.UsingAdvancedSearch || content.Contains("recent:"))
                {
                    result = await HitomiDataParser.SearchAsync(content.Trim());

                    if (content.Contains("recent:"))
                    {
                        var elem         = content.Split(' ').Where(x => x.StartsWith("recent:")).ElementAt(0);
                        int recent_count = 0;
                        int recent_start = 0;
                        if (elem.Substring("recent:".Length).Contains("-"))
                        {
                            recent_start = Convert.ToInt32(elem.Substring("recent:".Length).Split('-')[0]);
                            recent_count = Convert.ToInt32(elem.Substring("recent:".Length).Split('-')[1]);
                        }
                        else
                        {
                            recent_count = Convert.ToInt32(elem.Substring("recent:".Length));
                        }
                        SearchText.Text = "recent:" + (recent_start + recent_count) + "-" + recent_count;
                    }
                }
                else
                {
                    result = await HitomiDataSearchAdvanced.Search(content.Trim());
                }

                if (start_element != 0 && start_element <= result.Count)
                {
                    result.RemoveRange(0, start_element);
                }
                if (count_element != 0 && count_element < result.Count)
                {
                    result.RemoveRange(count_element, result.Count - count_element);
                }

                SearchCount.Text     = $"{FindResource("searched")}: {(result.Count != 0 ? result.Count.ToString("#,#") : "0")}{(FindResource("count_postfix"))}";
                SearchButton.Content = $"{FindResource("stop")}";
                _ = Task.Run(() => LoadThumbnail(result));
            }
            catch
            {
                SearchCount.Text = (string)FindResource("msg_incorret_search_grammar");
            }
        }
Пример #2
0
        private async void AppendAsync(string content)
        {
            if (content.Trim().StartsWith("http://") || content.Trim().StartsWith("https://"))
            {
                DownloaderHelper.ProcessOthers(content.Trim());
                return;
            }

            try
            {
                List <HitomiMetadata> result;

                int start_element = 0;
                int count_element = 0;

                if (content.Contains('/'))
                {
                    var elem = content.Split(' ').Where(x => x.StartsWith("/")).ElementAt(0);
                    start_element = Convert.ToInt32(elem.Substring(1));
                    content       = content.Replace(elem, " ");
                }

                if (content.Contains('?'))
                {
                    var elem = content.Split(' ').Where(x => x.StartsWith("?")).ElementAt(0);
                    count_element = Convert.ToInt32(elem.Substring(1));
                    content       = content.Replace(elem, " ");
                }

                if (!Settings.Instance.Hitomi.UsingAdvancedSearch || content.Contains("recent:"))
                {
                    result = await HitomiDataParser.SearchAsync(content.Trim());

                    if (content.Contains("recent:"))
                    {
                        var elem         = content.Split(' ').Where(x => x.StartsWith("recent:")).ElementAt(0);
                        int recent_count = 0;
                        int recent_start = 0;
                        if (elem.Substring("recent:".Length).Contains("-"))
                        {
                            recent_start = Convert.ToInt32(elem.Substring("recent:".Length).Split('-')[0]);
                            recent_count = Convert.ToInt32(elem.Substring("recent:".Length).Split('-')[1]);
                        }
                        else
                        {
                            recent_count = Convert.ToInt32(elem.Substring("recent:".Length));
                        }
                        SearchText.Text = "recent:" + (recent_start + recent_count) + "-" + recent_count;
                    }
                }
                else
                {
                    result = await HitomiDataSearchAdvanced.Search(content.Trim());
                }

                if (start_element != 0 && start_element <= result.Count)
                {
                    result.RemoveRange(0, start_element);
                }
                if (count_element != 0 && count_element < result.Count)
                {
                    result.RemoveRange(count_element, result.Count - count_element);
                }

                SearchCount.Text = $"검색된 항목: {result.Count.ToString("#,#")}개";
                _ = Task.Run(() => LoadThumbnail(result));
            }
            catch
            {
                SearchCount.Text = "검색 문법이 잘못되었습니다.";
            }
        }