0
0
mirror of https://github.com/sp-tarkov/patcher.git synced 2025-02-13 02:10:47 -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> <TargetFramework>net6.0</TargetFramework>
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract> <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AssemblyVersion>2.9.3</AssemblyVersion> <AssemblyVersion>2.9.4</AssemblyVersion>
<FileVersion>2.9.3</FileVersion> <FileVersion>2.9.4</FileVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<AvaloniaResource Include="Assets\**" /> <AvaloniaResource Include="Assets\**" />

View File

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

View File

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

View File

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

Binary file not shown.

View File

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

View File

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