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); } }
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); } }