JD2022-TU1/main/tools/modules/Orbit.Module/Actions/InstallShuttlePluginAction.cs

64 lines
No EOL
2.6 KiB
C#

using System;
using System.Threading.Tasks;
using Plume.Core.Logging;
using Plume.Icons;
using Plume.Interfaces.WPF.LongTasks;
using ShuttleInstaller;
using Action = Plume.Interfaces.WPF.Actions.Action;
namespace Orbit.Module.Actions.PhotoshopActions
{
public class InstallShuttlePluginAction : Action
{
private readonly IShuttleInstaller _shuttleInstaller;
private readonly ILogger _installerLogger;
private readonly ITaskManager _taskManager;
public InstallShuttlePluginAction(IShuttleInstaller shuttleInstaller, ILogger installerLogger, ITaskManager taskManager)
: base("Install Orbit Plugin", "Install the Orbit Plugin.", null)
{
Icon = new Icon(GetType().Assembly, "Resources/install.png");
_shuttleInstaller = shuttleInstaller ?? throw new ArgumentNullException(nameof(shuttleInstaller));
_installerLogger = installerLogger ?? throw new ArgumentNullException(nameof(installerLogger));
_taskManager = taskManager ?? throw new ArgumentNullException(nameof(taskManager));
_shuttleInstaller.CheckInstallation(installerLogger);
}
public override void TryExecute()
{
_shuttleInstaller.CheckInstallation(_installerLogger);
if (_shuttleInstaller.IsProperlyInstalled)
{
Context.NotificationManager.ShowInformation("Plugin is alreaady installed.");
return;
}
_taskManager.ExecuteAsync(ExecuteInstallation, "Install Shuttle");
}
private async Task ExecuteInstallation()
{
Context.NotificationManager.ShowInformation("Installing plugin...");
_shuttleInstaller.Uninstall(_installerLogger);
_shuttleInstaller.Install(_installerLogger);
_shuttleInstaller.CheckInstallation(_installerLogger);
if (!_shuttleInstaller.IsProperlyInstalled)
{
throw new InvalidOperationException("Installation failed.");
}
// The installation is so fast, users cannot understand something just happened
await Task.Delay(1000);
Context.NotificationManager.ShowInformation("Please follow the given instructions to finish the installation!");
// TODO: quick and dirty, open a documentation page
System.Diagnostics.Process.Start(@"https://mdc-web-tomcat17.ubisoft.org/confluence/x/3MbTIg");
}
public override bool CanExecute()
{
return !_shuttleInstaller.IsProperlyInstalled;
}
}
}