Small improvement in OS detection code.

This commit is contained in:
LoRd_MuldeR 2021-12-25 00:04:23 +01:00
parent ac4df08e6b
commit 8ec1f69393
2 changed files with 17 additions and 14 deletions

View File

@ -277,20 +277,21 @@ static QReadWriteLock g_os_version_lock;
static const struct
{
MUtils::OS::Version::os_version_t version;
bool checkBuildNo;
const char friendlyName[64];
}
g_os_version_lut[] =
{
{ MUtils::OS::Version::WINDOWS_WIN2K, "Windows 2000" }, //2000
{ MUtils::OS::Version::WINDOWS_WINXP, "Windows XP or Windows XP Media Center Edition" }, //XP
{ MUtils::OS::Version::WINDOWS_XPX64, "Windows Server 2003 or Windows XP x64" }, //XP_x64
{ MUtils::OS::Version::WINDOWS_VISTA, "Windows Vista or Windows Server 2008" }, //Vista
{ MUtils::OS::Version::WINDOWS_WIN70, "Windows 7 or Windows Server 2008 R2" }, //7
{ MUtils::OS::Version::WINDOWS_WIN80, "Windows 8 or Windows Server 2012" }, //8
{ MUtils::OS::Version::WINDOWS_WIN81, "Windows 8.1 or Windows Server 2012 R2" }, //8.1
{ MUtils::OS::Version::WINDOWS_WIN10, "Windows 10 or Windows Server 2016/2019" }, //10
{ MUtils::OS::Version::WINDOWS_WIN11, "Windows 11 or Windows Server 2022" }, //11
{ MUtils::OS::Version::UNKNOWN_OPSYS, "N/A" }
{ MUtils::OS::Version::WINDOWS_WIN2K, 0, "Windows 2000" }, //2000
{ MUtils::OS::Version::WINDOWS_WINXP, 0, "Windows XP or Windows XP Media Center Edition" }, //XP
{ MUtils::OS::Version::WINDOWS_XPX64, 0, "Windows Server 2003 or Windows XP x64" }, //XP_x64
{ MUtils::OS::Version::WINDOWS_VISTA, 0, "Windows Vista or Windows Server 2008" }, //Vista
{ MUtils::OS::Version::WINDOWS_WIN70, 0, "Windows 7 or Windows Server 2008 R2" }, //7
{ MUtils::OS::Version::WINDOWS_WIN80, 0, "Windows 8 or Windows Server 2012" }, //8
{ MUtils::OS::Version::WINDOWS_WIN81, 0, "Windows 8.1 or Windows Server 2012 R2" }, //8.1
{ MUtils::OS::Version::WINDOWS_WIN10, 0, "Windows 10 or Windows Server 2016" }, //10
{ MUtils::OS::Version::WINDOWS_WIN11, 1, "Windows 11 or Windows Server 2022" }, //11
{ MUtils::OS::Version::UNKNOWN_OPSYS, 0, "N/A" }
};
//OS version data dtructures
@ -315,7 +316,7 @@ namespace MUtils
const os_version_t WINDOWS_WIN80 = { OS_WINDOWS, 6, 2, 9200, 0 }; // 8
const os_version_t WINDOWS_WIN81 = { OS_WINDOWS, 6, 3, 9600, 0 }; // 8.1
const os_version_t WINDOWS_WIN10 = { OS_WINDOWS, 10, 0, 10240, 0 }; // 10
const os_version_t WINDOWS_WIN11 = { OS_WINDOWS, 10, 0, 20348, 0 }; // 11
const os_version_t WINDOWS_WIN11 = { OS_WINDOWS, 10, 0, 22000, 0 }; // 11
//Unknown OS
const os_version_t UNKNOWN_OPSYS = { OS_UNKNOWN, 0, 0, 0, 0 }; // N/A
@ -453,7 +454,7 @@ const char *MUtils::OS::os_friendly_name(const MUtils::OS::Version::os_version_t
for (size_t i = 0; g_os_version_lut[i].version.type != MUtils::OS::Version::OS_UNKNOWN; i++)
{
const MUtils::OS::Version::os_version_t &version = g_os_version_lut[i].version;
if ((os_version.versionMajor == version.versionMajor) && (os_version.versionMinor == version.versionMinor) && (os_version.versionBuild >= version.versionBuild))
if ((os_version.versionMajor == version.versionMajor) && (os_version.versionMinor == version.versionMinor) && ((!g_os_version_lut[i].checkBuildNo) || (os_version.versionBuild >= version.versionBuild)))
{
friendly_name = g_os_version_lut[i].friendlyName;
}

View File

@ -32,14 +32,14 @@
<ProjectGuid>{B7BCA0A5-17AD-4F20-A42C-CD6FFBD55D89}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>MUtilitiesTest_VS2017</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.14393.0</WindowsTargetPlatformVersion>
<ProjectName>MUtilitiesTest</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141_xp</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@ -133,6 +133,7 @@
<AdditionalLibraryDirectories>$(SolutionDir)\..\Prerequisites\Qt4\$(PlatformToolset)\Shared\lib;$(SolutionDir)\..\Prerequisites\GoogleTest\lib\$(PlatformToolset)\Shared;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>notelemetry.obj;gtest.lib;QtCore4.lib;QtGui4.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>LinkVerboseLib</ShowProgress>
<MinimumRequiredVersion>5.1</MinimumRequiredVersion>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_Static|Win32'">
@ -160,6 +161,7 @@
<AdditionalLibraryDirectories>$(SolutionDir)\..\Prerequisites\Qt4\$(PlatformToolset)\Static\lib;$(SolutionDir)\..\Prerequisites\GoogleTest\lib\$(PlatformToolset)\Static;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>notelemetry.obj;gtest.lib;QtCore.lib;QtGui.lib;Ws2_32.lib;Winmm.lib;Imm32.lib;PowrProf.lib;Version.lib;Psapi.lib;Sensapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>LinkVerboseLib</ShowProgress>
<MinimumRequiredVersion>5.1</MinimumRequiredVersion>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />