1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-16 16:04:08 +01:00
Radarr/NzbDrone.Core/Update/UpdatePackageProvider.cs

41 lines
1.3 KiB
C#
Raw Normal View History

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