public List<HitomiTagdata> GetResults(ref string word, ref int position)
        {
            var match = new List<HitomiTagdata>();

            if (!builded) return match;

            var old_data = HitomiIndex.Instance.tagdata_collection;
            HitomiIndex.Instance.tagdata_collection = tagdata_collection;

            if (word.Contains(":"))
            {
                if (word.StartsWith("artist:"))
                {
                    word = word.Substring("artist:".Length);
                    position += "artist:".Length;
                    match = HitomiDataAnalysis.GetArtistList(word);
                }
            }

            string[] match_target = {
                    "artist:",
                };

            string w = word;
            List<HitomiTagdata> data_col = (from ix in match_target where ix.StartsWith(w) select new HitomiTagdata { Tag = ix }).ToList();
            if (data_col.Count > 0)
                match.AddRange(data_col);
            match.AddRange(HitomiDataAnalysis.GetArtistList(word));

            HitomiIndex.Instance.tagdata_collection = old_data;

            return match;
        }
Ejemplo n.º 2
0
        private void bExtract_Click(object sender, EventArgs e)
        {
            Dictionary <int, HitomiIndexMetadata?> map = new Dictionary <int, HitomiIndexMetadata?>();

            foreach (var tuple in metadatas)
            {
                int key = Convert.ToInt32(tuple.Item2);
                if (!map.ContainsKey(key))
                {
                    map.Add(key, tuple.Item3);
                }
                else
                {
                }
            }

            List <ListViewItem> lvil = new List <ListViewItem>();
            int i = 0;

            foreach (var h in HitomiLog.Instance.DownloadTable)
            {
                if (!map.ContainsKey(h))
                {
                    var           md      = HitomiDataAnalysis.GetMetadataFromMagic(h.ToString());
                    List <string> artists = new List <string>();
                    if (md.HasValue)
                    {
                        if (md.Value.Artists != null)
                        {
                            md.Value.Artists.ToList().ForEach(x => artists.Add(HitomiIndex.Instance.index.Artists[x]));
                        }
                    }

                    lvil.Add(new ListViewItem(new string[]
                    {
                        (i + 1).ToString(),
                        h.ToString(),
                        string.Join(",", artists)
                    }));
                    i++;
                }
            }
            listView1.Items.Clear();
            listView1.Items.AddRange(lvil.ToArray());
        }
Ejemplo n.º 3
0
        public List <HitomiTagdata> GetResults(ref string word, ref int position)
        {
            var match = new List <HitomiTagdata>();

            if (!builded)
            {
                return(match);
            }

            var old_data = HitomiData.Instance.tagdata_collection;

            HitomiData.Instance.tagdata_collection = tagdata_collection;

            if (word.Contains(":"))
            {
                if (word.StartsWith("artist:"))
                {
                    word      = word.Substring("artist:".Length);
                    position += "artist:".Length;
                    match     = HitomiDataAnalysis.GetArtistList(word);
                }
                else if (word.StartsWith("tag:"))
                {
                    word      = word.Substring("tag:".Length);
                    position += "tag:".Length;
                    match     = HitomiDataAnalysis.GetTagList(word);
                }
                else if (word.StartsWith("tagx:"))
                {
                    word      = word.Substring("tagx:".Length);
                    position += "tagx:".Length;
                    match     = HitomiDataAnalysis.GetTagList(word);
                }
                else if (word.StartsWith("character:"))
                {
                    word      = word.Substring("character:".Length);
                    position += "character:".Length;
                    match     = HitomiDataAnalysis.GetCharacterList(word);
                }
                else if (word.StartsWith("group:"))
                {
                    word      = word.Substring("group:".Length);
                    position += "group:".Length;
                    match     = HitomiDataAnalysis.GetGroupList(word);
                }
                else if (word.StartsWith("series:"))
                {
                    word      = word.Substring("series:".Length);
                    position += "series:".Length;
                    match     = HitomiDataAnalysis.GetSeriesList(word);
                }
                else if (word.StartsWith("type:"))
                {
                    word      = word.Substring("type:".Length);
                    position += "type:".Length;
                    match     = HitomiDataAnalysis.GetTypeList(word);
                }
            }

            string[] match_target =
            {
                "artist:",
                "character:",
                "group:",
                "recent:",
                "series:",
                "tag:",
                "tagx:",
                "type:",
            };

            string w = word;
            List <HitomiTagdata> data_col = (from ix in match_target where ix.StartsWith(w) select new HitomiTagdata {
                Tag = ix
            }).ToList();

            if (data_col.Count > 0)
            {
                match.AddRange(data_col);
            }
            match.AddRange(HitomiDataAnalysis.GetTotalList(word));

            HitomiData.Instance.tagdata_collection = old_data;

            return(match);
        }
Ejemplo n.º 4
0
        private void RecursiveVisit(TreeNode node, List <Regex> regex)
        {
            string match = "";

            if (regex.Any(x => {
                if (!x.Match(Path.GetFileNameWithoutExtension(node.Text)).Success)
                {
                    return(false);
                }
                match = x.Match(Path.GetFileNameWithoutExtension(node.Text)).Groups[1].Value;
                return(true);
            }))
            {
                metadatas.Add(new Tuple <string, string, HitomiIndexMetadata?>(node.FullPath, match, HitomiDataAnalysis.GetMetadataFromMagic(match)));
                available_count += 1;
                if (!search_subfiles_whenever)
                {
                    return;
                }
            }

            visit_count += 1;

            foreach (var cnode in node.Nodes.OfType <TreeNode>())
            {
                RecursiveVisit(cnode, regex);
            }
        }
Ejemplo n.º 5
0
        public void SearchText_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                return;
            }
            int position = SearchText.SelectionStart;

            while (position > 0 && !" ()-+&|~".Contains(SearchText.Text[position - 1]))
            {
                position -= 1;
            }

            string word = "";

            for (int i = position; i < SearchText.Text.Length; i++)
            {
                if (" ()-+&|~".Contains(SearchText.Text[i]))
                {
                    break;
                }
                word += SearchText.Text[i];
            }

            if (word == "")
            {
                AutoComplete.IsOpen = false; return;
            }

            List <HitomiTagdata> match = new List <HitomiTagdata>();

            if (!specific)
            {
                if (word.Contains(":"))
                {
                    if (word.StartsWith("artist:"))
                    {
                        word      = word.Substring("artist:".Length);
                        position += "artist:".Length;
                        match     = HitomiDataAnalysis.GetArtistList(word);
                    }
                    else if (word.StartsWith("tag:"))
                    {
                        word      = word.Substring("tag:".Length);
                        position += "tag:".Length;
                        match     = HitomiDataAnalysis.GetTagList(word);
                    }
                    else if (word.StartsWith("tagx:"))
                    {
                        word      = word.Substring("tagx:".Length);
                        position += "tagx:".Length;
                        match     = HitomiDataAnalysis.GetTagList(word);
                    }
                    else if (word.StartsWith("character:"))
                    {
                        word      = word.Substring("character:".Length);
                        position += "character:".Length;
                        match     = HitomiDataAnalysis.GetCharacterList(word);
                    }
                    else if (word.StartsWith("group:"))
                    {
                        word      = word.Substring("group:".Length);
                        position += "group:".Length;
                        match     = HitomiDataAnalysis.GetGroupList(word);
                    }
                    else if (word.StartsWith("series:"))
                    {
                        word      = word.Substring("series:".Length);
                        position += "series:".Length;
                        match     = HitomiDataAnalysis.GetSeriesList(word);
                    }
                    else if (word.StartsWith("type:"))
                    {
                        word      = word.Substring("type:".Length);
                        position += "type:".Length;
                        match     = HitomiDataAnalysis.GetTypeList(word);
                    }
                    else if (word.StartsWith("lang:"))
                    {
                        word      = word.Substring("lang:".Length);
                        position += "lang:".Length;
                        match     = HitomiDataAnalysis.GetLanguageList(word);
                    }
                }

                string[] match_target =
                {
                    "artist:",
                    "character:",
                    "group:",
                    "recent:",
                    "series:",
                    "tag:",
                    "tagx:",
                    "type:",
                    "lang:"
                };

                List <HitomiTagdata> data_col = (from ix in match_target where ix.StartsWith(word) select new HitomiTagdata {
                    Tag = ix
                }).ToList();
                if (Settings.Instance.Hitomi.CustomAutoComplete != null)
                {
                    data_col.AddRange(from ix in Settings.Instance.Hitomi.CustomAutoComplete where ix.StartsWith(word) select new HitomiTagdata {
                        Tag = ix
                    });
                }
                if (data_col.Count > 0)
                {
                    match.AddRange(data_col);
                }
                match.AddRange(HitomiDataAnalysis.GetTotalList(word));
            }
            else if (specific_tag)
            {
                match = HitomiDataAnalysis.GetTagList(word, true);
            }
            else
            {
                match = HitomiDataAnalysis.GetArtistList(word, true);
            }

            if (match.Count > 0)
            {
                AutoComplete.IsOpen = true;
                AutoCompleteList.Items.Clear();
                List <string> listing = new List <string>();
                for (int i = 0; i < SettingWrap.Instance.MaxCountOfAutoCompleteResult && i < match.Count; i++)
                {
                    if (match[i].Count != 0)
                    {
                        listing.Add(match[i].Tag + $" ({match[i].Count})");
                    }
                    else
                    {
                        listing.Add(match[i].Tag);
                    }
                }
                var MaxColoredTextLength = word.Length;
                var ColoredTargetText    = word;
                listing.ForEach(x => {
                    if (SettingWrap.Instance.DoNotHightlightAutoCompleteResults)
                    {
                        AutoCompleteList.Items.Add(x);
                    }
                    else if (!Settings.Instance.Hitomi.UsingFuzzy)
                    {
                        try
                        {
                            var Result                   = new TextBlock();
                            Result.Foreground            = Brushes.Black;
                            int StartColoredTextPosition = x.IndexOf(ColoredTargetText);
                            string firstdraw             = x.Substring(0, StartColoredTextPosition);
                            Result.Text                  = firstdraw;

                            var Detected        = new Run();
                            Detected.Foreground = Brushes.HotPink;
                            string seconddraw   = x.Substring(StartColoredTextPosition, MaxColoredTextLength);
                            Detected.Text       = seconddraw;

                            var Postfix        = new Run();
                            Postfix.Foreground = Brushes.Black;
                            Postfix.Text       = x.Substring(StartColoredTextPosition + MaxColoredTextLength);

                            Result.Inlines.Add(Detected);
                            Result.Inlines.Add(Postfix);
                            AutoCompleteList.Items.Add(Result);
                        }
                        catch
                        {
                        }
                    }
                    else
                    {
                        try
                        {
                            var Result        = new TextBlock();
                            Result.Foreground = Brushes.Black;
                            string prefix     = "";
                            if (x.Contains(":") && !ColoredTargetText.Contains(":") && x.Split(':')[1] != "")
                            {
                                prefix = x.Split(':')[0] + ":";
                                x      = x.Split(':')[1];
                            }
                            string postfix = x.Split(' ').Length > 1 ? x.Split(' ')[1] : "";
                            x = x.Split(' ')[0];

                            if (prefix != "")
                            {
                                Result.Text = prefix;
                            }
                            int[] diff = Strings.GetLevenshteinDistance(x, ColoredTargetText);
                            for (int i = 0; i < x.Length; i++)
                            {
                                var Temp  = new Run();
                                Temp.Text = x[i].ToString();
                                if (diff[i + 1] == 1)
                                {
                                    Temp.Foreground = Brushes.HotPink;
                                }
                                else
                                {
                                    Temp.Foreground = Brushes.Black;
                                }
                                Result.Inlines.Add(Temp);
                            }
                            var Postfix        = new Run();
                            Postfix.Text       = postfix;
                            Postfix.Foreground = Brushes.Black;
                            Result.Inlines.Add(Postfix);
                            AutoCompleteList.Items.Add(Result);
                        }
                        catch
                        {
                        }
                    }
                });
                AutoComplete.HorizontalOffset = MeasureString(SearchText.Text.Substring(0, position)).Width;
            }
            else
            {
                AutoComplete.IsOpen = false; return;
            }

            global_position = position;
            global_text     = word;

            if (e.Key == Key.Down)
            {
                AutoCompleteList.SelectedIndex = 0;
                AutoCompleteList.Focus();
            }
            else if (e.Key == Key.Up)
            {
                AutoCompleteList.SelectedIndex = AutoCompleteList.Items.Count - 1;
                AutoCompleteList.Focus();
            }
            else if (e.Key == Key.Enter || e.Key == Key.Space)
            {
                if (SettingWrap.Instance.DoNotHightlightAutoCompleteResults)
                {
                    PutStringIntoTextBox(AutoCompleteList.Items[0].ToString());
                }
                else
                {
                    var inline = (AutoCompleteList.Items[0] as TextBlock).Inlines;
                    PutStringIntoTextBox(string.Join("", inline.Select(x => new TextRange(x.ContentStart, x.ContentEnd).Text)));
                }
            }
        }