From ae888107733ba56db4d413fc65bb9ecfec5dfd53 Mon Sep 17 00:00:00 2001 From: Nemesh Date: Sun, 24 Sep 2023 00:56:52 +0300 Subject: [PATCH] fix cpu names --- FloatTool/Common/Utils.cs | 34 +++++++--------------- FloatTool/ViewModels/BenchmarkViewModel.cs | 2 +- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/FloatTool/Common/Utils.cs b/FloatTool/Common/Utils.cs index c01bb8c..8582249 100644 --- a/FloatTool/Common/Utils.cs +++ b/FloatTool/Common/Utils.cs @@ -98,7 +98,7 @@ public static string FirstCharToUpper(this string input) => }; } - public static class Utils + public static partial class Utils { public static string API_URL = ""; public static string HOME_URL = ""; @@ -179,31 +179,17 @@ public static async Task CheckForUpdates() } } + [GeneratedRegex(@"(?:\d{1,}th Gen)?(?:Genuine)? ?(?'vendor'AMD|Intel|Qualcomm|Samsung|MediaTek)(?:\(R\)|\(r\))? (?'family'[a-zA-Z]*)(?:\(TM\)|\(tm\))?(?'model'.*?)( [a-zA-Z]{1,}-Core| with| CPU @| @|$)")] + private static partial Regex CpuNameRegex(); + public static string ShortCpuName(string cpu) { - cpu = cpu.Replace("(R)", ""); - cpu = cpu.Replace("(TM)", ""); - cpu = cpu.Replace("(tm)", ""); - cpu = cpu.Replace(" with Radeon Graphics", ""); - cpu = cpu.Replace(" with Radeon Vega Mobile Gfx", ""); - cpu = cpu.Replace(" CPU", ""); - cpu = cpu.Replace(" Processor", ""); - - Regex regex = new(@"( \S{1,}-Core)"); - MatchCollection matches = regex.Matches(cpu); - if (matches.Count > 0) - foreach (Match match in matches.Cast()) - cpu = cpu.Replace(match.Value, ""); - - var index = cpu.IndexOf('@'); - if (index != -1) - cpu = cpu[..index]; - - index = cpu.IndexOf('('); - if (index != -1) - cpu = cpu[..index]; - - return cpu.Trim(); + Regex regex = CpuNameRegex(); + Match match = regex.Match(cpu); + string vendor = match.Groups["vendor"].Value; + string family = match.Groups["family"].Value; + string model = match.Groups["model"].Value; + return $"{vendor} {family}{model}"; } public static string EscapeLocalization(string input) diff --git a/FloatTool/ViewModels/BenchmarkViewModel.cs b/FloatTool/ViewModels/BenchmarkViewModel.cs index a3b771b..59c1bbb 100644 --- a/FloatTool/ViewModels/BenchmarkViewModel.cs +++ b/FloatTool/ViewModels/BenchmarkViewModel.cs @@ -177,7 +177,7 @@ public async void PollBenchmarkResults() MultithreadedSpeed = Math.Max((int)benchmark.multithread, MultithreadedSpeed); SinglethreadedSpeed = Math.Max((int)benchmark.singlethread, SinglethreadedSpeed); } - else if (cpuName.StartsWith("Intel")) + else if (cpuName.Contains("Intel")) currentFill = IntelBrush; BenchmarkResults.Add(new BenchmarkResult