2014-04-28 09:34:29 +03:00
|
|
|
using System.Collections.Generic;
|
2013-10-05 11:15:48 +03:00
|
|
|
using System.Linq;
|
2013-10-07 01:22:43 +03:00
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2013-05-20 03:30:02 +03:00
|
|
|
using NzbDrone.Core.Update;
|
|
|
|
using NzbDrone.Api.Mapping;
|
|
|
|
|
|
|
|
namespace NzbDrone.Api.Update
|
|
|
|
{
|
|
|
|
public class UpdateModule : NzbDroneRestModule<UpdateResource>
|
|
|
|
{
|
2013-09-28 21:48:30 +03:00
|
|
|
private readonly IRecentUpdateProvider _recentUpdateProvider;
|
2013-05-20 03:30:02 +03:00
|
|
|
|
2014-09-12 02:49:41 +03:00
|
|
|
public UpdateModule(IRecentUpdateProvider recentUpdateProvider)
|
2013-05-20 03:30:02 +03:00
|
|
|
{
|
2013-09-28 21:48:30 +03:00
|
|
|
_recentUpdateProvider = recentUpdateProvider;
|
|
|
|
GetResourceAll = GetRecentUpdates;
|
2013-05-20 03:30:02 +03:00
|
|
|
}
|
|
|
|
|
2013-10-05 11:15:48 +03:00
|
|
|
private List<UpdateResource> GetRecentUpdates()
|
2013-05-20 03:30:02 +03:00
|
|
|
{
|
2013-10-05 11:15:48 +03:00
|
|
|
var resources = _recentUpdateProvider.GetRecentUpdatePackages()
|
|
|
|
.OrderByDescending(u => u.Version)
|
|
|
|
.InjectTo<List<UpdateResource>>();
|
2013-05-20 03:30:02 +03:00
|
|
|
|
2013-10-07 01:22:43 +03:00
|
|
|
foreach (var updateResource in resources)
|
2013-05-20 03:30:02 +03:00
|
|
|
{
|
2013-10-07 01:22:43 +03:00
|
|
|
if (updateResource.Version > BuildInfo.Version)
|
|
|
|
{
|
|
|
|
updateResource.IsUpgrade = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (updateResource.Version == BuildInfo.Version)
|
|
|
|
{
|
|
|
|
updateResource.Installed = true;
|
|
|
|
}
|
2013-05-20 03:30:02 +03:00
|
|
|
}
|
|
|
|
|
2013-10-05 11:15:48 +03:00
|
|
|
return resources;
|
2013-05-20 03:30:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|