Skip to content

Commit

Permalink
minor bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
laolarou726 committed Oct 23, 2023
1 parent 5843a3e commit 14a858f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ProjBobcat/ProjBobcat/Class/Model/JvmRulesModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public bool IsAllow()
!Name.Equals(Constants.OsSymbol, StringComparison.OrdinalIgnoreCase)) return false;
if (!string.IsNullOrEmpty(Arch) && Arch != SystemInfoHelper.GetSystemArch()) return false;
#if WINDOWS
if (!string.IsNullOrEmpty(Version) && Version != $"^{WindowsSystemVersion.CurrentVersion}\\.") return false;
if (!string.IsNullOrEmpty(Version) && Version != $"^{Platforms.Windows.SystemInfoHelper.GetWindowsMajorVersion()}\\.") return false;
#endif

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,22 @@ public static IEnumerable<string> GetLogicalDrives()
return Environment.GetLogicalDrives();
}

public static bool IsWindows7()
/// <summary>
/// 获取 Windows 系统版本,7,8.1,10,11
/// </summary>
/// <returns></returns>
public static string GetWindowsMajorVersion()
{
var os = Environment.OSVersion;
return Environment.OSVersion switch
{
{ Platform: PlatformID.Win32NT, Version: { Major: 6, Minor: 1 } } => "7",
{ Platform: PlatformID.Win32NT, Version: { Major: 6, Minor: 2 } } => "8",
{ Platform: PlatformID.Win32NT, Version: { Major: 6, Minor: 3 } } => "8.1",
{ Platform: PlatformID.Win32NT, Version: { Major: 10, Minor: 0 } } => "10",
{ Platform: PlatformID.Win32NT, Version.Build: >= 22000 } => "11",
var os => throw new NotImplementedException($"Unknown OS version: {os}")

return os is { Platform: PlatformID.Win32NT, Version: { Major: 6, Minor: 1 } };
};
}

/// <summary>
Expand All @@ -254,7 +265,7 @@ public static bool IsWindows7()
/// <returns>待检查的进程,如果不传则检测当前进程</returns>
public static unsafe bool IsRunningUnderTranslation(Process? proc = null)
{
if (IsWindows7()) return false;
if (GetWindowsMajorVersion() == "7") return false;

proc ??= Process.GetCurrentProcess();

Expand Down

0 comments on commit 14a858f

Please sign in to comment.