Exemplo n.º 1
0
        /// <summary>
        /// Starts the download
        /// </summary>
        /// <param name="sender">Event sender</param>
        /// <param name="e">Event arguments</param>
        private void FrmDownload_Shown(object sender, EventArgs e)
        {
            pbStatus.Maximum = Images.Count;
            Thread T = new Thread(delegate()
            {
                while (Images.Count > 0 && !Exit)
                {
                    ImgurImage I = Images[0];
                    Images.RemoveAt(0);
                    //Just cache if path is not defined
                    if (string.IsNullOrEmpty(Path))
                    {
                        Cache.GetImage(I);
                    }
                    else
                    {
                        string FileName = System.IO.Path.Combine(Path, I.GetImageUrl().Segments.Last());
                        if (FileName.StartsWith(Path))
                        {
                            System.IO.File.WriteAllBytes(FileName, Cache.GetImage(I));
                        }
                    }
#if DEBUG
                    System.Diagnostics.Debug.WriteLine($"URL ({I.GetImageUrl()}) tried to get out of {Path}");
#endif
                    Invoke((MethodInvoker) delegate { ++pbStatus.Value; });
                }
                Invoke((MethodInvoker)Done);
            })
            {
                IsBackground = true
            };

            T.Start();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Downloads an image from Imgur
 /// </summary>
 /// <param name="I">Imgur image</param>
 /// <param name="Size">Image size</param>
 /// <param name="AllowVideo">Allow video files</param>
 /// <returns>Image data</returns>
 /// <remarks>If <paramref name="AllowVideo"/> is <see cref="false"/>, it will use <see cref="ImgurImageSize.HugeThumbnail"/> for video files</remarks>
 public static byte[] GetImage(ImgurImage I, ImgurImageSize Size, bool AllowVideo)
 {
     using (WebClient WC = new WebClient())
     {
         if (AllowVideo || !I.type.ToLower().StartsWith("video/"))
         {
             return(WC.DownloadData(I.GetImageUrl(Size)));
         }
         return(WC.DownloadData(I.GetImageUrl(Size == ImgurImageSize.Original ? ImgurImageSize.HugeThumbnail : Size)));
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Gets the file name of a thumbnail from the cache
 /// </summary>
 /// <param name="I">Image metadata</param>
 /// <returns>File name</returns>
 public static string GetThumbnailName(ImgurImage I)
 {
     return(I.GetImageUrl(ImgurImageSize.Original).Segments.Last());
 }