Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,22 @@ jobs:
Write-Host "Trusted driver publisher certificate $($cert.Subject) [$($cert.Thumbprint)]."
}

- name: Prepare Sunshine close-applications regression test
if: runner.os == 'Windows'
id: sunshine_fixture
shell: powershell
run: |
$installer = Get-ChildItem -LiteralPath .\windows-driver-installer -Filter *.msi |
Select-Object -First 1
$fixtureDirectory = Join-Path $env:RUNNER_TEMP "libvirtualhid-sunshine-$([Guid]::NewGuid())"
$fixtureId = .\tests\scripts\test-installer-restart-manager.ps1 `
-MsiPath $installer.FullName -FixtureDirectory $fixtureDirectory
@("pid=$fixtureId", "exe=$fixtureDirectory\sunshine.exe") |
Out-File -FilePath $env:GITHUB_OUTPUT -Encoding utf8 -Append

- name: Install Windows driver installer
if: runner.os == 'Windows'
id: install_windows_driver
shell: pwsh
timeout-minutes: 10
run: |
Expand Down Expand Up @@ -382,6 +396,30 @@ jobs:
throw "Windows driver installer exited with code $($process.ExitCode)."
}

- name: Verify Windows installer closed Sunshine
if: always() && runner.os == 'Windows' && steps.sunshine_fixture.outputs.pid != ''
shell: powershell
env:
FIXTURE_PID: ${{ steps.sunshine_fixture.outputs.pid }}
FIXTURE_EXE: ${{ steps.sunshine_fixture.outputs.exe }}
INSTALL_OUTCOME: ${{ steps.install_windows_driver.outcome }}
run: |
$fixture = Get-Process -Id ([int] $env:FIXTURE_PID) -ErrorAction SilentlyContinue
$isFixture = $fixture -and $fixture.Path -eq $env:FIXTURE_EXE
try {
if ($env:INSTALL_OUTCOME -eq "success" -and $isFixture -and !$fixture.WaitForExit(15000)) {
Get-Content -LiteralPath (Join-Path $env:RUNNER_TEMP "libvirtualhid-driver-install.log")
throw "Windows Installer did not close the registered sunshine.exe fixture."
}
} finally {
if ($isFixture -and !$fixture.HasExited) {
Stop-Process -Id $fixture.Id -Force -ErrorAction SilentlyContinue
$null = $fixture.WaitForExit(10000)
}
Remove-Item -LiteralPath $env:FIXTURE_EXE -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath (Split-Path -Parent $env:FIXTURE_EXE) -ErrorAction SilentlyContinue
}

- name: Enable GitHub Actions evaluation window
if: runner.os == 'Windows'
shell: pwsh
Expand Down Expand Up @@ -513,6 +551,63 @@ jobs:
--xml-pretty \
-o reports/coverage.xml

- name: Repair Windows driver installer with an open consumer handle
if: runner.os == 'Windows'
shell: pwsh
timeout-minutes: 10
run: |
$installer = Get-ChildItem -LiteralPath .\windows-driver-installer -Filter *.msi |
Select-Object -First 1
if (!$installer) {
throw "Windows driver installer artifact did not contain an MSI."
}
if ((Get-Service -Name libvirtualhid_broker).Status -ne "Running") {
throw "The broker must be running before the MSI repair regression test."
}

$deviceHandle = [System.IO.File]::Open(
"\\.\LibVirtualHid",
[System.IO.FileMode]::Open,
[System.IO.FileAccess]::ReadWrite,
[System.IO.FileShare]::ReadWrite
)
$logPath = Join-Path $env:RUNNER_TEMP "libvirtualhid-driver-repair.log"
$driverLogPath = Join-Path $env:ProgramData "libvirtualhid\install-driver.log"
$setupApiLogPath = Join-Path $env:windir "inf\setupapi.dev.log"
$repairStartedAt = Get-Date
try {
$repairArguments = @(
"/i", $installer.FullName,
"REINSTALL=ALL", "REINSTALLMODE=amus",
"/qn", "/norestart", "/L*v", $logPath
)
$process = Start-Process `
-FilePath msiexec.exe `
-ArgumentList $repairArguments `
-PassThru `
-WindowStyle Hidden
if (!$process.WaitForExit([int] [TimeSpan]::FromMinutes(5).TotalMilliseconds)) {
Get-Content -LiteralPath $logPath -Tail 200 -ErrorAction SilentlyContinue
Get-Content -LiteralPath $driverLogPath -Tail 200 -ErrorAction SilentlyContinue
Stop-Process -Id $process.Id -Force -ErrorAction SilentlyContinue
throw "Windows driver installer repair timed out after 5 minutes."
}
if ($process.ExitCode -notin @(0, 3010)) {
Get-Content -LiteralPath $logPath -ErrorAction SilentlyContinue
Get-Content -LiteralPath $driverLogPath -ErrorAction SilentlyContinue
Get-WinEvent -FilterHashtable @{
LogName = "Microsoft-Windows-PowerShell/Operational"
StartTime = $repairStartedAt
Id = 4100
} -ErrorAction SilentlyContinue | Format-List TimeCreated, Id, Message
Get-Content -LiteralPath $setupApiLogPath -Tail 300 -ErrorAction SilentlyContinue
throw "Windows driver installer repair exited with code $($process.ExitCode)."
}
(Get-Service -Name libvirtualhid_broker).WaitForStatus("Running", [TimeSpan]::FromSeconds(15))
} finally {
$deviceHandle.Dispose()
}

- name: Uninstall Windows driver installer with an open consumer handle
if: >-
always() &&
Expand Down
7 changes: 6 additions & 1 deletion cmake/packaging/windows_wix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ set(CPACK_WIX_VERSION 4)
set(CPACK_GENERATOR "WIX")
set(WIX_VERSION 4.0.4)
set(WIX_UI_VERSION 4.0.4) # extension versioning is independent of the WiX version
set(WIX_UTIL_VERSION 4.0.4)
set(WIX_BUILD_PARENT_DIRECTORY "${CMAKE_BINARY_DIR}/wix_packaging")
set(WIX_BUILD_DIRECTORY "${CPACK_PACKAGE_DIRECTORY}/_CPack_Packages/win64/WIX")

Expand Down Expand Up @@ -55,6 +56,7 @@ function(libvirtualhid_wix_ensure_extension extension_name extension_version)
endfunction()

libvirtualhid_wix_ensure_extension(WixToolset.UI.wixext ${WIX_UI_VERSION})
libvirtualhid_wix_ensure_extension(WixToolset.Util.wixext ${WIX_UTIL_VERSION})

set(CPACK_WIX_ROOT "${WIX_TOOL_PATH}")
set(CPACK_WIX_UPGRADE_GUID "71D7B738-9D83-4E57-82E3-C3106D9F8053")
Expand All @@ -66,7 +68,10 @@ set(CPACK_WIX_PROGRAM_MENU_FOLDER "LizardByte")
# https://learn.microsoft.com/en-us/windows/win32/msi/reinstallmode
set(CPACK_WIX_PROPERTY_REINSTALLMODE "amus")
set(CPACK_WIX_EXTENSIONS
"WixToolset.UI.wixext")
"WixToolset.UI.wixext"
"WixToolset.Util.wixext")
set(CPACK_WIX_CUSTOM_XMLNS
"util=http://wixtoolset.org/schemas/v4/wxs/util")

set(CPACK_WIX_PATCH_FILE
"${CMAKE_CURRENT_LIST_DIR}/wix_resources/libvirtualhid-driver-installer-patch.xml")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<CPackWiXPatch>
<CPackWiXPatch xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<CPackWiXFragment Id="#PRODUCT">
<!-- Device handles do not make Sunshine appear in MSI file-in-use detection. -->
<util:RestartResource Id="RR_SunshineService" ServiceName="SunshineService" />
<util:RestartResource Id="RR_SunshineProcess" ProcessName="sunshine.exe" />

<CustomAction Id="CA_LibVirtualHidInstallDriver"
Directory="INSTALL_ROOT"
ExeCommand="&quot;[WindowsFolder]System32\WindowsPowerShell\v1.0\powershell.exe&quot; -WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File &quot;[INSTALL_ROOT]scripts\windows\install-driver.ps1&quot; -InfPath &quot;[INSTALL_ROOT]drivers\windows\libvirtualhid.inf&quot; -CertificatePath &quot;[INSTALL_ROOT]certificates\libvirtualhid-ci-test.cer&quot; -BrokerPath &quot;[INSTALL_ROOT]services\windows\libvirtualhid_broker.exe&quot; -SetupPath &quot;[INSTALL_ROOT]tools\windows\libvirtualhid_driver_setup.exe&quot; -LogPath &quot;[CommonAppDataFolder]libvirtualhid\install-driver.log&quot;"
Expand Down
13 changes: 13 additions & 0 deletions docs/windows-driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,19 @@ Restart Windows if the installer requests it. The package installs the
default. Applications can then use the normal C++ API without administrator
privileges.

During a reinstall or upgrade, the installer stops the broker before updating
the driver. This disconnects existing virtual devices. The interactive MSI
includes running Sunshine applications and `SunshineService` in Windows'
standard applications-to-close dialog. Closing Sunshine disconnects active
streams. Allow Windows to close it, or stop it yourself before continuing;
restart Sunshine and reconnect afterward. Silent installations follow Windows
Installer's Restart Manager policy without displaying the dialog.

Close other applications using libvirtualhid before upgrading. If an open
device handle prevents Windows from reloading the driver,
installation can finish with a reboot warning in `install-driver.log`;
restart Windows before using the updated driver.

A machine license is required to create a driver-backed device. Open
`virtualhid_control.exe` to activate or refresh a license, select a gamepad
profile, and create a test controller. The tool can submit buttons, axes,
Expand Down
Loading
Loading