Lidarr/src/NzbDrone.Core/HealthCheck/Checks/UpdateCheck.cs

60 lines
2.1 KiB
C#
Raw Normal View History

2014-02-26 05:40:47 +00:00
using System;
using System.IO;
using NzbDrone.Common.Disk;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
2014-02-26 05:40:47 +00:00
using NzbDrone.Core.Update;
namespace NzbDrone.Core.HealthCheck.Checks
{
public class UpdateCheck : HealthCheckBase
2014-02-26 05:40:47 +00:00
{
private readonly IDiskProvider _diskProvider;
private readonly IAppFolderInfo _appFolderInfo;
private readonly ICheckUpdateService _checkUpdateService;
private readonly IConfigFileProvider _configFileProvider;
2014-02-26 05:40:47 +00:00
public UpdateCheck(IDiskProvider diskProvider,
IAppFolderInfo appFolderInfo,
ICheckUpdateService checkUpdateService,
IConfigFileProvider configFileProvider)
2014-02-26 05:40:47 +00:00
{
_diskProvider = diskProvider;
_appFolderInfo = appFolderInfo;
_checkUpdateService = checkUpdateService;
_configFileProvider = configFileProvider;
2014-02-26 05:40:47 +00:00
}
2014-12-07 20:54:07 +00:00
public override HealthCheck Check()
2014-02-26 05:40:47 +00:00
{
2014-12-07 20:54:07 +00:00
if (OsInfo.IsWindows || _configFileProvider.UpdateAutomatically)
2014-02-26 05:40:47 +00:00
{
if (!_diskProvider.FolderWritable(_appFolderInfo.StartUpFolder))
2014-02-26 05:40:47 +00:00
{
return new HealthCheck(GetType(), HealthCheckResult.Error,
string.Format("Cannot install update because startup folder '{0}' is not writable by the user '{1}'.", _appFolderInfo.StartUpFolder, Environment.UserName),
"Cannot install update because startup folder is not writable by the user");
2014-02-26 05:40:47 +00:00
}
}
if (BuildInfo.BuildDateTime < DateTime.UtcNow.AddDays(-14))
{
if (_checkUpdateService.AvailableUpdate() != null)
{
return new HealthCheck(GetType(), HealthCheckResult.Warning, "New update is available");
2014-02-26 05:40:47 +00:00
}
}
return new HealthCheck(GetType());
}
public override bool CheckOnConfigChange
{
get
{
return false;
}
2014-02-26 05:40:47 +00:00
}
}
}