From 81d775ddcab0f14cead444b4005a8a87513b6228 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Wed, 10 Nov 2021 16:12:29 -0700 Subject: [PATCH] Revert "Reformatting" This reverts commit 6a85a3e7 --- Wabbajack.App/App.axaml | 1 + Wabbajack.App/Assets/Wabbajack.axaml | 6 +++++ Wabbajack.App/Controls/ResourceView.axaml | 15 +++++------- Wabbajack.App/Controls/ResourceView.axaml.cs | 15 ++++++++++-- Wabbajack.App/Controls/ResourceViewModel.cs | 24 ++++++++++---------- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/Wabbajack.App/App.axaml b/Wabbajack.App/App.axaml index 842e97aa..2f026076 100644 --- a/Wabbajack.App/App.axaml +++ b/Wabbajack.App/App.axaml @@ -9,6 +9,7 @@ + + + diff --git a/Wabbajack.App/Controls/ResourceView.axaml b/Wabbajack.App/Controls/ResourceView.axaml index 3097a736..9cbd59da 100644 --- a/Wabbajack.App/Controls/ResourceView.axaml +++ b/Wabbajack.App/Controls/ResourceView.axaml @@ -4,13 +4,10 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Wabbajack.App.Controls.ResourceView"> - - - - - - - - - + + + + + + \ No newline at end of file diff --git a/Wabbajack.App/Controls/ResourceView.axaml.cs b/Wabbajack.App/Controls/ResourceView.axaml.cs index bcf518de..ad795dbd 100644 --- a/Wabbajack.App/Controls/ResourceView.axaml.cs +++ b/Wabbajack.App/Controls/ResourceView.axaml.cs @@ -17,10 +17,21 @@ public partial class ResourceView : ReactiveUserControl, IAct this.Bind(ViewModel, vm => vm.MaxTasks, view => view.MaxTasks.Text) .DisposeWith(disposables); - this.Bind(ViewModel, vm => vm.MaxThroughput, view => view.MaxThroughput.Text) + + this.Bind(ViewModel, vm => vm.MaxThroughput, view => view.MaxThroughput.Text, + l => l is 0 or long.MaxValue ? "∞" : (l / 1024 / 1024).ToString(), + v => + { + v = v.Trim(); + if (v is "0" or "∞" || v == long.MaxValue.ToString()) + { + return long.MaxValue; + } + return long.TryParse(v, out var l) ? l * 1024 * 1024 : long.MaxValue; + }) .DisposeWith(disposables); - this.OneWayBind(ViewModel, vm => vm.CurrentThroughput, view => view.CurrentThrougput.Text, + this.OneWayBind(ViewModel, vm => vm.CurrentThroughput, view => view.CurrentThroughput.Text, val => val.FileSizeToString()) .DisposeWith(disposables); }); diff --git a/Wabbajack.App/Controls/ResourceViewModel.cs b/Wabbajack.App/Controls/ResourceViewModel.cs index d3b51c1d..067bbe97 100644 --- a/Wabbajack.App/Controls/ResourceViewModel.cs +++ b/Wabbajack.App/Controls/ResourceViewModel.cs @@ -2,9 +2,11 @@ using System; using System.Reactive.Disposables; using System.Reactive.Linq; using System.Timers; +using Avalonia.Threading; using ReactiveUI; using ReactiveUI.Fody.Helpers; using Wabbajack.App.ViewModels; +using Wabbajack.Common; using Wabbajack.RateLimiter; namespace Wabbajack.App.Controls; @@ -18,7 +20,7 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab { Activator = new ViewModelActivator(); _resource = resource; - _timer = new Timer(1.0); + _timer = new Timer(250); Name = resource.Name; @@ -32,14 +34,9 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab _timer.Stop(); _timer.Elapsed -= TimerElapsed; }).DisposeWith(disposables); - - this.WhenAnyValue(vm => vm.MaxThroughput) - .Skip(1) - .Subscribe(v => { _resource.MaxThroughput = MaxThroughput; }).DisposeWith(disposables); - - this.WhenAnyValue(vm => vm.MaxTasks) - .Skip(1) - .Subscribe(v => { _resource.MaxTasks = MaxTasks; }).DisposeWith(disposables); + + MaxTasks = _resource.MaxTasks; + MaxThroughput = _resource.MaxThroughput; }); } @@ -50,6 +47,8 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab [Reactive] public long CurrentThroughput { get; set; } [Reactive] public string Name { get; set; } + + [Reactive] public string ThroughputHumanFriendly { get; set; } public void Dispose() @@ -59,8 +58,9 @@ public class ResourceViewModel : ViewModelBase, IActivatableViewModel, IDisposab private void TimerElapsed(object? sender, ElapsedEventArgs e) { - MaxTasks = _resource.MaxTasks; - MaxThroughput = _resource.MaxThroughput; - CurrentThroughput = _resource.StatusReport.Transferred; + Dispatcher.UIThread.Post(() => { + CurrentThroughput = _resource.StatusReport.Transferred; + ThroughputHumanFriendly = _resource.StatusReport.Transferred.ToFileSizeString(); + }); } } \ No newline at end of file