Add unsupported Windows version handling

This commit is contained in:
ded_ikar
2026-04-29 15:29:39 +05:00
parent 29311e06a3
commit 3a0bb21323
5 changed files with 204 additions and 1 deletions
+14
View File
@@ -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())
{
+1 -1
View File
@@ -11,7 +11,7 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>Resources\icon.ico</ApplicationIcon>
<!-- Default optimization properties -->
<!-- Basic optimization -->
<DebugType>none</DebugType>
<DebugSymbols>false</DebugSymbols>
<Optimize>true</Optimize>
+85
View File
@@ -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
};
}
}
}
+78
View File
@@ -0,0 +1,78 @@
<Window x:Class="QoSManager.Views.UnsupportedVersionWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Неподдерживаемая версия Windows" Height="520" Width="580"
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
Background="#2D2D30">
<Grid Margin="25">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!-- Заголовок с иконкой -->
<StackPanel Orientation="Horizontal" Grid.Row="0" Margin="0,0,0,25">
<TextBlock Text="⚠️" FontSize="36" Margin="0,0,15,0" VerticalAlignment="Center"/>
<TextBlock Text="Неподдерживаемая версия Windows"
FontSize="22"
FontWeight="Bold"
Foreground="#E74C3C"
VerticalAlignment="Center"/>
</StackPanel>
<!-- Основное сообщение -->
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
<StackPanel Margin="5">
<TextBlock TextWrapping="Wrap" FontSize="14" LineHeight="24" Margin="0,0,0,20">
<Run Text="Обнаружена версия Windows:" FontWeight="Bold"/>
<LineBreak/>
<Run x:Name="VersionText" Text="{Binding VersionString}" Foreground="#E67E22" FontWeight="Bold"/>
</TextBlock>
<TextBlock TextWrapping="Wrap" FontSize="14" LineHeight="24" Margin="0,0,0,20">
<Run Text="QoS Manager не работает на Windows Home версиях, так как они не поддерживают Group Policy и QoS политики."/>
</TextBlock>
<Border Background="#34495E" CornerRadius="6" Padding="18" Margin="0,0,0,20">
<StackPanel>
<TextBlock Text="Что не поддерживается в Windows Home:" FontWeight="Bold" FontSize="15" Margin="0,0,0,12"/>
<TextBlock Text="• Group Policy Editor (gpedit.msc)" FontSize="14" Margin="10,0,0,8"/>
<TextBlock Text="• PowerShell модуль NetQosPolicy" FontSize="14" Margin="10,0,0,8"/>
<TextBlock Text="• QoS политики на уровне ОС" FontSize="14" Margin="10,0,0,0"/>
</StackPanel>
</Border>
<TextBlock TextWrapping="Wrap" FontSize="14" LineHeight="24" Margin="0,0,0,20">
<Run Text="Для работы приложения требуется:" FontWeight="Bold"/>
</TextBlock>
<Border Background="#27AE60" CornerRadius="6" Padding="18">
<StackPanel>
<TextBlock Text="Поддерживаемые версии Windows:" FontWeight="Bold" FontSize="15" Margin="0,0,0,12" Foreground="White"/>
<TextBlock Text="• Windows 10/11 Pro" FontSize="14" Margin="10,0,0,8" Foreground="White"/>
<TextBlock Text="• Windows 10/11 Enterprise" FontSize="14" Margin="10,0,0,8" Foreground="White"/>
<TextBlock Text="• Windows 10/11 Education" FontSize="14" Margin="10,0,0,0" Foreground="White"/>
</StackPanel>
</Border>
</StackPanel>
</ScrollViewer>
<!-- Buttons -->
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Grid.Row="2" Margin="0,25,0,0">
<Button x:Name="ExitButton" Content="Выход"
Background="#C0392B"
Foreground="White"
FontSize="16"
FontWeight="Bold"
Padding="40,15"
MinWidth="120"
MinHeight="45"
BorderThickness="0"
Cursor="Hand"
Click="ExitButton_Click"/>
</StackPanel>
</Grid>
</Window>
+26
View File
@@ -0,0 +1,26 @@
using System;
using System.Windows;
using QoSManager.Services;
namespace QoSManager.Views
{
public partial class UnsupportedVersionWindow : Window
{
private readonly WindowsVersionService.WindowsInfo _windowsInfo;
public UnsupportedVersionWindow(WindowsVersionService.WindowsInfo windowsInfo)
{
InitializeComponent();
_windowsInfo = windowsInfo;
DataContext = this;
VersionText.Text = _windowsInfo.VersionString;
}
private void ExitButton_Click(object sender, RoutedEventArgs e)
{
// User decided to exit
DialogResult = false;
Close();
}
}
}