wabbajack/Wabbajack.App.Wpf/View Models/Settings/SettingsVM.cs

58 lines
2.1 KiB
C#
Raw Normal View History

2021-12-26 21:56:44 +00:00
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
2021-12-27 23:15:30 +00:00
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
2021-12-26 21:56:44 +00:00
using ReactiveUI;
2021-12-30 00:15:37 +00:00
using Wabbajack;
using Wabbajack.LoginManagers;
using Wabbajack.Messages;
2021-12-27 23:15:30 +00:00
using Wabbajack.Networking.WabbajackClientApi;
using Wabbajack.Services.OSIntegrated.TokenProviders;
2021-12-27 05:53:39 +00:00
using Wabbajack.View_Models.Settings;
2021-12-26 21:56:44 +00:00
namespace Wabbajack
{
public class SettingsVM : BackNavigatingVM
{
public MainWindowVM MWVM { get; }
public LoginManagerVM Login { get; }
public PerformanceSettings Performance { get; }
public FiltersSettings Filters { get; }
public AuthorFilesVM AuthorFile { get; }
public ICommand OpenTerminalCommand { get; }
2021-12-28 21:39:20 +00:00
public SettingsVM(ILogger<SettingsVM> logger, MainWindowVM mainWindowVM, IServiceProvider provider)
: base(logger)
2021-12-26 21:56:44 +00:00
{
MWVM = mainWindowVM;
Login = new LoginManagerVM(provider.GetRequiredService<ILogger<LoginManagerVM>>(), this,
provider.GetRequiredService<IEnumerable<INeedsLogin>>());
2021-12-26 21:56:44 +00:00
Performance = mainWindowVM.Settings.Performance;
2021-12-28 23:18:55 +00:00
AuthorFile = new AuthorFilesVM(provider.GetRequiredService<ILogger<AuthorFilesVM>>()!,
provider.GetRequiredService<WabbajackApiTokenProvider>()!, provider.GetRequiredService<Client>()!, this);
2021-12-26 21:56:44 +00:00
Filters = mainWindowVM.Settings.Filters;
2021-12-27 23:15:30 +00:00
OpenTerminalCommand = ReactiveCommand.CreateFromTask(OpenTerminal);
BackCommand = ReactiveCommand.Create(NavigateBack.Send);
2021-12-26 21:56:44 +00:00
}
private async Task OpenTerminal()
{
var process = new ProcessStartInfo
{
FileName = "cmd.exe",
2021-12-27 23:15:30 +00:00
WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!
2021-12-26 21:56:44 +00:00
};
Process.Start(process);
await MWVM.ShutdownApplication();
}
}
}