65 lines
No EOL
2.4 KiB
C#
65 lines
No EOL
2.4 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using Plume.Core.Logging;
|
|
using Plume.Icons;
|
|
using ShuttleInstaller;
|
|
|
|
namespace Orbit.AfterEffects.Actions
|
|
{
|
|
public class InstallAfterEffectsPluginAction : BaseAction
|
|
{
|
|
private readonly IShuttleInstaller _serverInstaller;
|
|
private readonly ILogger _installerLogger;
|
|
|
|
public InstallAfterEffectsPluginAction(IShuttleInstaller serverInstaller) :
|
|
base("Install Orbit Plugin", "Install the Orbit Plugin.", null)
|
|
{
|
|
_serverInstaller = serverInstaller ?? throw new ArgumentNullException(nameof(serverInstaller));
|
|
|
|
Icon = new Icon(GetType().Assembly, "Resources/install.png");
|
|
|
|
// TODO: make Intialize method virtual so it can be overriden, and put the following code in it (and remove the App.Current call)
|
|
_installerLogger = App.Current.LoggerManager.GetOrCreateLogger(_serverInstaller.GetType().Name);
|
|
_serverInstaller.CheckInstallation(_installerLogger);
|
|
}
|
|
|
|
public override void TryExecute()
|
|
{
|
|
_serverInstaller.CheckInstallation(_installerLogger);
|
|
if (_serverInstaller.IsProperlyInstalled)
|
|
{
|
|
Context.NotificationManager.ShowInformation("Plugin is alreaady installed.");
|
|
return;
|
|
}
|
|
|
|
App.Current.TaskManager.ExecuteAsync(ExecuteInstallation, "Install Shuttle");
|
|
}
|
|
|
|
private async Task ExecuteInstallation()
|
|
{
|
|
Context.NotificationManager.ShowInformation("Installing plugin...");
|
|
|
|
_serverInstaller.Uninstall(_installerLogger);
|
|
_serverInstaller.Install(_installerLogger);
|
|
|
|
_serverInstaller.CheckInstallation(_installerLogger);
|
|
if (!_serverInstaller.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 !_serverInstaller.IsProperlyInstalled;
|
|
}
|
|
}
|
|
} |