From 3a0bb21323e03710bbbb67014ec119ae717c9421 Mon Sep 17 00:00:00 2001 From: ded_ikar <192651098+dedikar@users.noreply.github.com> Date: Wed, 29 Apr 2026 15:29:39 +0500 Subject: [PATCH] Add unsupported Windows version handling --- App.xaml.cs | 14 +++++ QoSManager.csproj | 2 +- Services/WindowsVersionService.cs | 85 ++++++++++++++++++++++++++ Views/UnsupportedVersionWindow.xaml | 78 +++++++++++++++++++++++ Views/UnsupportedVersionWindow.xaml.cs | 26 ++++++++ 5 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 Services/WindowsVersionService.cs create mode 100644 Views/UnsupportedVersionWindow.xaml create mode 100644 Views/UnsupportedVersionWindow.xaml.cs diff --git a/App.xaml.cs b/App.xaml.cs index a98807c..332cbf1 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -25,6 +25,20 @@ namespace QoSManager { base.OnStartup(e); + // Проверка версии Windows + var versionService = new WindowsVersionService(); + var windowsInfo = versionService.GetWindowsInfo(); + + if (!windowsInfo.IsQoSSupported) + { + var warningWindow = new UnsupportedVersionWindow(windowsInfo); + warningWindow.ShowDialog(); + + // Always exit on unsupported version + Shutdown(); + return; + } + // Проверка административных прав if (!IsAdministrator()) { diff --git a/QoSManager.csproj b/QoSManager.csproj index cce3e07..7cb9dc5 100644 --- a/QoSManager.csproj +++ b/QoSManager.csproj @@ -11,7 +11,7 @@ app.manifest Resources\icon.ico - + none false true diff --git a/Services/WindowsVersionService.cs b/Services/WindowsVersionService.cs new file mode 100644 index 0000000..981e272 --- /dev/null +++ b/Services/WindowsVersionService.cs @@ -0,0 +1,85 @@ +using Microsoft.Win32; +using System; + +namespace QoSManager.Services +{ + public class WindowsVersionService + { + public enum WindowsEdition + { + Home, + Pro, + Enterprise, + Education, + Unknown + } + + public class WindowsInfo + { + public WindowsEdition Edition { get; set; } + public string ProductName { get; set; } + public bool IsQoSSupported { get; set; } + public string VersionString { get; set; } + } + + public WindowsInfo GetWindowsInfo() + { + var info = new WindowsInfo(); + + try + { + // Получаем информацию о версии Windows из реестра + using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion")) + { + if (key != null) + { + var productName = key.GetValue("ProductName")?.ToString() ?? "Unknown"; + info.ProductName = productName; + info.Edition = ParseEdition(productName); + info.IsQoSSupported = IsQoSSupported(info.Edition); + info.VersionString = $"{productName} ({info.Edition})"; + } + } + } + catch (Exception ex) + { + info.ProductName = "Error reading version"; + info.Edition = WindowsEdition.Unknown; + info.IsQoSSupported = false; + info.VersionString = $"Error: {ex.Message}"; + } + + return info; + } + + private WindowsEdition ParseEdition(string productName) + { + if (string.IsNullOrEmpty(productName)) + return WindowsEdition.Unknown; + + productName = productName.ToLowerInvariant(); + + if (productName.Contains("home")) + return WindowsEdition.Home; + if (productName.Contains("pro")) + return WindowsEdition.Pro; + if (productName.Contains("enterprise")) + return WindowsEdition.Enterprise; + if (productName.Contains("education")) + return WindowsEdition.Education; + + return WindowsEdition.Unknown; + } + + private bool IsQoSSupported(WindowsEdition edition) + { + return edition switch + { + WindowsEdition.Pro => true, + WindowsEdition.Enterprise => true, + WindowsEdition.Education => true, + _ => false + }; + } + } +} diff --git a/Views/UnsupportedVersionWindow.xaml b/Views/UnsupportedVersionWindow.xaml new file mode 100644 index 0000000..2b7c722 --- /dev/null +++ b/Views/UnsupportedVersionWindow.xaml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +