chore: 更新 .gitignore 文件以排除交叉编译产物和刷机工具相关目录
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user