Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions SysManager/SysManager/ViewModels/CleanupViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ void Collect(PowerShellLine l)
if (l.Kind == OutputKind.Output) captured.Add(l.Text);
if (l.Text.Contains('%') || l.Text.Contains("complete", StringComparison.OrdinalIgnoreCase))
{
var m = Regex.Match(l.Text, @"(\d+)\s*%");
var m = SfcPercentRegex().Match(l.Text);
if (m.Success && int.TryParse(m.Groups[1].Value, out var pct) && pct is >= 0 and <= 100)
{
Progress = pct;
Expand Down Expand Up @@ -356,7 +356,7 @@ void Collect(PowerShellLine l)
if (l.Kind == OutputKind.Output) captured.Add(l.Text);
if (l.Text.Contains('%'))
{
var m = Regex.Match(l.Text, @"([\d.]+)%");
var m = DismPercentRegex().Match(l.Text);
if (m.Success && double.TryParse(m.Groups[1].Value, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out var pct) && pct is >= 0 and <= 100)
{
Progress = (int)pct;
Expand Down Expand Up @@ -410,4 +410,12 @@ private void Cancel()
_sfcCts?.Cancel();
_dismCts?.Cancel();
}

// SFC reports progress as a whole-number percentage, e.g. "50 %".
[GeneratedRegex(@"(\d+)\s*%")]
private static partial Regex SfcPercentRegex();

// DISM reports progress as a decimal percentage, e.g. "50.0%".
[GeneratedRegex(@"([\d.]+)%")]
private static partial Regex DismPercentRegex();
}
7 changes: 6 additions & 1 deletion SysManager/SysManager/ViewModels/SpeedTestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// License: MIT

using System.Collections.ObjectModel;
using System.Text.RegularExpressions;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Serilog;
Expand Down Expand Up @@ -173,10 +174,14 @@ private async Task ClearOoklaHistoryAsync()
private static int? ParseServerId(string option)
{
if (option.StartsWith("Auto")) return null;
var match = System.Text.RegularExpressions.Regex.Match(option, @"ID:\s*(\d+)");
var match = ServerIdRegex().Match(option);
return match.Success ? int.Parse(match.Groups[1].Value) : null;
}

// Speedtest server options are formatted "Name (ID: 1234)".
[GeneratedRegex(@"ID:\s*(\d+)")]
private static partial Regex ServerIdRegex();

protected override void Dispose(bool disposing)
{
if (disposing)
Expand Down
Loading