0
0
mirror of https://github.com/sp-tarkov/patcher.git synced 2025-02-12 14:50:45 -05:00

Merge pull request 'add elapsed time to patch views' (#12) from feature/show-elapsed-time into main

Reviewed-on: waffle.lord/Patcher#12
This commit is contained in:
IsWaffle 2023-07-21 01:53:08 +00:00
commit 7a96f95a01
7 changed files with 60 additions and 6 deletions

View File

@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable>
<AssemblyVersion>2.9.3</AssemblyVersion>
<FileVersion>2.9.3</FileVersion>
<AssemblyVersion>2.9.4</AssemblyVersion>
<FileVersion>2.9.4</FileVersion>
</PropertyGroup>
<ItemGroup>
<AvaloniaResource Include="Assets\**" />

View File

@ -4,11 +4,13 @@ using PatcherUtils;
using ReactiveUI;
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reactive.Disposables;
using System.Reflection;
using System.Threading.Tasks;
using System.Timers;
namespace PatchClient.ViewModels
{
@ -16,6 +18,9 @@ namespace PatchClient.ViewModels
{
private bool _initLineItemProgress = true;
private bool _autoClose = false;
private Stopwatch _patchStopwatch;
private Timer _udpatePatchElapsedTimer = new Timer(1000);
public ObservableCollection<LineItemProgress> LineItems { get; set; } = new ObservableCollection<LineItemProgress>();
private string _ProgressMessage = "";
@ -39,10 +44,19 @@ namespace PatchClient.ViewModels
set => this.RaiseAndSetIfChanged(ref _PatchMessage, value);
}
private string _ElapsedPatchTimeDetails;
public string ElapsedPatchTimeDetails
{
get => _ElapsedPatchTimeDetails;
set => this.RaiseAndSetIfChanged(ref _ElapsedPatchTimeDetails, value);
}
public PatcherViewModel(IScreen Host, bool autoClose) : base(Host)
{
_autoClose = autoClose;
ElapsedPatchTimeDetails = "Starting ...";
_udpatePatchElapsedTimer.Elapsed += _udpatePatchElapsedTimer_Elapsed;
this.WhenActivated((CompositeDisposable disposables) =>
{
@ -76,6 +90,14 @@ namespace PatchClient.ViewModels
});
}
private void _udpatePatchElapsedTimer_Elapsed(object? sender, ElapsedEventArgs e)
{
Dispatcher.UIThread.InvokeAsync(() =>
{
ElapsedPatchTimeDetails = $"Elapsed Patch Time: {_patchStopwatch.Elapsed.ToString("hh':'mm':'ss")}";
});
}
private void RunPatcher()
{
Task.Run(async() =>
@ -86,8 +108,14 @@ namespace PatchClient.ViewModels
patcher.ProgressChanged += patcher_ProgressChanged;
_udpatePatchElapsedTimer.Start();
_patchStopwatch = Stopwatch.StartNew();
var patchMessage = patcher.ApplyPatches();
_patchStopwatch.Stop();
_udpatePatchElapsedTimer.Stop();
LazyOperations.CleanupTempDir();
Directory.Delete(LazyOperations.PatchFolder, true);

View File

@ -20,6 +20,7 @@
<!-- Current Patch Text -->
<Label Content="{Binding ProgressMessage}"/>
<Label Content="{Binding ElapsedPatchTimeDetails}" HorizontalAlignment="Right"/>
<Label Content="{Binding PatchMessage}" Grid.Row="1"
Classes="dark"/>
<ProgressBar Grid.Row="2" Value="{Binding PatchPercent}"/>

View File

@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable>
<AssemblyVersion>2.9.3</AssemblyVersion>
<FileVersion>2.9.3</FileVersion>
<AssemblyVersion>2.9.4</AssemblyVersion>
<FileVersion>2.9.4</FileVersion>
</PropertyGroup>
<ItemGroup>

Binary file not shown.

View File

@ -15,6 +15,7 @@ using System.Reactive.Disposables;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace PatchGenerator.ViewModels
{
@ -48,17 +49,28 @@ namespace PatchGenerator.ViewModels
set => this.RaiseAndSetIfChanged(ref _IndeterminateProgress, value);
}
private string _ElapsedTimeDetails;
public string ElapsedTimeDetails
{
get => _ElapsedTimeDetails;
set => this.RaiseAndSetIfChanged(ref _ElapsedTimeDetails, value);
}
private LineItem[] lineItems;
public ObservableCollection<PatchItem> PatchItemCollection { get; set; } = new ObservableCollection<PatchItem>();
public ObservableCollection<PatchItem> PatchItemLegendCollection { get; set; } = new ObservableCollection<PatchItem>();
private Stopwatch patchGenStopwatch = new Stopwatch();
private Timer updateElapsedTimeTimer = new Timer(1000);
private readonly PatchGenInfo generationInfo;
public PatchGenerationViewModel(IScreen Host, PatchGenInfo GenerationInfo) : base(Host)
{
generationInfo = GenerationInfo;
ElapsedTimeDetails = "Starting ...";
updateElapsedTimeTimer.Elapsed += UpdateElapsedTimeTimer_Elapsed;
foreach (KeyValuePair<string, IBrush> pair in PatchItemDefinitions.Colors)
{
@ -75,6 +87,14 @@ namespace PatchGenerator.ViewModels
});
}
private void UpdateElapsedTimeTimer_Elapsed(object? sender, ElapsedEventArgs e)
{
Dispatcher.UIThread.InvokeAsync(() =>
{
ElapsedTimeDetails = $"Elapsed Patch Time: {patchGenStopwatch.Elapsed.ToString("hh':'mm':'ss")}";
});
}
public void GeneratePatches()
{
Task.Run(() =>
@ -87,6 +107,7 @@ namespace PatchGenerator.ViewModels
patcher.ProgressChanged += Patcher_ProgressChanged;
updateElapsedTimeTimer.Start();
patchGenStopwatch.Start();
var message = patcher.GeneratePatches();
@ -97,6 +118,7 @@ namespace PatchGenerator.ViewModels
}
patchGenStopwatch.Stop();
updateElapsedTimeTimer.Stop();
PrintSummary();

View File

@ -64,6 +64,9 @@
<Label Content="{Binding ProgressMessage}"/>
<Label Content="{Binding PatchPercent, StringFormat={}{0}%}" Grid.Column="2"/>
</Grid>
<Label Content="{Binding ElapsedTimeDetails}" Grid.Row="4" HorizontalAlignment="Left" Margin="10"
/>
<CheckBox Content="AutoScroll" Grid.Row="4" HorizontalAlignment="Right" Margin="10"
IsChecked="{Binding AutoScroll}"/>