예제 #1
0
파일: Helper.cs 프로젝트: framug/mptvseries
        public static bool DownloadFile(string url, string localFile)
        {
            WebClient webClient = new WebClient();

            webClient.Headers.Add("user-agent", Settings.UserAgent);

            // .NET 4.0: Use TLS v1.2. Many download sources no longer support the older and now insecure TLS v1.0/1.1 and SSL v3.
            ServicePointManager.SecurityProtocol = ( SecurityProtocolType )0xc00;

            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                if (!File.Exists(localFile) || ImageAllocator.LoadImageFastFromFile(localFile) == null)
                {
                    MPTVSeriesLog.Write("Downloading new file from: " + url, MPTVSeriesLog.LogLevel.Debug);
                    webClient.DownloadFile(url, localFile);
                }
                return(true);
            }
            catch (WebException)
            {
                MPTVSeriesLog.Write("File download failed from '{0}' to '{1}'", url, localFile);
                return(false);
            }
        }
예제 #2
0
        static void appendLogos(List <string> logosForBuilding, ref Graphics g, int totalHeight, int totalWidth)
        {
            int          noImgs     = logosForBuilding.Count;
            List <Image> imgs       = new List <Image>();
            List <Size>  imgSizes   = new List <Size>();
            int          spacer     = 5;
            int          checkWidth = 0;
            // step one: get all sizes (not all logos are obviously square) and scale them to fit vertically
            Image single = null;
            float scale = 0, totalHeightf = (float)totalHeight;
            Size  tmp   = default(Size);
            int   x_pos = 0;

            for (int i = 0; i < logosForBuilding.Count; i++)
            {
                try
                {
                    single = ImageAllocator.LoadImageFastFromFile(logosForBuilding[i]);
                }
                catch (Exception)
                {
                    MPTVSeriesLog.Write("Could not load Image file... " + logosForBuilding[i]);
                    return;
                }
                scale       = totalHeightf / (float)single.Size.Height;
                tmp         = new Size((int)(single.Width * scale), (int)(single.Height * scale));
                checkWidth += tmp.Width;
                imgSizes.Add(tmp);
                imgs.Add(single);
            }
            // step two: check if we are too big horizontally and if so scale again
            checkWidth += imgSizes.Count * spacer;
            if (checkWidth > totalWidth)
            {
                scale = (float)checkWidth / (float)totalWidth;
                for (int i = 0; i < imgSizes.Count; i++)
                {
                    imgSizes[i] = new Size((int)(imgSizes[i].Width / scale), (int)(imgSizes[i].Height / scale));
                }
            }
            // step three: finally draw them
            for (int i = 0; i < imgs.Count; i++)
            {
                g.DrawImage(imgs[i], x_pos, totalHeight - imgSizes[i].Height, imgSizes[i].Width, imgSizes[i].Height);
                x_pos += imgSizes[i].Width + spacer;
            }
        }
예제 #3
0
        public static bool DownloadFile(string url, string localFile)
        {
            WebClient webClient = new WebClient();

            webClient.Headers.Add("user-agent", Settings.UserAgent);

            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(localFile));
                if (!File.Exists(localFile) || ImageAllocator.LoadImageFastFromFile(localFile) == null)
                {
                    MPTVSeriesLog.Write("Downloading new file from: " + url, MPTVSeriesLog.LogLevel.Debug);
                    webClient.DownloadFile(url, localFile);
                }
                return(true);
            }
            catch (WebException)
            {
                MPTVSeriesLog.Write("File download failed from '{0}' to '{1}'", url, localFile);
                return(false);
            }
        }