bug修复调整
This commit is contained in:
@@ -66,6 +66,8 @@ internal sealed class KernelStatus
|
||||
{
|
||||
public bool Ready { get; set; }
|
||||
public bool IsAdmin { get; set; }
|
||||
/// <summary>PawnIO 驱动是否已安装(ring0 传感器读取依赖它或 WinRing0,缺失时温度/频率通常无法读取)</summary>
|
||||
public bool PawnIoInstalled { get; set; }
|
||||
public double UptimeMs { get; set; }
|
||||
public int GroupCount { get; set; }
|
||||
public int SensorCount { get; set; }
|
||||
|
||||
@@ -277,7 +277,7 @@ internal sealed class HardwareManager : IDisposable
|
||||
_ => "",
|
||||
};
|
||||
|
||||
private static bool IsRunningAsAdmin()
|
||||
internal static bool IsRunningAsAdmin()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -44,6 +44,7 @@ internal static class HttpEndpoints
|
||||
{
|
||||
Ready = hw?.Ready ?? false,
|
||||
IsAdmin = hw?.IsAdmin ?? false,
|
||||
PawnIoInstalled = PawnIoSupport.IsServiceInstalled(),
|
||||
UptimeMs = kernel.Uptime.Elapsed.TotalMilliseconds,
|
||||
GroupCount = snap?.Groups.Count ?? 0,
|
||||
SensorCount = kernel.Scheduler.Cache.SensorCount,
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace ThingHK;
|
||||
|
||||
/// <summary>
|
||||
/// PawnIO 驱动支持:检测 + 静默安装。
|
||||
///
|
||||
/// 背景:LHM 读取 CPU 温度/频率等 ring0 数据依赖内核驱动,回退用的 WinRing0 被
|
||||
/// 微软"易受攻击的驱动程序阻止列表"和部分杀软(如火绒)拦截,导致传感器缺失。
|
||||
/// PawnIO 是正规签名的替代驱动(不在阻止列表、兼容 HVCI/安全启动),
|
||||
/// LHM 0.9.5+ 检测到已安装时优先使用,无需任何代码开关。
|
||||
///
|
||||
/// 安装器约定:PawnIO_setup.exe 与 ThingHK.exe 同目录
|
||||
/// (由 Tauri 侧 prepare_kernel 从资源目录随内核一起复制到 {app_data}/monitor/cores/)。
|
||||
///
|
||||
/// 静默参数:-install -silent(官方 CLI 参数,见 namazso/PawnIO.Setup)。
|
||||
/// 退出码:0=成功;3010=成功但需重启(ERROR_SUCCESS_REBOOT_REQUIRED)。
|
||||
///
|
||||
/// 策略:仅在内核已提权时安装。两种提权模式(Thing 提权继承 / 仅提权 ThingHK)
|
||||
/// 都只有一次 UAC,内核拿到权限后自行静默安装,避免二次弹窗。
|
||||
/// serve 模式调用;scan 诊断模式不安装,保持被动。
|
||||
/// </summary>
|
||||
internal static class PawnIoSupport
|
||||
{
|
||||
/// <summary>驱动服务注册表键:存在即认为已安装</summary>
|
||||
private const string ServiceKeyName = @"SYSTEM\CurrentControlSet\Services\PawnIO";
|
||||
|
||||
private const string SetupFileName = "PawnIO_setup.exe";
|
||||
|
||||
/// <summary>3010 = ERROR_SUCCESS_REBOOT_REQUIRED(安装成功但需重启生效)</summary>
|
||||
private const int ExitCodeRebootRequired = 3010;
|
||||
|
||||
/// <summary>驱动安装通常数秒内完成,留足余量防止卡死启动流程</summary>
|
||||
private const int InstallTimeoutMs = 90_000;
|
||||
|
||||
/// <summary>检测 PawnIO 驱动服务是否已注册</summary>
|
||||
public static bool IsServiceInstalled()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var key = Registry.LocalMachine.OpenSubKey(ServiceKeyName);
|
||||
return key != null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 确保 PawnIO 就绪:已安装直接返回;未安装且当前已提权时静默安装。
|
||||
/// 返回描述性结果(写入 stderr 日志 + /status 诊断)。
|
||||
/// </summary>
|
||||
public static string EnsureInstalled()
|
||||
{
|
||||
if (IsServiceInstalled())
|
||||
return "already-installed";
|
||||
|
||||
if (!HardwareManager.IsRunningAsAdmin())
|
||||
return "skipped: not elevated (温度/频率等传感器需要提权运行)";
|
||||
|
||||
string setupPath = Path.Combine(AppContext.BaseDirectory, SetupFileName);
|
||||
if (!File.Exists(setupPath))
|
||||
return $"skipped: {SetupFileName} 未找到(应随内核一起部署,见 prepare_kernel)";
|
||||
|
||||
try
|
||||
{
|
||||
using var process = Process.Start(new ProcessStartInfo
|
||||
{
|
||||
FileName = setupPath,
|
||||
Arguments = "-install -silent",
|
||||
UseShellExecute = false,
|
||||
CreateNoWindow = true,
|
||||
});
|
||||
if (process == null)
|
||||
return "failed: Process.Start 返回 null";
|
||||
|
||||
if (!process.WaitForExit(InstallTimeoutMs))
|
||||
{
|
||||
try { process.Kill(); } catch { /* 超时后进程可能已自行退出 */ }
|
||||
return "failed: 安装超时";
|
||||
}
|
||||
|
||||
int code = process.ExitCode;
|
||||
if (code == ExitCodeRebootRequired)
|
||||
return "installed: 需重启后生效";
|
||||
|
||||
if (code != 0)
|
||||
return $"failed: 安装器退出码 {code}";
|
||||
|
||||
return IsServiceInstalled()
|
||||
? "installed"
|
||||
: "failed: 安装器返回 0 但服务未注册";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return $"failed: {ex.Message}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,6 +87,11 @@ internal static class Program
|
||||
|
||||
Console.Error.WriteLine($"[ThingHK] serve 模式: port={port} config={configPath ?? "(默认)"} fast={fastMs}ms slow={slowMs}ms");
|
||||
|
||||
// PawnIO:ring0 传感器读取的首选驱动(未安装且已提权时静默安装,
|
||||
// 避开 WinRing0 被系统阻止列表/杀软拦截导致的温度/频率缺失)
|
||||
string pawnIoResult = PawnIoSupport.EnsureInstalled();
|
||||
Console.Error.WriteLine($"[ThingHK] PawnIO: {pawnIoResult}");
|
||||
|
||||
using var kernel = new KernelHost();
|
||||
await kernel.StartAsync(configPath, fastMs, slowMs);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.7-pre716" />
|
||||
<PackageReference Include="LibreHardwareMonitorLib" Version="0.9.7-pre729" />
|
||||
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user