|
|
@ -229,6 +229,8 @@ namespace NzbDrone.Common.Http
|
|
|
|
|
|
|
|
|
|
|
|
public void DownloadFile(string url, string fileName)
|
|
|
|
public void DownloadFile(string url, string fileName)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var fileNamePart = fileName + ".part";
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var fileInfo = new FileInfo(fileName);
|
|
|
|
var fileInfo = new FileInfo(fileName);
|
|
|
@ -240,24 +242,22 @@ namespace NzbDrone.Common.Http
|
|
|
|
_logger.Debug("Downloading [{0}] to [{1}]", url, fileName);
|
|
|
|
_logger.Debug("Downloading [{0}] to [{1}]", url, fileName);
|
|
|
|
|
|
|
|
|
|
|
|
var stopWatch = Stopwatch.StartNew();
|
|
|
|
var stopWatch = Stopwatch.StartNew();
|
|
|
|
using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite))
|
|
|
|
using (var fileStream = new FileStream(fileNamePart, FileMode.Create, FileAccess.ReadWrite))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var request = new HttpRequest(url);
|
|
|
|
var request = new HttpRequest(url);
|
|
|
|
request.ResponseStream = fileStream;
|
|
|
|
request.ResponseStream = fileStream;
|
|
|
|
var response = Get(request);
|
|
|
|
var response = Get(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stopWatch.Stop();
|
|
|
|
stopWatch.Stop();
|
|
|
|
|
|
|
|
File.Move(fileNamePart, fileName);
|
|
|
|
_logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
|
|
|
|
_logger.Debug("Downloading Completed. took {0:0}s", stopWatch.Elapsed.Seconds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (WebException e)
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
|
|
|
|
_logger.Warn("Failed to get response from: {0} {1}", url, e.Message);
|
|
|
|
|
|
|
|
throw;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.Warn(e, "Failed to get response from: " + url);
|
|
|
|
if (File.Exists(fileNamePart))
|
|
|
|
throw;
|
|
|
|
{
|
|
|
|
|
|
|
|
File.Delete(fileNamePart);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|