mirror of
https://github.com/quasar/Quasar.git
synced 2026-10-24 17:31:11 +08:00
- Improved Client Installation, Update and Uninstallation - Improved Registry Access - Split SystemCore class
164 lines
6.8 KiB
C#
164 lines
6.8 KiB
C#
using System;
|
|
using System.Management;
|
|
using System.Text.RegularExpressions;
|
|
using xClient.Core.Utilities;
|
|
|
|
namespace xClient.Core.Helper
|
|
{
|
|
public static class PlatformHelper
|
|
{
|
|
/// <summary>
|
|
/// Initializes the <see cref="PlatformHelper"/> class.
|
|
/// </summary>
|
|
static PlatformHelper()
|
|
{
|
|
Win32NT = Environment.OSVersion.Platform == PlatformID.Win32NT;
|
|
XpOrHigher = Win32NT && Environment.OSVersion.Version.Major >= 5;
|
|
VistaOrHigher = Win32NT && Environment.OSVersion.Version.Major >= 6;
|
|
SevenOrHigher = Win32NT && (Environment.OSVersion.Version >= new Version(6, 1));
|
|
EightOrHigher = Win32NT && (Environment.OSVersion.Version >= new Version(6, 2, 9200));
|
|
EightPointOneOrHigher = Win32NT && (Environment.OSVersion.Version >= new Version(6, 3));
|
|
TenOrHigher = Win32NT && (Environment.OSVersion.Version >= new Version(10, 0));
|
|
RunningOnMono = Type.GetType("Mono.Runtime") != null;
|
|
|
|
Name = "Unknown OS";
|
|
using (
|
|
ManagementObjectSearcher searcher =
|
|
new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem"))
|
|
{
|
|
foreach (ManagementObject os in searcher.Get())
|
|
{
|
|
Name = os["Caption"].ToString();
|
|
break;
|
|
}
|
|
}
|
|
|
|
Name = Regex.Replace(Name, "^.*(?=Windows)", "").TrimEnd().TrimStart(); // Remove everything before first match "Windows" and trim end & start
|
|
Architecture = (Is64BitOperatingSystem()) ? 64 : 32;
|
|
}
|
|
|
|
/// <summary>
|
|
/// The function determines whether the current operating system is a 64-bit operating system.
|
|
/// </summary>
|
|
/// <returns>
|
|
/// The function returns true if the operating system is 64-bit; otherwise, it returns false.
|
|
/// </returns>
|
|
static bool Is64BitOperatingSystem()
|
|
{
|
|
if (IntPtr.Size == 8) // 64-bit programs run only on Win64
|
|
{
|
|
return true;
|
|
}
|
|
else // 32-bit programs run on both 32-bit and 64-bit Windows
|
|
{
|
|
// Detect whether the current process is a 32-bit process
|
|
// running on a 64-bit system.
|
|
bool flag;
|
|
return ((DoesWin32MethodExist("kernel32.dll", "IsWow64Process") &&
|
|
NativeMethods.IsWow64Process(NativeMethods.GetCurrentProcess(), out flag)) && flag);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The function determines whether a method exists in the export table of a certain module.
|
|
/// </summary>
|
|
/// <param name="moduleName">The name of the module</param>
|
|
/// <param name="methodName">The name of the method</param>
|
|
/// <returns>
|
|
/// The function returns true if the method specified by methodName exists in the export table
|
|
/// of the module specified by moduleName.
|
|
/// </returns>
|
|
static bool DoesWin32MethodExist(string moduleName, string methodName)
|
|
{
|
|
IntPtr moduleHandle = NativeMethods.GetModuleHandle(moduleName);
|
|
if (moduleHandle == IntPtr.Zero)
|
|
{
|
|
return false;
|
|
}
|
|
return (NativeMethods.GetProcAddress(moduleHandle, methodName) != IntPtr.Zero);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the full name of the operating system running on this computer (including the edition and architecture).
|
|
/// </summary>
|
|
public static string FullName { get { return string.Format("{0} {1} Bit", Name, Architecture); } }
|
|
|
|
/// <summary>
|
|
/// Gets the name of the operating system running on this computer (including the edition).
|
|
/// </summary>
|
|
public static string Name { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Determines whether the Operating System is 32 or 64-bit.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>32</c> if the Operating System is 32-bit, otherwise <c>64</c> for 64-bit.
|
|
/// </value>
|
|
public static int Architecture { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Returns a indicating whether the application is running in Mono runtime.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if the application is running in Mono runtime; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public static bool RunningOnMono { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Returns a indicating whether the Operating System is Windows 32 NT based.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if the Operating System is Windows 32 NT based; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public static bool Win32NT { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Returns a value indicating whether the Operating System is Windows XP or higher.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if the Operating System is Windows XP or higher; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public static bool XpOrHigher { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Returns a value indicating whether the Operating System is Windows Vista or higher.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if the Operating System is Windows Vista or higher; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public static bool VistaOrHigher { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Returns a value indicating whether the Operating System is Windows 7 or higher.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if the Operating System is Windows 7 or higher; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public static bool SevenOrHigher { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Returns a value indicating whether the Operating System is Windows 8 or higher.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if the Operating System is Windows 8 or higher; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public static bool EightOrHigher { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Returns a value indicating whether the Operating System is Windows 8.1 or higher.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if the Operating System is Windows 8.1 or higher; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public static bool EightPointOneOrHigher { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Returns a value indicating whether the Operating System is Windows 10 or higher.
|
|
/// </summary>
|
|
/// <value>
|
|
/// <c>true</c> if the Operating System is Windows 10 or higher; otherwise, <c>false</c>.
|
|
/// </value>
|
|
public static bool TenOrHigher { get; private set; }
|
|
}
|
|
}
|