fix(packaging/windows): add Sunshine directories to system PATH (#3727)

This commit is contained in:
ReenigneArcher
2025-03-21 22:19:57 -04:00
committed by GitHub
parent 7c8113ded8
commit 873939a7b2
3 changed files with 119 additions and 4 deletions

View File

@ -20,6 +20,9 @@ install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/windows/misc/service/"
install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/windows/misc/migration/"
DESTINATION "scripts"
COMPONENT assets)
install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/windows/misc/path/"
DESTINATION "scripts"
COMPONENT assets)
# Configurable options for the service
install(DIRECTORY "${SUNSHINE_SOURCE_ASSETS_DIR}/windows/misc/autostart/"
@ -64,6 +67,7 @@ SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
IfSilent +2 0
ExecShell 'open' 'https://docs.lizardbyte.dev/projects/sunshine'
nsExec::ExecToLog 'icacls \\\"$INSTDIR\\\" /reset'
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\\\"'
@ -78,7 +82,7 @@ set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
"${CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS}
nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\delete-firewall-rule.bat\\\"'
nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\uninstall-service.bat\\\"'
nsExec::ExecToLog '\\\"$INSTDIR\\\\sunshine.exe\\\" --restore-nvprefs-undo'
nsExec::ExecToLog '\\\"$INSTDIR\\\\${CMAKE_PROJECT_NAME}.exe\\\" --restore-nvprefs-undo'
MessageBox MB_YESNO|MB_ICONQUESTION \
'Do you want to remove Virtual Gamepad?' \
/SD IDNO IDNO NoGamepad
@ -88,16 +92,18 @@ set(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS
'Do you want to remove $INSTDIR (this includes the configuration, cover images, and settings)?' \
/SD IDNO IDNO NoDelete
RMDir /r \\\"$INSTDIR\\\"; skipped if no
nsExec::ExecToLog '\\\"$INSTDIR\\\\scripts\\\\update-path.bat\\\" remove'
NoDelete:
")
# Adding an option for the start menu
set(CPACK_NSIS_MODIFY_PATH "OFF")
set(CPACK_NSIS_MODIFY_PATH OFF)
set(CPACK_NSIS_EXECUTABLES_DIRECTORY ".")
# This will be shown on the installed apps Windows settings
set(CPACK_NSIS_INSTALLED_ICON_NAME "${CMAKE_PROJECT_NAME}.exe")
set(CPACK_NSIS_CREATE_ICONS_EXTRA
"${CPACK_NSIS_CREATE_ICONS_EXTRA}
SetOutPath '\$INSTDIR'
CreateShortCut '\$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\${CMAKE_PROJECT_NAME}.lnk' \
'\$INSTDIR\\\\${CMAKE_PROJECT_NAME}.exe' '--shortcut'
")

View File

@ -335,8 +335,6 @@ recommended for most users. No support will be provided!}
scripts/uninstall-service.bat
```
To uninstall, delete the extracted directory which contains the `sunshine.exe` file.
## Initial Setup
After installation, some initial setup is required.

View File

@ -0,0 +1,111 @@
@echo off
setlocal EnableDelayedExpansion
rem Check if parameter is provided
if "%~1"=="" (
echo Usage: %0 [add^|remove]
echo add - Adds Sunshine directories to system PATH
echo remove - Removes Sunshine directories from system PATH
exit /b 1
)
rem Get sunshine root directory
for %%I in ("%~dp0\..") do set "ROOT_DIR=%%~fI"
echo Sunshine root directory: !ROOT_DIR!
rem Define directories to add to path
set "PATHS_TO_MANAGE[0]=!ROOT_DIR!"
set "PATHS_TO_MANAGE[1]=!ROOT_DIR!\tools"
rem System path registry location
set "KEY_NAME=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
set "VALUE_NAME=Path"
rem Get the current path
for /f "tokens=2*" %%A in ('reg query "%KEY_NAME%" /v "%VALUE_NAME%"') do set "CURRENT_PATH=%%B"
echo Current path: !CURRENT_PATH!
rem Check if adding to path
if /i "%~1"=="add" (
set "NEW_PATH=!CURRENT_PATH!"
rem Process each directory to add
for /L %%i in (0,1,1) do (
set "DIR_TO_ADD=!PATHS_TO_MANAGE[%%i]!"
rem Check if path already contains this directory
echo "!CURRENT_PATH!" | findstr /i /c:"!DIR_TO_ADD!" > nul
if !ERRORLEVEL!==0 (
echo !DIR_TO_ADD! already in path
) else (
echo Adding to path: !DIR_TO_ADD!
set "NEW_PATH=!NEW_PATH!;!DIR_TO_ADD!"
)
)
rem Only update if path was changed
if "!NEW_PATH!" neq "!CURRENT_PATH!" (
rem Set the new path in the registry
reg add "%KEY_NAME%" /v "%VALUE_NAME%" /t REG_EXPAND_SZ /d "!NEW_PATH!" /f
if !ERRORLEVEL!==0 (
echo Successfully added Sunshine directories to PATH
) else (
echo Failed to add Sunshine directories to PATH
)
) else (
echo No changes needed to PATH
)
exit /b !ERRORLEVEL!
)
rem Check if removing from path
if /i "%~1"=="remove" (
set "CHANGES_MADE=0"
rem Process each directory to remove
for /L %%i in (0,1,1) do (
set "DIR_TO_REMOVE=!PATHS_TO_MANAGE[%%i]!"
rem Check if path contains this directory
echo "!CURRENT_PATH!" | findstr /i /c:"!DIR_TO_REMOVE!" > nul
if !ERRORLEVEL!==0 (
echo Removing from path: !DIR_TO_REMOVE!
rem Build a new path by parsing and filtering the current path
set "NEW_PATH="
for %%p in ("!CURRENT_PATH:;=" "!") do (
set "PART=%%~p"
if /i "!PART!" NEQ "!DIR_TO_REMOVE!" (
if defined NEW_PATH (
set "NEW_PATH=!NEW_PATH!;!PART!"
) else (
set "NEW_PATH=!PART!"
)
)
)
set "CURRENT_PATH=!NEW_PATH!"
set "CHANGES_MADE=1"
) else (
echo !DIR_TO_REMOVE! not found in path
)
)
rem Only update if path was changed
if "!CHANGES_MADE!"=="1" (
rem Set the new path in the registry
reg add "%KEY_NAME%" /v "%VALUE_NAME%" /t REG_EXPAND_SZ /d "!CURRENT_PATH!" /f
if !ERRORLEVEL!==0 (
echo Successfully removed Sunshine directories from PATH
) else (
echo Failed to remove Sunshine directories from PATH
)
) else (
echo No changes needed to PATH
)
exit /b !ERRORLEVEL!
)
echo Unknown parameter: %~1
echo Usage: %0 [add^|remove]
exit /b 1