2022-03-13 22:47:30 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using ReactiveUI;
|
2023-10-12 18:33:06 +00:00
|
|
|
|
using Wabbajack.Common;
|
|
|
|
|
using Wabbajack.Downloaders;
|
2022-03-13 22:47:30 +00:00
|
|
|
|
using Wabbajack.LoginManagers;
|
|
|
|
|
using Wabbajack.Messages;
|
|
|
|
|
using Wabbajack.Networking.WabbajackClientApi;
|
2023-10-12 18:33:06 +00:00
|
|
|
|
using Wabbajack.RateLimiter;
|
|
|
|
|
using Wabbajack.Services.OSIntegrated;
|
2022-03-13 22:47:30 +00:00
|
|
|
|
using Wabbajack.Services.OSIntegrated.TokenProviders;
|
2023-10-12 18:33:06 +00:00
|
|
|
|
using Wabbajack.Util;
|
2022-03-13 22:47:30 +00:00
|
|
|
|
using Wabbajack.View_Models.Settings;
|
|
|
|
|
|
|
|
|
|
namespace Wabbajack
|
|
|
|
|
{
|
|
|
|
|
public class SettingsVM : BackNavigatingVM
|
|
|
|
|
{
|
2023-10-12 18:33:06 +00:00
|
|
|
|
private readonly Configuration.MainSettings _settings;
|
|
|
|
|
private readonly SettingsManager _settingsManager;
|
|
|
|
|
|
2022-03-13 22:47:30 +00:00
|
|
|
|
public LoginManagerVM Login { get; }
|
|
|
|
|
public PerformanceSettings Performance { get; }
|
|
|
|
|
public AuthorFilesVM AuthorFile { get; }
|
|
|
|
|
|
|
|
|
|
public ICommand OpenTerminalCommand { get; }
|
|
|
|
|
|
|
|
|
|
public SettingsVM(ILogger<SettingsVM> logger, IServiceProvider provider)
|
|
|
|
|
: base(logger)
|
|
|
|
|
{
|
2023-10-12 18:33:06 +00:00
|
|
|
|
_settings = provider.GetRequiredService<Configuration.MainSettings>();
|
|
|
|
|
_settingsManager = provider.GetRequiredService<SettingsManager>();
|
|
|
|
|
|
|
|
|
|
Login = new LoginManagerVM(provider.GetRequiredService<ILogger<LoginManagerVM>>(), this,
|
2022-03-13 22:47:30 +00:00
|
|
|
|
provider.GetRequiredService<IEnumerable<INeedsLogin>>());
|
2023-10-12 18:33:06 +00:00
|
|
|
|
AuthorFile = new AuthorFilesVM(provider.GetRequiredService<ILogger<AuthorFilesVM>>()!,
|
2022-03-13 22:47:30 +00:00
|
|
|
|
provider.GetRequiredService<WabbajackApiTokenProvider>()!, provider.GetRequiredService<Client>()!, this);
|
|
|
|
|
OpenTerminalCommand = ReactiveCommand.CreateFromTask(OpenTerminal);
|
2023-10-12 18:33:06 +00:00
|
|
|
|
Performance = new PerformanceSettings(
|
|
|
|
|
_settings,
|
|
|
|
|
provider.GetRequiredService<IResource<DownloadDispatcher>>(),
|
|
|
|
|
provider.GetRequiredService<SystemParametersConstructor>());
|
|
|
|
|
BackCommand = ReactiveCommand.Create(() =>
|
|
|
|
|
{
|
|
|
|
|
NavigateBack.Send();
|
|
|
|
|
Unload();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Unload()
|
|
|
|
|
{
|
|
|
|
|
_settingsManager.Save(Configuration.MainSettings.SettingsFileName, _settings).FireAndForget();
|
|
|
|
|
|
|
|
|
|
base.Unload();
|
2022-03-13 22:47:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task OpenTerminal()
|
|
|
|
|
{
|
|
|
|
|
var process = new ProcessStartInfo
|
|
|
|
|
{
|
|
|
|
|
FileName = "cmd.exe",
|
|
|
|
|
WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly()!.Location)!
|
|
|
|
|
};
|
|
|
|
|
Process.Start(process);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|