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;
             ha.ImagesLink = HitomiParser.GetImageLink(Koromo_Copy.Net.NetCommon.DownloadString(HitomiCommon.GetImagesLinkAddress(ha.Magic)));
         }
         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 * 200 / BitmapImage.Height;
         }));
     });
 }
예제 #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 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;
                    ha.ImagesLink = HitomiParser.GetImageLink(Koromo_Copy.Net.NetCommon.DownloadString(HitomiCommon.GetImagesLinkAddress(ha.Magic)));
                }
                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);
                    }
                }));
            });
예제 #4
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (!Addr.Text.EndsWith(".txt"))
            {
                PB.IsIndeterminate = true;
                FileIndexor fi = new FileIndexor();
                await fi.ListingDirectoryAsync(Addr.Text);

                PB.IsIndeterminate = false;

                file_list = new List <string>();
                fi.Enumerate((string path, List <FileInfo> files) =>
                {
                    foreach (var iz in files)
                    {
                        if (Path.GetExtension(iz.Name) == ".zip")
                        {
                            file_list.Add(iz.FullName);
                        }
                    }
                });

                append(file_list.Count.ToString("#,#") + "개의 Zip 파일이 검색됨");
            }
            else
            {
                var lls = File.ReadAllLines(Addr.Text);

                var pp = new List <Tuple <string, string> >();

                var rx = new Regex(@"^\[(\d+)\]");
                foreach (var article in lls)
                {
                    var f = Path.GetFileNameWithoutExtension(article);
                    if (rx.Match(Path.GetFileNameWithoutExtension(article)).Success)
                    {
                        var id     = rx.Match(System.IO.Path.GetFileNameWithoutExtension(article)).Groups[1].Value;
                        var artist = Path.GetFileName(Path.GetDirectoryName(article));

                        pp.Add(new Tuple <string, string>(id, artist));
                    }
                    else
                    {
                        append("[NO MATCH] " + article);
                    }
                }

                var articles = new List <HitomiArticle>();

                foreach (var p in pp)
                {
                    var aaa = HitomiLegalize.GetMetadataFromMagic(p.Item1);

                    if (!aaa.HasValue)
                    {
                        append("[NOT FOUND] " + p.Item1);
                        continue;
                    }

                    var xxx = HitomiLegalize.MetadataToArticle(aaa.Value);
                    xxx.Artists = new string[] { p.Item2 };
                    articles.Add(xxx);
                }

                await Task.Run(() =>
                {
                    int cnt = 0;
                    foreach (var at in articles)
                    {
                        try
                        {
                            var url       = HitomiCommon.GetImagesLinkAddress(at.Magic);
                            var imgs      = HitomiParser.GetImageLink(NetCommon.DownloadString(url));
                            at.ImagesLink = imgs;
                        }
                        catch
                        {
                            append("[FAIL DOWNLOAD] " + at.Magic);
                        }

                        cnt++;

                        Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                       delegate
                        {
                            PB.Value = cnt / (double)articles.Count * 100;
                        }));
                    }

                    int count = 0;

                    foreach (var ha in articles)
                    {
                        if (ha.ImagesLink == null)
                        {
                            continue;
                        }
                        var prefix = HitomiCommon.MakeDownloadDirectory(ha);
                        Directory.CreateDirectory(prefix);
                        DownloadSpace.Instance.RequestDownload(ha.Title,
                                                               ha.ImagesLink.Select(y => HitomiCommon.GetDownloadImageAddress(ha.Magic, y, ha.HasWebp[y], ha.HasWebp[y] || ha.Hashs[y].Length > 3 ? ha.Hashs[y] : "")).ToArray(),
                                                               ha.ImagesLink.Select(y => Path.Combine(prefix, y)).ToArray(),
                                                               Koromo_Copy.Interface.SemaphoreExtends.Default, prefix, ha);
                        count++;
                    }

                    Application.Current.Dispatcher.BeginInvoke(new Action(
                                                                   delegate
                    {
                        if (count > 0)
                        {
                            MainWindow.Instance.FadeOut_MiddlePopup($"{count}{FindResource("msg_download_start")}");
                        }
                        MainWindow.Instance.Activate();
                        MainWindow.Instance.FocusDownload();
                    }));
                });
            }
        }