WPF app CLI support

This commit is contained in:
Halgari 2022-10-14 16:46:38 -06:00
parent bb0c6c7ca9
commit 17cf1e7d00
7 changed files with 117 additions and 7 deletions

View File

@ -1,7 +1,8 @@
### Changelog
#### Version - 3.0.2.0 - ????
#### Version - 3.0.2.0 - 10/14/2022
* Show Modlist readmes after install
* Basic support for commandline options in the WPF app
#### Version - 3.0.1.9 - 10/4/2022
* Lots of compiler improvements for faster compilation

View File

@ -1,6 +1,7 @@
using System;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using Microsoft.Extensions.DependencyInjection;
@ -9,6 +10,7 @@ using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using NLog.Targets;
using ReactiveUI;
using Wabbajack.CLI.Builder;
using Wabbajack.DTOs;
using Wabbajack.DTOs.Interventions;
using Wabbajack.Interventions;
@ -34,19 +36,34 @@ namespace Wabbajack
WebView2AutoInstaller.CheckAndInstallAsync(false, false).Wait();
RxApp.MainThreadScheduler = new DispatcherScheduler(Dispatcher.CurrentDispatcher);
_host = Host.CreateDefaultBuilder(e.Args)
_host = Host.CreateDefaultBuilder(Array.Empty<string>())
.ConfigureLogging(AddLogging)
.ConfigureServices((host, services) =>
{
ConfigureServices(services);
})
.Build();
var args = e.Args;
RxApp.MainThreadScheduler.Schedule(0, (_, _) =>
{
var mainWindow = _host.Services.GetRequiredService<MainWindow>();
mainWindow!.Show();
return Disposable.Empty;
if (args.Length > 0)
{
var builder = _host.Services.GetRequiredService<CommandLineBuilder>();
builder.Run(e.Args).ContinueWith(async x =>
{
Environment.Exit(await x);
});
return Disposable.Empty;
}
else
{
var mainWindow = _host.Services.GetRequiredService<MainWindow>();
mainWindow!.Show();
return Disposable.Empty;
}
});
}
@ -123,6 +140,10 @@ namespace Wabbajack
services.AddSingleton<ManualDownloadHandler>();
services.AddSingleton<ManualBlobDownloadHandler>();
// Verbs
services.AddSingleton<CommandLineBuilder>();
services.AddCLIVerbs();
return services;
}

View File

@ -0,0 +1,13 @@

using Microsoft.Extensions.DependencyInjection;
namespace Wabbajack;
using Wabbajack.Verbs;
using Wabbajack.CLI.Builder;
public static class CommandLineBuilderExtensions{
public static void AddCLIVerbs(this IServiceCollection services) {
CommandLineBuilder.RegisterCommand<NexusLogin>(NexusLogin.Definition, c => ((NexusLogin)c).Run);
services.AddSingleton<NexusLogin>();
}
}

View File

@ -0,0 +1,29 @@
<#@ template language="C#v3.5" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.IO"#>
<#@ import namespace="System.Collections.Generic" #>
using Microsoft.Extensions.DependencyInjection;
namespace Wabbajack;
using Wabbajack.Verbs;
using Wabbajack.CLI.Builder;
public static class CommandLineBuilderExtensions{
public static void AddCLIVerbs(this IServiceCollection services) {
<#
foreach (var verb in Directory.EnumerateFiles("Verbs"))
{
var klass = verb.Split('\\').Last().Split('.').First();
if (klass == "IVerb") continue;
#>
CommandLineBuilder.RegisterCommand<<#=klass#>>(<#=klass#>.Definition, c => ((<#=klass#>)c).Run);
services.AddSingleton<<#=klass#>>();
<#
}
#>
}
}

View File

@ -0,0 +1,36 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Wabbajack.CLI.Builder;
using Wabbajack.UserIntervention;
namespace Wabbajack.Verbs;
public class NexusLogin
{
private readonly ILogger<NexusLogin> _logger;
private readonly IServiceProvider _services;
public NexusLogin(ILogger<NexusLogin> logger, IServiceProvider services)
{
_logger = logger;
_services = services;
}
public static VerbDefinition Definition = new("nexus-login", "Log into the Nexus via the normal browser method",
Array.Empty<OptionDefinition>());
public async Task<int> Run(CancellationToken token)
{
var tcs = new TaskCompletionSource<int>();
var view = new BrowserWindow();
view.Closed += (sender, args) => { tcs.TrySetResult(0); };
var provider = _services.GetRequiredService<NexusLoginHandler>();
view.DataContext = provider;
view.Show();
return await tcs.Task;
}
}

View File

@ -61,6 +61,15 @@
<None Remove="Resources\Wabba_Mouth_Small.png" />
<Compile Remove="View Models\Compilers\VortexCompilerVM.cs" />
<Compile Remove="View Models\Installers\VortexInstallerVM.cs" />
<None Update="VerbRegistration.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>VerbRegistration.cs</LastGenOutput>
</None>
<Compile Update="VerbRegistration.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>VerbRegistration.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
@ -81,7 +90,7 @@
<PackageReference Include="MahApps.Metro" Version="2.4.9" />
<PackageReference Include="MahApps.Metro.IconPacks" Version="4.11.0" />
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell" Version="1.1.4" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.2-mauipre.1.22102.15" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.1343.22" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.0.4" />
<PackageReference Include="PInvoke.User32" Version="0.7.124" />
@ -95,6 +104,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Wabbajack.CLI.Builder\Wabbajack.CLI.Builder.csproj" />
<ProjectReference Include="..\Wabbajack.Services.OSIntegrated\Wabbajack.Services.OSIntegrated.csproj" />
</ItemGroup>

View File

@ -10,7 +10,7 @@ namespace Wabbajack.CLI.Builder;
public class CommandLineBuilder
{
private static IServiceProvider _provider;
public CommandLineBuilder(IServiceProvider provider, IConsole console)
public CommandLineBuilder(IServiceProvider provider)
{
_provider = provider;
}