chore: 更新 .gitignore 文件以排除交叉编译产物和刷机工具相关目录

This commit is contained in:
Nixevol
2026-11-27 07:28:40 +08:00
parent 6cd92aec2c
commit 64b01f886b
13 changed files with 1916 additions and 0 deletions
Binary file not shown.
+62
View File
@@ -0,0 +1,62 @@
param([switch]$Install)
$ErrorActionPreference = 'Stop'
$inf = Join-Path $PSScriptRoot 'qhsusb.inf'
$cer = Join-Path $PSScriptRoot 'qhsusb.cer'
function Test-QhsusbInstalled {
$files = @(Get-ChildItem 'C:\Windows\INF\oem*.inf' -ErrorAction SilentlyContinue)
foreach ($file in $files) {
try {
$text = Get-Content -LiteralPath $file.FullName -Raw -ErrorAction Stop
} catch {
continue
}
if ($text -match 'QHSUSB__BULK' -and $text -match 'VID_05C6&PID_9008') {
return $true
}
}
return $false
}
function Test-Admin {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}
if (-not $Install) {
if (Test-QhsusbInstalled) {
Write-Output "DRIVER`tREADY"
} else {
Write-Output "DRIVER`tMISSING"
}
exit 0
}
if (-not (Test-Admin)) {
$arg = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -Install"
try {
Start-Process -FilePath powershell.exe -ArgumentList $arg -Verb RunAs -Wait | Out-Null
} catch {
Write-Output "DRIVER`tFAIL`tcancel"
exit 1
}
if (Test-QhsusbInstalled) {
Write-Output "DRIVER`tINSTALLED"
exit 0
}
Write-Output "DRIVER`tFAIL"
exit 1
}
if (Test-Path -LiteralPath $cer) {
& certutil.exe -addstore -f TrustedPublisher $cer | Out-Null
}
$proc = Start-Process -FilePath "$env:SystemRoot\System32\pnputil.exe" -ArgumentList @('/add-driver', $inf, '/install') -Wait -PassThru -NoNewWindow
if (Test-QhsusbInstalled) {
Write-Output "DRIVER`tINSTALLED"
exit 0
}
Write-Output ("DRIVER`tFAIL`t" + $proc.ExitCode)
exit 1
Binary file not shown.
Binary file not shown.
+107
View File
@@ -0,0 +1,107 @@
param(
[Parameter(Mandatory = $true)][string]$InstanceId
)
$ErrorActionPreference = 'Stop'
$inf = (Resolve-Path (Join-Path $PSScriptRoot 'qhsusb.inf')).Path
if (-not (Test-Path -LiteralPath $inf)) {
throw '找不到 WinUSB 驱动描述'
}
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
using System.Text;
public static class QhsusbOne {
public const uint DIGCF_PRESENT = 0x2;
public const uint DIGCF_ALLCLASSES = 0x4;
public const uint DI_ENUMSINGLEINF = 0x00010000;
public const uint DIF_SELECTBESTCOMPATDRV = 0x17;
public const uint DIF_INSTALLDEVICE = 0x2;
public const uint SPDIT_COMPATDRIVER = 2;
[StructLayout(LayoutKind.Sequential)]
public struct SP_DEVINFO_DATA {
public int cbSize;
public Guid ClassGuid;
public uint DevInst;
public IntPtr Reserved;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct SP_DEVINSTALL_PARAMS {
public int cbSize;
public int Flags;
public int FlagsEx;
public IntPtr hwndParent;
public IntPtr InstallMsgHandler;
public IntPtr InstallMsgHandlerContext;
public IntPtr FileQueue;
public IntPtr ClassInstallReserved;
public int Reserved;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string DriverPath;
}
[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr SetupDiGetClassDevs(IntPtr classGuid, string enumerator, IntPtr hwnd, uint flags);
[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupDiOpenDeviceInfo(IntPtr deviceInfoSet, string deviceInstanceId, IntPtr hwnd, uint flags, ref SP_DEVINFO_DATA data);
[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupDiGetDeviceInstallParams(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA data, ref SP_DEVINSTALL_PARAMS parms);
[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupDiSetDeviceInstallParams(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA data, ref SP_DEVINSTALL_PARAMS parms);
[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupDiBuildDriverInfoList(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA data, uint type);
[DllImport("setupapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool SetupDiCallClassInstaller(uint installFunction, IntPtr deviceInfoSet, ref SP_DEVINFO_DATA data);
[DllImport("setupapi.dll", SetLastError = true)]
public static extern bool SetupDiDestroyDriverInfoList(IntPtr deviceInfoSet, ref SP_DEVINFO_DATA data, uint type);
[DllImport("setupapi.dll", SetLastError = true)]
public static extern bool SetupDiDestroyDeviceInfoList(IntPtr deviceInfoSet);
}
"@
function Throw-IfFailed([bool]$ok, [string]$step) {
if ($ok) { return }
$code = [Runtime.InteropServices.Marshal]::GetLastWin32Error()
throw ($step + ' 失败,Win32 错误 ' + $code)
}
$set = [QhsusbOne]::SetupDiGetClassDevs([IntPtr]::Zero, 'USB', [IntPtr]::Zero, [QhsusbOne]::DIGCF_PRESENT -bor [QhsusbOne]::DIGCF_ALLCLASSES)
Throw-IfFailed (-not ($set -eq [IntPtr]::Zero -or $set -eq [IntPtr]-1)) '打开设备列表'
$dev = New-Object QhsusbOne+SP_DEVINFO_DATA
$dev.cbSize = [Runtime.InteropServices.Marshal]::SizeOf($dev)
try {
$ok = [QhsusbOne]::SetupDiOpenDeviceInfo($set, $InstanceId, [IntPtr]::Zero, 0, [ref]$dev)
Throw-IfFailed $ok '定位这一台设备'
$parms = New-Object QhsusbOne+SP_DEVINSTALL_PARAMS
$parms.cbSize = [Runtime.InteropServices.Marshal]::SizeOf($parms)
$ok = [QhsusbOne]::SetupDiGetDeviceInstallParams($set, [ref]$dev, [ref]$parms)
Throw-IfFailed $ok '读取安装参数'
$parms.Flags = $parms.Flags -bor [QhsusbOne]::DI_ENUMSINGLEINF
$parms.DriverPath = $inf
$ok = [QhsusbOne]::SetupDiSetDeviceInstallParams($set, [ref]$dev, [ref]$parms)
Throw-IfFailed $ok '指定驱动文件'
$ok = [QhsusbOne]::SetupDiBuildDriverInfoList($set, [ref]$dev, [QhsusbOne]::SPDIT_COMPATDRIVER)
Throw-IfFailed $ok '建立驱动列表'
try {
$ok = [QhsusbOne]::SetupDiCallClassInstaller([QhsusbOne]::DIF_SELECTBESTCOMPATDRV, $set, [ref]$dev)
Throw-IfFailed $ok '选择驱动'
$ok = [QhsusbOne]::SetupDiCallClassInstaller([QhsusbOne]::DIF_INSTALLDEVICE, $set, [ref]$dev)
Throw-IfFailed $ok '安装驱动'
} finally {
[void][QhsusbOne]::SetupDiDestroyDriverInfoList($set, [ref]$dev, [QhsusbOne]::SPDIT_COMPATDRIVER)
}
} finally {
[void][QhsusbOne]::SetupDiDestroyDeviceInfoList($set)
}
Write-Output 'OK'