2013-04-13 23:57:10 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
using System.Linq;
|
2013-04-13 23:57:10 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2013-08-24 02:21:12 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
using NLog;
|
2013-04-13 23:57:10 +00:00
|
|
|
|
using NzbDrone.Common;
|
2013-08-10 05:00:07 +00:00
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-04-13 23:57:10 +00:00
|
|
|
|
using NzbDrone.Core.Configuration;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Update
|
|
|
|
|
{
|
2013-04-15 01:41:39 +00:00
|
|
|
|
public interface IUpdatePackageProvider
|
2013-04-13 23:57:10 +00:00
|
|
|
|
{
|
2013-04-15 01:41:39 +00:00
|
|
|
|
UpdatePackage GetLatestUpdate();
|
2013-04-13 23:57:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-04-15 01:41:39 +00:00
|
|
|
|
public class UpdatePackageProvider : IUpdatePackageProvider
|
2013-04-13 23:57:10 +00:00
|
|
|
|
{
|
2013-08-24 02:21:12 +00:00
|
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
2013-04-13 23:57:10 +00:00
|
|
|
|
private readonly IHttpProvider _httpProvider;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
private readonly Logger _logger;
|
2013-04-13 23:57:10 +00:00
|
|
|
|
|
2013-08-24 02:21:12 +00:00
|
|
|
|
public UpdatePackageProvider(IConfigFileProvider configFileProvider, IHttpProvider httpProvider, Logger logger)
|
2013-04-13 23:57:10 +00:00
|
|
|
|
{
|
2013-08-24 02:21:12 +00:00
|
|
|
|
_configFileProvider = configFileProvider;
|
2013-04-13 23:57:10 +00:00
|
|
|
|
_httpProvider = httpProvider;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
_logger = logger;
|
2013-04-13 23:57:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-24 02:21:12 +00:00
|
|
|
|
public UpdatePackage GetLatestUpdate()
|
2013-04-13 23:57:10 +00:00
|
|
|
|
{
|
2013-08-24 02:21:12 +00:00
|
|
|
|
var url = String.Format("{0}/v1/update/{1}?{2}", Services.RootUrl, _configFileProvider.Branch, BuildInfo.Version);
|
|
|
|
|
var update = JsonConvert.DeserializeObject<UpdatePackageAvailable>(_httpProvider.DownloadString(url));
|
2013-04-13 23:57:10 +00:00
|
|
|
|
|
2013-08-24 02:21:12 +00:00
|
|
|
|
if (!update.Available) return null;
|
2013-04-13 23:57:10 +00:00
|
|
|
|
|
2013-08-24 02:21:12 +00:00
|
|
|
|
return update.UpdatePackage;
|
2013-04-15 01:41:39 +00:00
|
|
|
|
}
|
2013-04-13 23:57:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|