public override void DownloadImage_Click(object sender, RoutedEventArgs e) { base.DownloadImage_Click(sender, e); string filename = CF.File.GetDownloadTitle(CF.File.SaftyFileName(h.name)); for (int i = 0; i < h.files.Length; i++) { Hitomi.HFile file = h.files[i]; WebClient wc = new WebClient(); wc.Headers.Add("referer", "https://hitomi.la/"); string folder = Global.config.download_folder.Get <string>(); if (!File.Exists($"{AppDomain.CurrentDomain.BaseDirectory}/{folder}/{filename}/{i}.jpg")) { bool fileen = Global.config.download_file_encrypt.Get <bool>(); h.FileInfo.encrypted = fileen; string path = $"{AppDomain.CurrentDomain.BaseDirectory}/{folder}/{filename}/{file.name}.{InternetP.GetDirFromHFileS(file)}.lock"; if (fileen) { FileEncrypt.DownloadAsync(wc, new Uri(file.url), path + ".lock"); } else { wc.DownloadFileAsync(new Uri(file.url), path); } } } }
protected virtual void SetImage(Hitomi.HFile file) { BitmapImage LoadingImage = new BitmapImage(new Uri("/Resources/loading2.gif", UriKind.RelativeOrAbsolute)); LoadingImage.Freeze(); image.Source = LoadingImage; WpfAnimatedGif.ImageBehavior.SetAnimatedSource(image, LoadingImage); }
protected override async void SetImage(Hitomi.HFile file) { base.SetImage(file); int copypage = page; if (images == null || images.Length < hitomi.files.Length) { images = new BitmapImage[hitomi.files.Length]; } if (images[copypage] == null) { BitmapImage image = null; Task <byte[]> task = null; for (int m = 0; m < 10 && image == null; m++) { task = ImageProcessor.ProcessAsync(file.url); try { image = (await task).ToImage(); } catch { } } if (image == null && task.IsFaulted) { MessageBox.Show($"{copypage + 1}번 이미지를 불러오는데 실패했습니다.\nlatest.log 에 정보가 기록됩니다.\n{file.url}\n{task.Exception.InnerException.ToString()}"); System.Reflection.MethodBase current = System.Reflection.MethodBase.GetCurrentMethod(); task.Exception.InnerException.WriteExcept(sourceName: current.FullName()); } else { image.Freeze(); if (images.Length == hitomi.files.Length) { images[copypage] = image; } } } if (copypage == page && images.Length == hitomi.files.Length) { if (file.url.EndsWith(".gif")) { WpfAnimatedGif.ImageBehavior.SetAnimatedSource(image, images[page]); } else { WpfAnimatedGif.ImageBehavior.SetAnimatedSource(image, null); image.Source = images[page]; } ClearMemory(); } }
protected override async void PreLoad() { base.PreLoad(); if (page + 1 >= hiyobi.files.Length) { return; } int loadpage = page + 1; if (images == null || images.Length < hiyobi.files.Length) { images = new BitmapImage[hiyobi.files.Length]; } if (images[loadpage] != null) { return; } Hitomi.HFile file = hiyobi.files[loadpage]; BitmapImage image = null; Task <byte[]> task = null; for (int m = 0; m < 10 && image == null; m++) { task = ImageProcessor.ProcessAsync(file.url); try { image = (await task).ToImage(); } catch { } } if (image == null && task.IsFaulted) { MessageBox.Show($"{loadpage + 1}번 이미지를 불러오는데 실패했습니다.\nlatest.log 에 정보가 기록됩니다.\n{file.url}\n{task.Exception.InnerException.ToString()}"); System.Reflection.MethodBase current = System.Reflection.MethodBase.GetCurrentMethod(); task.Exception.InnerException.WriteExcept(sourceName: current.FullName()); } else { image.Freeze(); if (images.Length == hiyobi.files.Length) { images[loadpage] = image; } } }