public static bool DownloadImage(string url, string localFile)
{
WebClient webClient = new WebClient();
webClient.Headers.Add("user-agent", TraktSettings.UserAgent);
try
{
Directory.CreateDirectory(Path.GetDirectoryName(localFile));
if (!File.Exists(localFile))
{
TraktLogger.Debug("Downloading new image. Url = '{0}', Filename = '{1}'", url, localFile);
webClient.DownloadFile(url, localFile);
}
return true;
}
catch (Exception)
{
TraktLogger.Warning("Image download failed. Url = '{0}', Filename = '{1}'", url, localFile);
try { if (File.Exists(localFile)) File.Delete(localFile); } catch { }
return false;
}
}