private void SearchMaterialElements_Loaded(object sender, RoutedEventArgs e)
        {
            if (init)
            {
                return;
            }
            init = true;
            Task.Run(() =>
            {
                HitomiArticle ha = Article as HitomiArticle;
                try
                {
                    ha.Thumbnail = HitomiCommon.HitomiThumbnail + HitomiParser.ParseGalleryBlock(Koromo_Copy.Net.NetCommon.DownloadString(
                                                                                                     $"{HitomiCommon.HitomiGalleryBlock}{ha.Magic}.html")).Thumbnail;
                    var info      = Koromo_Copy.Net.NetCommon.DownloadString(HitomiCommon.GetImagesLinkAddress(ha.Magic));
                    ha.ImagesLink = HitomiParser.GetImageLink(info);
                    ha.HasWebp    = HitomiParser.CheckHasWebp(info);
                    ha.Hashs      = HitomiParser.GetHash(info);
                }
                catch
                {
                    ha.IsUnstable = true;
                    var har       = HCommander.GetArticleData(Convert.ToInt32(ha.Magic));
                    if (!har.HasValue)
                    {
                        MessageBox.Show($"{ha.Magic}를 찾을 수 없습니다. 이 항목은 히요비, 이헨, 익헨 어디에도 없었습니다. 프로그램 제작자에게 문의하세요.", "Koromo copy", MessageBoxButton.OK, MessageBoxImage.Error);
                        return;
                    }
                    ha.UnstableModel = har.Value;
                    ha.Thumbnail     = ha.UnstableModel.Thumbnail;
                    ha.ImagesLink    = new List <string>();
                }
                Application.Current.Dispatcher.BeginInvoke(new Action(
                                                               delegate
                {
                    try
                    {
                        if (ha.IsUnstable && ha.UnstableModel.ArticleType == HArticleType.EXHentai)
                        {
                            var image = NetCommon.GetExHentaiClient().DownloadData(new Uri(ha.UnstableModel.Thumbnail));
                            using (var ms = new System.IO.MemoryStream(image))
                            {
                                BitmapImage.BeginInit();
                                if (Settings.Instance.Model.LowQualityImage)
                                {
                                    BitmapImage.DecodePixelWidth = 100;
                                }
                                BitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                                BitmapImage.StreamSource = ms;
                                BitmapImage.EndInit();
                            }
                        }
                        else
                        {
                            BitmapImage.BeginInit();
                            BitmapImage.UriSource = new Uri(ha.Thumbnail);
                            if (Settings.Instance.Model.LowQualityImage)
                            {
                                BitmapImage.DecodePixelWidth = 100;
                            }
                            BitmapImage.EndInit();
                            BitmapImage.DownloadCompleted += B_DownloadCompleted;
                        }
                    }
                    catch (Exception ex)
                    {
                        Monitor.Instance.Push("[SME Error] " + ex.Message + "\r\n" + ex.StackTrace);
                    }

                    ImageCount.Text = ha.ImagesLink.Count + " Pages";
                    Image.Source    = BitmapImage;

                    if (ha.Artists != null && ha.Artists[0].ToUpper() != "N/A")
                    {
                        var stack = new StackPanel {
                            Orientation = Orientation.Horizontal
                        };
                        stack.Children.Add(new PackIcon {
                            Kind = PackIconKind.Artist, Opacity = .56
                        });
                        stack.Children.Add(new TextBlock {
                            Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "작가 목록"
                        });
                        var menu_item = new MenuItem {
                            Header = stack
                        };
                        foreach (var artist in ha.Artists)
                        {
                            var item = new MenuItem {
                                Header = new TextBlock {
                                    Text = artist
                                }, Tag = $"artist:{artist.Replace(' ', '_')}"
                            };
                            item.Click += MenuItem_Click;
                            menu_item.Items.Add(item);
                        }
                        Menu.Items.Add(menu_item);
                    }
                    if (ha.Groups != null && ha.Groups[0].ToUpper() != "N/A")
                    {
                        var stack = new StackPanel {
                            Orientation = Orientation.Horizontal
                        };
                        stack.Children.Add(new PackIcon {
                            Kind = PackIconKind.UserGroup, Opacity = .56
                        });
                        stack.Children.Add(new TextBlock {
                            Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "그룹 목록"
                        });
                        var menu_item = new MenuItem {
                            Header = stack
                        };
                        foreach (var group in ha.Groups)
                        {
                            var item = new MenuItem {
                                Header = new TextBlock {
                                    Text = group
                                }, Tag = $"group:{group.Replace(' ', '_')}"
                            };
                            item.Click += MenuItem_Click;
                            menu_item.Items.Add(item);
                        }
                        Menu.Items.Add(menu_item);
                    }
                    if (ha.Series != null)
                    {
                        var stack = new StackPanel {
                            Orientation = Orientation.Horizontal
                        };
                        stack.Children.Add(new PackIcon {
                            Kind = PackIconKind.Book, Opacity = .56
                        });
                        stack.Children.Add(new TextBlock {
                            Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "시리즈 목록"
                        });
                        var menu_item = new MenuItem {
                            Header = stack
                        };
                        foreach (var series in ha.Series)
                        {
                            MenuItem item = null;
                            if (KoreanSeries.SeriesMap(series) == series)
                            {
                                item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = series
                                    }, Tag = $"series:{series.Replace(' ', '_')}"
                                }
                            }
                            ;
                            else
                            {
                                item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = $"{series} ({KoreanSeries.SeriesMap(series)})"
                                    }, Tag = $"series:{series.Replace(' ', '_')}"
                                }
                            };
                            item.Click += MenuItem_Click;
                            menu_item.Items.Add(item);
                        }
                        Menu.Items.Add(menu_item);
                    }
                    if (ha.Tags != null)
                    {
                        var stack = new StackPanel {
                            Orientation = Orientation.Horizontal
                        };
                        stack.Children.Add(new PackIcon {
                            Kind = PackIconKind.Tag, Opacity = .56
                        });
                        stack.Children.Add(new TextBlock {
                            Margin = new Thickness(8, 0, 0, 0), VerticalAlignment = VerticalAlignment.Center, Text = "태그 목록"
                        });
                        var menu_item = new MenuItem {
                            Header = stack
                        };
                        foreach (var tag in ha.Tags)
                        {
                            MenuItem item = null;
                            if (KoreanTag.TagMap(tag) == tag)
                            {
                                item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = tag
                                    }, Tag = $"{(tag.StartsWith("female:") || tag.StartsWith("male:") ? tag.Replace(' ', '_') : $"tag:{tag.Replace(' ', '_')}")}"
                                }
                            }
                            ;
                            else if (KoreanTag.TagMap(tag).Contains(':'))
                            {
                                item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = $"{tag} ({KoreanTag.TagMap(tag).Split(':')[1]})"
                                    }, Tag = $"{(tag.StartsWith("female:") || tag.StartsWith("male:") ? tag.Replace(' ', '_') : $"tag:{tag.Replace(' ', '_')}")}"
                                }
                            }
                            ;
                            else
                            {
                                item = new MenuItem {
                                    Header = new TextBlock {
                                        Text = $"{tag} ({KoreanTag.TagMap(tag)})"
                                    }, Tag = $"{(tag.StartsWith("female:") || tag.StartsWith("male:") ? tag.Replace(' ', '_') : $"tag:{tag.Replace(' ', '_')}")}"
                                }
                            };
                            item.Click += MenuItem_Click;
                            menu_item.Items.Add(item);
                        }
                        Menu.Items.Add(menu_item);
                    }
                }));
            });
示例#2
0
 private void SearchElements_Loaded(object sender, EventArgs ex)
 {
     if (init)
     {
         return;
     }
     init = true;
     Task.Run(() =>
     {
         HitomiArticle ha = Article as HitomiArticle;
         try
         {
             ha.Thumbnail = HitomiCommon.HitomiThumbnail + HitomiParser.ParseGalleryBlock(Koromo_Copy.Net.NetCommon.DownloadString(
                                                                                              $"{HitomiCommon.HitomiGalleryBlock}{ha.Magic}.html")).Thumbnail;
             var info      = Koromo_Copy.Net.NetCommon.DownloadString(HitomiCommon.GetImagesLinkAddress(ha.Magic));
             ha.ImagesLink = HitomiParser.GetImageLink(info);
             ha.HasWebp    = HitomiParser.CheckHasWebp(info);
             ha.Hashs      = HitomiParser.GetHash(info);
         }
         catch
         {
             ha.IsUnstable = true;
             var har       = HCommander.GetArticleData(Convert.ToInt32(ha.Magic));
             if (!har.HasValue)
             {
                 Koromo_Copy.Console.Console.Instance.WriteErrorLine($"Cannot find '{ha.Magic}'! This item was not found in Hiyobi, Ex-Hentai, and Hitomi. Contact to the developer.\r\n" +
                                                                     "Run program as an administrator, or use a DPI program or VPN.");
                 return;
             }
             ha.UnstableModel = har.Value;
             ha.Thumbnail     = ha.UnstableModel.Thumbnail;
             ha.ImagesLink    = new List <string>();
         }
         Application.Current.Dispatcher.BeginInvoke(new Action(
                                                        delegate
         {
             try
             {
                 if (ha.IsUnstable && ha.UnstableModel.ArticleType == HArticleType.EXHentai)
                 {
                     var image = NetCommon.GetExHentaiClient().DownloadData(new Uri(ha.UnstableModel.Thumbnail));
                     using (var ms = new System.IO.MemoryStream(image))
                     {
                         BitmapImage.BeginInit();
                         if (Settings.Instance.Model.LowQualityImage)
                         {
                             BitmapImage.DecodePixelWidth = 100;
                         }
                         BitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                         BitmapImage.StreamSource = ms;
                         BitmapImage.EndInit();
                     }
                 }
                 else
                 {
                     BitmapImage.BeginInit();
                     BitmapImage.UriSource = new Uri(ha.Thumbnail);
                     if (Settings.Instance.Model.LowQualityImage)
                     {
                         BitmapImage.DecodePixelWidth = 100;
                     }
                     BitmapImage.EndInit();
                     BitmapImage.DownloadCompleted += B_DownloadCompleted;
                 }
                 if (!ha.IsUnstable)
                 {
                     Page.Text = ha.ImagesLink.Count + " Pages";
                 }
                 else
                 {
                     Page.Text = ha.UnstableModel.Length + " Pages";
                 }
                 Image.Source  = BitmapImage;
                 Image.Stretch = Stretch.Uniform;
                 Image.Width   = BitmapImage.Width * 200 / BitmapImage.Height;
             }
             catch (Exception e)
             {
                 Monitor.Instance.Push($"[Search Elements] isunstable={ha.IsUnstable} article_type={ha.UnstableModel}" +
                                       $" thumbnail={(ha.UnstableModel.Thumbnail ?? ha.Thumbnail)}" +
                                       $"\r\n{e.Message}\r\n{e.StackTrace}");
             }
         }));
     });
 }
 private void SearchElements_Loaded(object sender, EventArgs ex)
 {
     if (init)
     {
         return;
     }
     init = true;
     Task.Run(() =>
     {
         HitomiArticle ha = Article;
         try
         {
             ha.Thumbnail = HitomiCommon.HitomiThumbnail + HitomiParser.ParseGalleryBlock(Koromo_Copy.Net.NetCommon.DownloadString(
                                                                                              $"{HitomiCommon.HitomiGalleryBlock}{ha.Magic}.html")).Thumbnail;
             var info      = Koromo_Copy.Net.NetCommon.DownloadString(HitomiCommon.GetImagesLinkAddress(ha.Magic));
             ha.ImagesLink = HitomiParser.GetImageLink(info);
             ha.HasWebp    = HitomiParser.CheckHasWebp(info);
             ha.Hashs      = HitomiParser.GetHash(info);
         }
         catch
         {
             ha.IsUnstable = true;
             var har       = HCommander.GetArticleData(Convert.ToInt32(ha.Magic));
             if (!har.HasValue)
             {
                 MessageBox.Show($"{ha.Magic}를 찾을 수 없습니다. 이 항목은 히요비, 이헨, 익헨 어디에도 없었습니다. 프로그램 제작자에게 문의하세요.", "Koromo copy", MessageBoxButton.OK, MessageBoxImage.Error);
                 return;
             }
             ha.UnstableModel = har.Value;
             ha.Thumbnail     = ha.UnstableModel.Thumbnail;
             ha.ImagesLink    = new List <string>();
         }
         Application.Current.Dispatcher.BeginInvoke(new Action(
                                                        delegate
         {
             if (ha.IsUnstable && ha.UnstableModel.ArticleType == HArticleType.EXHentai)
             {
                 var image = NetCommon.GetExHentaiClient().DownloadData(new Uri(ha.UnstableModel.Thumbnail));
                 using (var ms = new System.IO.MemoryStream(image))
                 {
                     BitmapImage.BeginInit();
                     if (Settings.Instance.Model.LowQualityImage)
                     {
                         BitmapImage.DecodePixelWidth = 100;
                     }
                     BitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                     BitmapImage.StreamSource = ms;
                     BitmapImage.EndInit();
                 }
             }
             else
             {
                 BitmapImage.BeginInit();
                 BitmapImage.UriSource = new Uri(ha.Thumbnail);
                 if (Settings.Instance.Model.LowQualityImage)
                 {
                     BitmapImage.DecodePixelWidth = 100;
                 }
                 BitmapImage.EndInit();
                 BitmapImage.DownloadCompleted += B_DownloadCompleted;
             }
             Page.Text     = ha.ImagesLink.Count + " Pages";
             Image.Source  = BitmapImage;
             Image.Stretch = Stretch.Uniform;
             Image.Width   = BitmapImage.Width * 500 / BitmapImage.Height;
         }));
     });
 }