fix(windows): bundle vigembus instead of downloading it (#4088)

This commit is contained in:
ReenigneArcher 2025-07-16 18:34:06 -04:00 committed by GitHub
parent 1725da216b
commit 1d4f5c3798
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 70 deletions

View File

@ -4,6 +4,20 @@ install(TARGETS sunshine RUNTIME DESTINATION "." COMPONENT application)
# Hardening: include zlib1.dll (loaded via LoadLibrary() in openssl's libcrypto.a)
install(FILES "${ZLIB}" DESTINATION "." COMPONENT application)
# ViGEmBus installer
set(VIGEMBUS_INSTALLER "${CMAKE_BINARY_DIR}/vigembus_installer.exe")
file(DOWNLOAD
"https://github.com/nefarius/ViGEmBus/releases/download/v1.21.442.0/ViGEmBus_1.21.442_x64_x86_arm64.exe"
${VIGEMBUS_INSTALLER}
SHOW_PROGRESS
EXPECTED_HASH SHA256=155c50f1eec07bdc28d2f61a3e3c2c6c132fee7328412de224695f89143316bc
TIMEOUT 60
)
install(FILES ${VIGEMBUS_INSTALLER}
DESTINATION "scripts"
RENAME "vigembus_installer.exe"
COMPONENT gamepad)
# Adding tools
install(TARGETS dxgi-info RUNTIME DESTINATION "tools" COMPONENT dxgi)
install(TARGETS audio-info RUNTIME DESTINATION "tools" COMPONENT audio)

View File

@ -15,7 +15,8 @@ SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\update-path.bat\\\" add'
nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\migrate-config.bat\\\"'
nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\add-firewall-rule.bat\\\"'
nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\install-gamepad.bat\\\"'
nsExec::ExecToLog \
'powershell.exe -ExecutionPolicy Bypass -File \\\"$INSTDIR\\\\scripts\\\\install-gamepad.ps1\\\"'
nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\install-service.bat\\\"'
nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\autostart-service.bat\\\"'
NoController:
@ -31,7 +32,9 @@ set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
MessageBox MB_YESNO|MB_ICONQUESTION \
'Do you want to remove Virtual Gamepad?' \
/SD IDNO IDNO NoGamepad
nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\uninstall-gamepad.bat\\\"'; skipped if no
nsExec::ExecToLog \
'powershell.exe -ExecutionPolicy Bypass -File \\\"$INSTDIR\\\\scripts\\\\uninstall-gamepad.ps1\\\"'; \
skipped if no
NoGamepad:
MessageBox MB_YESNO|MB_ICONQUESTION \
'Do you want to remove $INSTDIR (this includes the configuration, cover images, and settings)?' \

View File

@ -1,64 +0,0 @@
@echo off
setlocal enabledelayedexpansion
rem Check if a compatible version of ViGEmBus is already installed (1.17 or later)
rem
rem Note: We use exit code 2 to indicate success because either 0 or 1 may be returned
rem based on the PowerShell version if an exception occurs.
powershell -c Exit $(if ((Get-Item "$env:SystemRoot\System32\drivers\ViGEmBus.sys").VersionInfo.FileVersion -ge [System.Version]"1.17") { 2 } Else { 1 })
if %ERRORLEVEL% EQU 2 (
goto skip
)
goto continue
:skip
echo "The installed version is 1.17 or later, no update needed. Exiting."
exit /b 0
:continue
rem Get temp directory
set temp_dir=%temp%/Sunshine
rem Create temp directory if it doesn't exist
if not exist "%temp_dir%" mkdir "%temp_dir%"
rem Get system proxy setting
set proxy=
for /f "tokens=3" %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^| find /i "ProxyEnable"') do (
set ProxyEnable=%%a
if !ProxyEnable! equ 0x1 (
for /f "tokens=3" %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" ^| find /i "ProxyServer"') do (
set proxy=%%a
echo Using system proxy !proxy! to download Virtual Gamepad
set proxy=-x !proxy!
)
) else (
rem Proxy is not enabled.
)
)
rem get browser_download_url from asset 0 of https://api.github.com/repos/nefarius/vigembus/releases/latest
set latest_release_url=https://api.github.com/repos/nefarius/vigembus/releases/latest
rem Use curl to get the api response, and find the browser_download_url
for /F "tokens=* USEBACKQ" %%F in (`curl -s !proxy! -L %latest_release_url% ^| findstr browser_download_url`) do (
set browser_download_url=%%F
)
rem Strip quotes
set browser_download_url=%browser_download_url:"=%
rem Remove the browser_download_url key
set browser_download_url=%browser_download_url:browser_download_url: =%
echo %browser_download_url%
rem Download the exe
curl -s -L !proxy! -o "%temp_dir%\virtual_gamepad.exe" %browser_download_url%
rem Install Virtual Gamepad
%temp_dir%\virtual_gamepad.exe /passive /promptrestart
rem Delete temp directory
rmdir /S /Q "%temp_dir%"

View File

@ -0,0 +1,20 @@
# Check if a compatible version of ViGEmBus is already installed (1.17 or later)
try {
$vigemBusPath = "$env:SystemRoot\System32\drivers\ViGEmBus.sys"
$fileVersion = (Get-Item $vigemBusPath).VersionInfo.FileVersion
if ($fileVersion -ge [System.Version]"1.17") {
Write-Information "The installed version is 1.17 or later, no update needed. Exiting."
exit 0
}
}
catch {
Write-Information "ViGEmBus driver not found or inaccessible, proceeding with installation."
}
# Install Virtual Gamepad
$scriptPath = Split-Path -Parent $MyInvocation.MyCommand.Path
$installerPath = Join-Path $scriptPath "vigembus_installer.exe"
Start-Process `
-FilePath $installerPath `
-ArgumentList "/passive", "/promptrestart"

View File

@ -1,4 +0,0 @@
@echo off
rem Use wmic to get the uninstall Virtual Gamepad
wmic product where name="ViGEm Bus Driver" call uninstall

View File

@ -0,0 +1,8 @@
# Use Get-CimInstance to find and uninstall Virtual Gamepad
$product = Get-CimInstance -ClassName Win32_Product -Filter "Name='ViGEm Bus Driver'"
if ($product) {
Invoke-CimMethod -InputObject $product -MethodName Uninstall
Write-Information "ViGEm Bus Driver uninstalled successfully"
} else {
Write-Warning "ViGEm Bus Driver not found"
}