mirror of
https://github.com/thinkonmay/sunshine-sdk.git
synced 2026-01-26 01:46:14 +00:00
fix(installer/windows): remember service start type (#3902)
This commit is contained in:
parent
ef5253a61d
commit
3ad90cd7f1
@ -1,10 +1,13 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
rem Get sunshine root directory
|
||||
for %%I in ("%~dp0\..") do set "ROOT_DIR=%%~fI"
|
||||
|
||||
set SERVICE_NAME=SunshineService
|
||||
set SERVICE_BIN="%ROOT_DIR%\tools\sunshinesvc.exe"
|
||||
set "SERVICE_BIN=%ROOT_DIR%\tools\sunshinesvc.exe"
|
||||
set "SERVICE_CONFIG_DIR=%LOCALAPPDATA%\LizardByte\Sunshine"
|
||||
set "SERVICE_CONFIG_FILE=%SERVICE_CONFIG_DIR%\service_start_type.txt"
|
||||
|
||||
rem Set service to demand start. It will be changed to auto later if the user selected that option.
|
||||
set SERVICE_START_TYPE=demand
|
||||
@ -26,6 +29,34 @@ if %ERRORLEVEL%==0 (
|
||||
set SC_CMD=create
|
||||
)
|
||||
|
||||
rem Check if we have a saved start type from previous installation
|
||||
if exist "%SERVICE_CONFIG_FILE%" (
|
||||
rem Debug output file content
|
||||
type "%SERVICE_CONFIG_FILE%"
|
||||
|
||||
rem Read the saved start type
|
||||
for /f "usebackq delims=" %%a in ("%SERVICE_CONFIG_FILE%") do (
|
||||
set "SAVED_START_TYPE=%%a"
|
||||
)
|
||||
|
||||
echo Raw saved start type: [!SAVED_START_TYPE!]
|
||||
|
||||
rem Check start type
|
||||
if "!SAVED_START_TYPE!"=="2-delayed" (
|
||||
set SERVICE_START_TYPE=delayed-auto
|
||||
) else if "!SAVED_START_TYPE!"=="2" (
|
||||
set SERVICE_START_TYPE=auto
|
||||
) else if "!SAVED_START_TYPE!"=="3" (
|
||||
set SERVICE_START_TYPE=demand
|
||||
) else if "!SAVED_START_TYPE!"=="4" (
|
||||
set SERVICE_START_TYPE=disabled
|
||||
)
|
||||
|
||||
del "%SERVICE_CONFIG_FILE%"
|
||||
)
|
||||
|
||||
echo Setting service start type set to: [!SERVICE_START_TYPE!]
|
||||
|
||||
rem Run the sc command to create/reconfigure the service
|
||||
sc %SC_CMD% %SERVICE_NAME% binPath= %SERVICE_BIN% start= %SERVICE_START_TYPE% DisplayName= "Sunshine Service"
|
||||
|
||||
|
||||
@ -1,4 +1,36 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
set "SERVICE_CONFIG_DIR=%LOCALAPPDATA%\LizardByte\Sunshine"
|
||||
set "SERVICE_CONFIG_FILE=%SERVICE_CONFIG_DIR%\service_start_type.txt"
|
||||
|
||||
rem Save the current service start type to a file if the service exists
|
||||
sc qc SunshineService >nul 2>&1
|
||||
if %ERRORLEVEL%==0 (
|
||||
if not exist "%SERVICE_CONFIG_DIR%\" mkdir "%SERVICE_CONFIG_DIR%\"
|
||||
|
||||
rem Get the start type
|
||||
for /f "tokens=3" %%i in ('sc qc SunshineService ^| findstr /C:"START_TYPE"') do (
|
||||
set "CURRENT_START_TYPE=%%i"
|
||||
)
|
||||
|
||||
rem Set the content to write
|
||||
if "!CURRENT_START_TYPE!"=="2" (
|
||||
sc qc SunshineService | findstr /C:"(DELAYED)" >nul
|
||||
if !ERRORLEVEL!==0 (
|
||||
set "CONTENT=2-delayed"
|
||||
) else (
|
||||
set "CONTENT=2"
|
||||
)
|
||||
) else if "!CURRENT_START_TYPE!" NEQ "" (
|
||||
set "CONTENT=!CURRENT_START_TYPE!"
|
||||
) else (
|
||||
set "CONTENT=unknown"
|
||||
)
|
||||
|
||||
rem Write content to file
|
||||
echo !CONTENT!> "%SERVICE_CONFIG_FILE%"
|
||||
)
|
||||
|
||||
rem Stop and delete the legacy SunshineSvc service
|
||||
net stop sunshinesvc
|
||||
|
||||
Loading…
Reference in New Issue
Block a user