2017-10-27 03:21:06 +00:00
|
|
|
using System;
|
2014-02-26 05:40:47 +00:00
|
|
|
using System.IO;
|
|
|
|
using NzbDrone.Common.Disk;
|
|
|
|
using NzbDrone.Common.EnvironmentInfo;
|
2016-11-02 18:09:29 +00:00
|
|
|
using NzbDrone.Common.Extensions;
|
2014-06-07 19:19:37 +00:00
|
|
|
using NzbDrone.Core.Configuration;
|
2017-10-27 03:21:06 +00:00
|
|
|
using NzbDrone.Core.Configuration.Events;
|
2014-02-26 05:40:47 +00:00
|
|
|
using NzbDrone.Core.Update;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.HealthCheck.Checks
|
|
|
|
{
|
2017-10-27 03:21:06 +00:00
|
|
|
[CheckOn(typeof(ConfigFileSavedEvent))]
|
2014-04-10 00:15:13 +00:00
|
|
|
public class UpdateCheck : HealthCheckBase
|
2014-02-26 05:40:47 +00:00
|
|
|
{
|
|
|
|
private readonly IDiskProvider _diskProvider;
|
|
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
private readonly ICheckUpdateService _checkUpdateService;
|
2014-06-07 19:19:37 +00:00
|
|
|
private readonly IConfigFileProvider _configFileProvider;
|
2014-02-26 05:40:47 +00:00
|
|
|
|
2014-06-07 19:19:37 +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;
|
2014-06-07 19:19:37 +00:00
|
|
|
_configFileProvider = configFileProvider;
|
2014-02-26 05:40:47 +00:00
|
|
|
}
|
2014-12-07 20:54:07 +00:00
|
|
|
|
2014-04-10 00:15:13 +00:00
|
|
|
public override HealthCheck Check()
|
2014-02-26 05:40:47 +00:00
|
|
|
{
|
2016-01-25 03:22:07 +00:00
|
|
|
var startupFolder = _appFolderInfo.StartUpFolder;
|
|
|
|
var uiFolder = Path.Combine(startupFolder, "UI");
|
|
|
|
|
2015-12-27 19:40:37 +00:00
|
|
|
if ((OsInfo.IsWindows || _configFileProvider.UpdateAutomatically) &&
|
|
|
|
_configFileProvider.UpdateMechanism == UpdateMechanism.BuiltIn)
|
2014-02-26 05:40:47 +00:00
|
|
|
{
|
2016-11-02 18:09:29 +00:00
|
|
|
if (OsInfo.IsOsx && startupFolder.GetAncestorFolders().Contains("AppTranslocation"))
|
|
|
|
{
|
|
|
|
return new HealthCheck(GetType(), HealthCheckResult.Error,
|
|
|
|
string.Format("Cannot install update because startup folder '{0}' is in an App Translocation folder.", startupFolder),
|
|
|
|
"Cannot install update because startup folder is in an App Translocation folder.");
|
|
|
|
}
|
|
|
|
|
2016-01-25 03:22:07 +00:00
|
|
|
if (!_diskProvider.FolderWritable(startupFolder))
|
2014-02-26 05:40:47 +00:00
|
|
|
{
|
2015-02-05 07:52:58 +00:00
|
|
|
return new HealthCheck(GetType(), HealthCheckResult.Error,
|
2016-01-25 03:22:07 +00:00
|
|
|
string.Format("Cannot install update because startup folder '{0}' is not writable by the user '{1}'.", startupFolder, Environment.UserName),
|
2015-02-05 07:52:58 +00:00
|
|
|
"Cannot install update because startup folder is not writable by the user");
|
2014-02-26 05:40:47 +00:00
|
|
|
}
|
2016-01-25 03:22:07 +00:00
|
|
|
|
|
|
|
if (!_diskProvider.FolderWritable(uiFolder))
|
|
|
|
{
|
|
|
|
return new HealthCheck(GetType(), HealthCheckResult.Error,
|
|
|
|
string.Format("Cannot install update because UI folder '{0}' is not writable by the user '{1}'.", uiFolder, Environment.UserName),
|
|
|
|
"Cannot install update because UI 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)
|
|
|
|
{
|
2014-04-10 00:15:13 +00:00
|
|
|
return new HealthCheck(GetType(), HealthCheckResult.Warning, "New update is available");
|
2014-02-26 05:40:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-10 00:15:13 +00:00
|
|
|
return new HealthCheck(GetType());
|
|
|
|
}
|
2014-02-26 05:40:47 +00:00
|
|
|
}
|
|
|
|
}
|