Merge pull request #1019 from Noggog/misc-fixes

Misc fixes
This commit is contained in:
Timothy Baldridge 2020-08-08 08:57:35 -06:00 committed by GitHub
commit 38b0e739cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 72 additions and 68 deletions

View File

@ -40,16 +40,23 @@ namespace Wabbajack.Common
MakeUpdate(Percent.Zero);
}
private Percent OverAllStatus(Percent sub_status)
/// <summary>
/// Converts a percent that's within the scope of a single step
/// to the overall percent when all steps are considered
/// </summary>
/// <param name="singleStepPercent">Percent progress of the current single step</param>
/// <returns>Overall progress in relation to all steps</returns>
private Percent OverAllStatus(Percent singleStepPercent)
{
var per_step = 1.0f / _internalMaxStep;
var macro = _internalCurrentStep * per_step;
return Percent.FactoryPutInRange(macro + (per_step * sub_status.Value));
return Percent.FactoryPutInRange(macro + (per_step * singleStepPercent.Value));
}
public void MakeUpdate(Percent progress)
{
_progress.OnNext(progress);
// Need to convert from single step progress to overall progress for output subject
_progress.OnNext(OverAllStatus(progress));
}
public void MakeUpdate(int max, int curr)

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Reactive;
@ -38,11 +38,6 @@ namespace Wabbajack.Lib.Downloaders
public NexusDownloader()
{
if (CLIArguments.ApiKey != null)
{
CLIArguments.ApiKey.ToEcryptedJson("nexusapikey");
}
TriggerLogin = ReactiveCommand.CreateFromTask(
execute: () => Utils.CatchAndLog(NexusApiClient.RequestAndCacheAPIKey),
canExecute: IsLoggedIn.Select(b => !b).ObserveOnGuiThread());
@ -115,6 +110,11 @@ namespace Wabbajack.Lib.Downloaders
// Could have become prepared while we waited for the lock
if (!_prepared)
{
if (CLIArguments.ApiKey != null)
{
await CLIArguments.ApiKey.ToEcryptedJson("nexusapikey");
}
_client = await NexusApiClient.Get();
_status = await _client.GetUserStatus();
if (!_client.IsAuthenticated)

View File

@ -3472,6 +3472,7 @@
<Style BasedOn="{StaticResource MahApps.Styles.TabControl}" TargetType="TabControl" />
<Style BasedOn="{StaticResource MahApps.Styles.TabItem}" TargetType="{x:Type TabItem}" />
<Style BasedOn="{StaticResource MahApps.Styles.Slider}" TargetType="Slider" />
<Style BasedOn="{StaticResource MahApps.Styles.ToolTip}" TargetType="ToolTip">
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Control.Background}" />

View File

@ -212,12 +212,12 @@ namespace Wabbajack
.QueryWhenChanged(query => query.FirstOrDefault())
.ToGuiProperty(this, nameof(ActiveGlobalUserIntervention));
CloseWhenCompleteCommand = ReactiveCommand.Create(
CloseWhenCompleteCommand = ReactiveCommand.CreateFromTask(
canExecute: this.WhenAny(x => x.Completed)
.Select(x => x != null),
execute: () =>
execute: async () =>
{
MWVM.ShutdownApplication();
await MWVM.ShutdownApplication();
});
GoToCommand = ReactiveCommand.Create(

View File

@ -412,12 +412,12 @@ namespace Wabbajack
.QueryWhenChanged(query => query.FirstOrDefault())
.ToGuiProperty(this, nameof(ActiveGlobalUserIntervention));
CloseWhenCompleteCommand = ReactiveCommand.Create(
CloseWhenCompleteCommand = ReactiveCommand.CreateFromTask(
canExecute: this.WhenAny(x => x.Completed)
.Select(x => x != null),
execute: () =>
execute: async () =>
{
MWVM.ShutdownApplication();
await MWVM.ShutdownApplication();
});
GoToInstallCommand = ReactiveCommand.Create(

View File

@ -46,7 +46,6 @@ namespace Wabbajack
public ICommand CopyVersionCommand { get; }
public ICommand ShowLoginManagerVM { get; }
public ICommand OpenSettingsCommand { get; }
public ICommand OpenTerminalCommand { get; }
public string VersionDisplay { get; }
@ -77,14 +76,11 @@ namespace Wabbajack
.Subscribe()
.DisposeWith(CompositeDisposable);
var singleton_lock = new AsyncLock();
Utils.LogMessages
.OfType<IUserIntervention>()
.ObserveOnGuiThread()
.SelectTask(async msg =>
{
using var _ = await singleton_lock.WaitAsync();
try
{
await UserInterventionHandlers.Handle(msg);
@ -127,7 +123,7 @@ namespace Wabbajack
VersionDisplay = $"v{fvi.FileVersion}";
Utils.Log($"Wabbajack Version: {fvi.FileVersion}");
Task.Run(() => Metrics.Send("started_wabbajack", fvi.FileVersion));
Task.Run(() => Metrics.Send("started_wabbajack", fvi.FileVersion)).FireAndForget();
}
catch (Exception ex)
{
@ -142,21 +138,6 @@ namespace Wabbajack
canExecute: this.WhenAny(x => x.ActivePane)
.Select(active => !SettingsPane.IsValueCreated || !object.ReferenceEquals(active, SettingsPane.Value)),
execute: () => NavigateTo(SettingsPane.Value));
OpenTerminalCommand = ReactiveCommand.Create(() => OpenTerminal());
}
private void OpenTerminal()
{
var process = new ProcessStartInfo
{
FileName = "cmd.exe",
WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
};
Process.Start(process);
ShutdownApplication();
}
private static bool IsStartingFromModlist(out AbsolutePath modlistPath)
@ -171,7 +152,6 @@ namespace Wabbajack
return true;
}
public void OpenInstaller(AbsolutePath path)
{
if (path == default) return;
@ -193,14 +173,14 @@ namespace Wabbajack
ActivePane = vm;
}
public void ShutdownApplication()
public async Task ShutdownApplication()
{
Dispose();
Settings.PosX = MainWindow.Left;
Settings.PosY = MainWindow.Top;
Settings.Width = MainWindow.Width;
Settings.Height = MainWindow.Height;
MainSettings.SaveSettings(Settings).AsTask().Wait();
await MainSettings.SaveSettings(Settings);
Application.Current.Shutdown();
}
}

View File

@ -1,8 +1,12 @@
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;
using ReactiveUI;
using Wabbajack.Lib;
@ -15,7 +19,9 @@ namespace Wabbajack
public PerformanceSettings Performance { get; }
public FiltersSettings Filters { get; }
public AuthorFilesVM AuthorFile { get; }
public ICommand OpenTerminalCommand { get; }
public SettingsVM(MainWindowVM mainWindowVM)
: base(mainWindowVM)
{
@ -24,7 +30,18 @@ namespace Wabbajack
Performance = mainWindowVM.Settings.Performance;
AuthorFile = new AuthorFilesVM(this);
Filters = mainWindowVM.Settings.Filters;
OpenTerminalCommand = ReactiveCommand.CreateFromTask(() => OpenTerminal());
}
private async Task OpenTerminal()
{
var process = new ProcessStartInfo
{
FileName = "cmd.exe",
WorkingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)
};
Process.Start(process);
await MWVM.ShutdownApplication();
}
}
}

View File

@ -69,14 +69,6 @@
Height="17"
Kind="Cog" />
</Button>
<Button Grid.Column="1"
Margin="5,0"
Command="{Binding OpenTerminalCommand}">
<icon:PackIconMaterial
Width="17"
Height="17"
Kind="Console" />
</Button>
</mahapps:WindowCommands>
</mahapps:MetroWindow.RightWindowCommands>
</mahapps:MetroWindow>

View File

@ -162,7 +162,7 @@ namespace Wabbajack
private void Window_Closing(object sender, CancelEventArgs e)
{
_mwvm.ShutdownApplication();
_mwvm.ShutdownApplication().Wait();
}
}
}

View File

@ -1,5 +1,5 @@
<rxui:ReactiveUserControl
x:Class="Wabbajack.ModlistGallerySettingsView"
x:Class="Wabbajack.MiscSettingsView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@ -9,7 +9,7 @@
xmlns:xwpf="http://schemas.xceed.com/wpf/xaml/toolkit"
d:DesignHeight="450"
d:DesignWidth="800"
x:TypeArguments="local:FiltersSettings"
x:TypeArguments="local:SettingsVM"
mc:Ignorable="d">
<Border
x:Name="PerformanceView"
@ -42,6 +42,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.Resources>
<Style BasedOn="{StaticResource MainButtonStyle}" TargetType="Button">
@ -55,21 +56,21 @@
</Style>
</Grid.Resources>
<CheckBox Grid.Row="0"
Name="FilterPersistCheckBox"
Margin="0,5,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Gallery filters are saved on exit">
Name="FilterPersistCheckBox"
Margin="0,5,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Gallery filters are saved on exit">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="1.2" ScaleY="1.2" />
</CheckBox.LayoutTransform>
</CheckBox>
<CheckBox Grid.Row="1"
Name="UseCompressionCheckBox"
Margin="0,5,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Use NTFS LZS compression during install">
Name="UseCompressionCheckBox"
Margin="0,5,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Content="Use NTFS LZS compression during install">
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="1.2" ScaleY="1.2" />
</CheckBox.LayoutTransform>
@ -78,6 +79,10 @@
Name="ClearCefCache"
Margin="0,5,0,0"
Content="Clear In-App Browser Cache" />
<Button Grid.Row="3"
Name="OpenTerminal"
Margin="0,5,0,0"
Content="Open Terminal and Close WJ" />
</Grid>
</Grid>
</Border>

View File

@ -21,20 +21,23 @@ using Wabbajack.Lib.WebAutomation;
namespace Wabbajack
{
/// <summary>
/// Interaction logic for ModlistGallerySettingsView.xaml
/// Interaction logic for MiscSettingsView.xaml
/// </summary>
public partial class ModlistGallerySettingsView : ReactiveUserControl<FiltersSettings>
public partial class MiscSettingsView : ReactiveUserControl<SettingsVM>
{
public ModlistGallerySettingsView()
public MiscSettingsView()
{
InitializeComponent();
this.WhenActivated(disposable =>
{
// Bind Values
this.Bind(this.ViewModel, x => x.IsPersistent, x => x.FilterPersistCheckBox.IsChecked)
this.BindStrict(this.ViewModel, x => x.Filters.IsPersistent, x => x.FilterPersistCheckBox.IsChecked)
.DisposeWith(disposable);
this.Bind(this.ViewModel, x => x.UseCompression, x => x.UseCompressionCheckBox.IsChecked)
this.BindStrict(this.ViewModel, x => x.Filters.UseCompression, x => x.UseCompressionCheckBox.IsChecked)
.DisposeWith(disposable);
this.WhenAnyValue(x => x.ViewModel.OpenTerminalCommand)
.BindToStrict(this, x => x.OpenTerminal.Command)
.DisposeWith(disposable);
this.ClearCefCache.Click += (sender, args) => {Driver.ClearCache();};

View File

@ -43,7 +43,7 @@
<WrapPanel>
<local:LoginSettingsView x:Name="LoginView" />
<local:PerformanceSettingsView x:Name="PerformanceView" />
<local:ModlistGallerySettingsView x:Name="ModlistGalleryView" />
<local:MiscSettingsView x:Name="MiscGalleryView" />
<local:AuthorFilesView x:Name="AuthorFilesView" />
</WrapPanel>
</ScrollViewer>

View File

@ -34,8 +34,7 @@ namespace Wabbajack
.DisposeWith(disposable);
this.OneWayBindStrict(this.ViewModel, x => x.Performance, x => x.PerformanceView.ViewModel)
.DisposeWith(disposable);
this.OneWayBindStrict(this.ViewModel, x => x.Filters, x => x.ModlistGalleryView.ViewModel)
.DisposeWith(disposable);
this.MiscGalleryView.ViewModel = this.ViewModel;
});
}
}