Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on unsupported OS versions #95

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
65 changes: 65 additions & 0 deletions Core/LocalAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using LocalAdmin.V2.IO.ExitHandlers;
using System;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -521,6 +522,7 @@ internal async Task Start(string[] args)

if (_firstRun)
{
VerifySystemVersion();
try
{
SetupExitHandlers();
Expand Down Expand Up @@ -619,6 +621,69 @@ private static void Menu()
ConsoleUtil.WriteLine(string.Empty, ConsoleColor.Cyan);
}

[StructLayout(LayoutKind.Sequential)]
private unsafe struct OSVERSIONINFO
{
public uint dwOSVersionInfoSize;
public uint dwMajorVersion;
public uint dwMinorVersion;
public uint dwBuildNumber;
private uint dwPlatformId;
public fixed ushort szCSDVersion[128];
public ushort wServicePackMajor;
public ushort wServicePackMinor;
private ushort wSuiteMask;
public byte wProductType;
private byte wReserved;
}

private static unsafe void VerifySystemVersion()
{
try
{
if (OperatingSystem.IsWindows())
{
OSVERSIONINFO info = new()
{
dwOSVersionInfoSize = (uint) sizeof(OSVERSIONINFO)
};

uint status = GetWindowsVersion(&info);
if (status != 0)
throw new Win32Exception(NtStatusToErrorCode(status));
Version windows = new((int) info.dwMajorVersion, (int) info.dwMinorVersion, (int) info.dwBuildNumber);

Version minimumWindows = new(10, 0, 19043); // Windows 21H1+
if (windows < minimumWindows)
{
ConsoleUtil.WriteLine($"Unsupported Windows version! SCPSL servers require Windows 21H1+ (build 19043+) and your server has {windows}!", ConsoleColor.Red);
}
return;

[DllImport("ntdll", EntryPoint = "RtlGetVersion")]
static extern uint GetWindowsVersion(OSVERSIONINFO* lpVersionInformation);

[DllImport("ntdll", EntryPoint = "RtlNtStatusToDosError")]
static extern int NtStatusToErrorCode(uint status);
}

Version glibc = Version.Parse(Marshal.PtrToStringUTF8((nint) GetGlibcVersion()));

Version minimumGlibc = new(2, 35); // Ubuntu 22.04
if (glibc < minimumGlibc)
{
ConsoleUtil.WriteLine($"Unsupported Linux version! SCPSL servers require Ubuntu 22.04+ (glibc 2.35) while your distro is based on glibc {glibc}!)", ConsoleColor.Red);
}

[DllImport("libc", EntryPoint = "gnu_get_libc_version")]
static extern sbyte* GetGlibcVersion();
}
catch (Exception ex)
{
ConsoleUtil.WriteLine($"Failed to check the OS version: {ex.Message}", ConsoleColor.Red);
}
}

private static void SetupExitHandlers()
{
ProcessHandler.Handler.Setup();
Expand Down
1 change: 1 addition & 0 deletions LocalAdmin V2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<TargetFramework Condition="!$(RuntimeIdentifier.StartsWith('win', StringComparison.OrdinalIgnoreCase))">net8.0</TargetFramework>
<ApplicationManifest>app.manifest</ApplicationManifest>
<LangVersion>10</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<RootNamespace>LocalAdmin.V2</RootNamespace>
<AssemblyName>LocalAdmin</AssemblyName>
Expand Down
6 changes: 0 additions & 6 deletions app.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>

<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />

<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />

<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

Expand Down
Loading