2011-11-22 06:55:09 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
2011-11-14 06:01:51 +00:00
|
|
|
|
using System.Web.Mvc;
|
2011-11-22 06:55:09 +00:00
|
|
|
|
using NzbDrone.Common;
|
2011-12-02 01:33:17 +00:00
|
|
|
|
using NzbDrone.Core.Jobs;
|
2013-02-18 07:59:43 +00:00
|
|
|
|
using NzbDrone.Core.Lifecycle;
|
2011-11-14 06:01:51 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
|
|
|
|
using NzbDrone.Web.Models;
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class UpdateController : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly UpdateProvider _updateProvider;
|
2013-02-18 07:59:43 +00:00
|
|
|
|
private readonly JobController _jobProvider;
|
2012-03-07 02:59:43 +00:00
|
|
|
|
private readonly EnvironmentProvider _environmentProvider;
|
2011-11-22 06:55:09 +00:00
|
|
|
|
private readonly DiskProvider _diskProvider;
|
2011-11-14 06:01:51 +00:00
|
|
|
|
|
2013-02-18 07:59:43 +00:00
|
|
|
|
public UpdateController(UpdateProvider updateProvider, JobController jobProvider,
|
2012-03-07 02:59:43 +00:00
|
|
|
|
EnvironmentProvider environmentProvider, DiskProvider diskProvider)
|
2011-11-14 06:01:51 +00:00
|
|
|
|
{
|
|
|
|
|
_updateProvider = updateProvider;
|
|
|
|
|
_jobProvider = jobProvider;
|
2012-03-07 02:59:43 +00:00
|
|
|
|
_environmentProvider = environmentProvider;
|
2011-11-22 06:55:09 +00:00
|
|
|
|
_diskProvider = diskProvider;
|
2011-11-14 06:01:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
2011-11-22 06:55:09 +00:00
|
|
|
|
var updateModel = new UpdateModel();
|
2012-03-07 02:59:43 +00:00
|
|
|
|
updateModel.UpdatePackage = _updateProvider.GetAvilableUpdate(_environmentProvider.Version);
|
2011-11-22 06:55:09 +00:00
|
|
|
|
updateModel.LogFiles = _updateProvider.UpdateLogFile();
|
2012-03-07 02:59:43 +00:00
|
|
|
|
updateModel.LogFolder = _environmentProvider.GetUpdateLogFolder();
|
2011-11-22 06:55:09 +00:00
|
|
|
|
|
|
|
|
|
return View(updateModel);
|
2011-11-14 06:01:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult StartUpdate()
|
|
|
|
|
{
|
2012-10-20 04:36:47 +00:00
|
|
|
|
_jobProvider.QueueJob(typeof(AppUpdateJob));
|
2011-11-14 06:01:51 +00:00
|
|
|
|
|
2012-01-19 05:01:47 +00:00
|
|
|
|
return JsonNotificationResult.Info("Update will begin shortly", "NzbDrone will restart automatically.");
|
2011-11-22 06:55:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActionResult ViewLog( string filepath)
|
|
|
|
|
{
|
|
|
|
|
ViewBag.Log = _diskProvider.ReadAllText(filepath).Replace(Environment.NewLine, "<br/>");
|
|
|
|
|
return View();
|
2011-11-14 06:01:51 +00:00
|
|
|
|
}
|
2012-02-29 00:59:48 +00:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ActionResult Post(string expectedVersion)
|
|
|
|
|
{
|
|
|
|
|
var model = new PostUpgradeModel();
|
2012-03-07 02:59:43 +00:00
|
|
|
|
model.CurrentVersion = _environmentProvider.Version;
|
2012-02-29 00:59:48 +00:00
|
|
|
|
model.ExpectedVersion = Version.Parse(expectedVersion);
|
|
|
|
|
model.Success = model.CurrentVersion >= model.ExpectedVersion;
|
|
|
|
|
|
|
|
|
|
if (!model.Success)
|
|
|
|
|
model.LogFile = _updateProvider.UpdateLogFile().FirstOrDefault();
|
|
|
|
|
|
|
|
|
|
return View(model);
|
|
|
|
|
}
|
2011-11-14 06:01:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|