Example #1
0
        static public string DownloadBanner(string onlineFilename, Settings.Path localPath, string localFilename)
        {
            WebClient webClient     = new WebClient();
            string    fullLocalPath = Helper.PathCombine(Settings.GetPath(localPath), localFilename);
            string    fullURL       = (DBOnlineMirror.Banners.EndsWith("/") ? DBOnlineMirror.Banners : (DBOnlineMirror.Banners + "/")) + onlineFilename;

            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(fullLocalPath));
                if (!File.Exists(fullLocalPath) || // only if the file doesn't exist
                    ImageAllocator.LoadImageFastFromFile(fullLocalPath) == null)       // or the file is damaged
                {
                    MPTVSeriesLog.Write("Downloading new Image from: " + fullURL, MPTVSeriesLog.LogLevel.Debug);
                    webClient.DownloadFile(fullURL, fullLocalPath);
                    return(fullLocalPath);
                }
                return(string.Empty);
            }
            catch (WebException ex)
            {
                MPTVSeriesLog.Write($"Banner download failed from '{fullURL}' to '{fullLocalPath.Replace("/", @"\")}'. Reason='{ex.Message}'");
                return(null);
            }
        }
Example #2
0
        static public int StartFileDownload(string fullURL, Settings.Path localPath, string localFilename)
        {
            WebClient webClient = new WebClient();

            // .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;

            int nDownloadGUID = nDownloadGUIDGenerator;

            nDownloadGUIDGenerator++;

            string fullLocalPath = Helper.PathCombine(Settings.GetPath(localPath), localFilename);

            webClient.Headers.Add("user-agent", Settings.UserAgent);
            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(fullLocalPath));
                if (!File.Exists(fullLocalPath) || // only if the file doesn't exist
                    ImageAllocator.LoadImageFastFromFile(fullLocalPath) == null)       // or the file is damaged
                {
                    webClient.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(webClient_DownloadFileCompleted);
                    webClient.DownloadFileAsync(new Uri(fullURL), fullLocalPath, nDownloadGUID);
                    webClientList.Add(nDownloadGUID, webClient);
                    return(nDownloadGUID);
                }
                return(-1);
            }
            catch (WebException)
            {
                MPTVSeriesLog.Write("File download failed (" + fullURL + ") to " + fullLocalPath.Replace("/", @"\"));
                return(-1);
            }
        }
Example #3
0
        void setFanartPreviewBackground(FanartContainer fanart)
        {
            if (fanart == null)
            {
                ClearGUIProperty(GuiProperty.FanArt_SelectedFanartResolution);
                ClearGUIProperty(GuiProperty.FanArt_SelectedPreview);
                ClearGUIProperty(GuiProperty.FanArt_SelectedFanartIsDisabled);
                ClearGUIProperty(GuiProperty.FanArt_SelectedFanartIsDefault);
                ClearGUIProperty(GuiProperty.FanArt_Source);
                return;
            }

            if (fanart.ImageType == ImageEntityType.TvDB_FanArt)
            {
                VM_TvDB_ImageFanart fanartTvDb = fanart.FanartObject as VM_TvDB_ImageFanart;
                if (fanartTvDb != null)
                {
                    SetGUIProperty(GuiProperty.FanArt_SelectedFanartResolution, fanartTvDb.BannerType2);
                }
                else
                {
                    ClearGUIProperty(GuiProperty.FanArt_SelectedFanartResolution);
                }
            }
            else
            {
                ClearGUIProperty(GuiProperty.FanArt_SelectedFanartResolution);
            }

            SetGUIProperty(GuiProperty.FanArt_SelectedFanartIsDisabled, fanart.IsImageEnabled ? Translation.No : Translation.Yes);
            SetGUIProperty(GuiProperty.FanArt_SelectedFanartIsDefault, fanart.IsImageDefault ? Translation.Yes : Translation.No);
            SetGUIProperty(GuiProperty.FanArt_Source, fanart.FanartSource);

            string preview;

            if (File.Exists(fanart.FullImagePath))
            {
                // Ensure Fanart on Disk is valid as well
                ImageAllocator.LoadImageFastFromFile(fanart.FullImagePath);
                // Should be safe to assign fullsize fanart if available
                preview = ImageAllocator.GetOtherImage(fanart.FullImagePath, default(Size), false);
            }
            else
            {
                preview = m_Facade.SelectedListItem.IconImageBig;
            }

            SetGUIProperty(GuiProperty.FanArt_SelectedPreview, preview);
        }
Example #4
0
        void setFanartPreviewBackground(FanartContainer fanart)
        {
            MainWindow.setGUIProperty("FanArt.SelectedFanartResolution", " ");
            MainWindow.setGUIProperty("FanArt.SelectedPreview", " ");
            MainWindow.setGUIProperty("FanArt.SelectedFanartIsDisabled", " ");
            MainWindow.setGUIProperty("FanArt.SelectedFanartIsDefault", " ");
            MainWindow.setGUIProperty("FanArt.Source", " ");

            if (fanart == null)
            {
                return;
            }

            if (fanart.ImageType == ImageEntityType.TvDB_FanArt)
            {
                TvDB_ImageFanartVM fanartTvDB = fanart.FanartObject as TvDB_ImageFanartVM;
                MainWindow.setGUIProperty("FanArt.SelectedFanartResolution", fanartTvDB.BannerType2);
            }

            MainWindow.setGUIProperty("FanArt.SelectedFanartIsDisabled", fanart.IsImageEnabled ? "No" : "Yes");
            MainWindow.setGUIProperty("FanArt.SelectedFanartIsDefault", fanart.IsImageDefault ? "Yes" : "No");
            MainWindow.setGUIProperty("FanArt.Source", fanart.FanartSource);

            string preview = string.Empty;

            if (File.Exists(fanart.FullImagePath))
            {
                // Ensure Fanart on Disk is valid as well
                ImageAllocator.LoadImageFastFromFile(fanart.FullImagePath);

                // Should be safe to assign fullsize fanart if available
                preview = ImageAllocator.GetOtherImage(fanart.FullImagePath, default(System.Drawing.Size), false);
            }
            else
            {
                preview = m_Facade.SelectedListItem.IconImageBig;
            }

            MainWindow.setGUIProperty("FanArt.SelectedPreview", preview);
        }