整理目录

This commit is contained in:
Zhanghu
2025-10-28 13:40:25 +08:00
parent 99ea33693c
commit 38cd05834d
144 changed files with 11308 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
@echo off
rem Get sunshine root directory
for %%I in ("%~dp0\..") do set "ROOT_DIR=%%~fI"
set RULE_NAME=Sunshine
set PROGRAM_BIN="%ROOT_DIR%\sunshine.exe"
rem Add the rule
netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=tcp program=%PROGRAM_BIN% enable=yes
netsh advfirewall firewall add rule name=%RULE_NAME% dir=in action=allow protocol=udp program=%PROGRAM_BIN% enable=yes

View File

@@ -0,0 +1,4 @@
@echo off
rem Set the service to auto-start
sc config SunshineService start= auto

View File

@@ -0,0 +1,6 @@
@echo off
set RULE_NAME=Sunshine
rem Delete the rule
netsh advfirewall firewall delete rule name=%RULE_NAME%

View File

@@ -0,0 +1,64 @@
@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,67 @@
@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_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
rem Remove the legacy SunshineSvc service
net stop sunshinesvc
sc delete sunshinesvc
rem Check if SunshineService already exists
sc qc %SERVICE_NAME% > nul 2>&1
if %ERRORLEVEL%==0 (
rem Stop the existing service if running
net stop %SERVICE_NAME%
rem Reconfigure the existing service
set SC_CMD=config
) else (
rem Create a new service
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"
rem Set the description of the service
sc description %SERVICE_NAME% "Sunshine is a self-hosted game stream host for Moonlight."
rem Start the new service
net start %SERVICE_NAME%

View File

@@ -0,0 +1,59 @@
@echo off
rem Get sunshine root directory
for %%I in ("%~dp0\..") do set "OLD_DIR=%%~fI"
rem Create the config directory if it didn't already exist
set "NEW_DIR=%OLD_DIR%\config"
if not exist "%NEW_DIR%\" mkdir "%NEW_DIR%"
icacls "%NEW_DIR%" /reset
rem Migrate all files that aren't already present in the config dir
if exist "%OLD_DIR%\apps.json" (
if not exist "%NEW_DIR%\apps.json" (
move "%OLD_DIR%\apps.json" "%NEW_DIR%\apps.json"
icacls "%NEW_DIR%\apps.json" /reset
)
)
if exist "%OLD_DIR%\sunshine.conf" (
if not exist "%NEW_DIR%\sunshine.conf" (
move "%OLD_DIR%\sunshine.conf" "%NEW_DIR%\sunshine.conf"
icacls "%NEW_DIR%\sunshine.conf" /reset
)
)
if exist "%OLD_DIR%\sunshine_state.json" (
if not exist "%NEW_DIR%\sunshine_state.json" (
move "%OLD_DIR%\sunshine_state.json" "%NEW_DIR%\sunshine_state.json"
icacls "%NEW_DIR%\sunshine_state.json" /reset
)
)
rem Migrate the credentials directory
if exist "%OLD_DIR%\credentials\" (
if not exist "%NEW_DIR%\credentials\" (
move "%OLD_DIR%\credentials" "%NEW_DIR%\"
)
)
rem Create the credentials directory if it wasn't migrated or already existing
if not exist "%NEW_DIR%\credentials\" mkdir "%NEW_DIR%\credentials"
rem Disallow read access to the credentials directory contents for normal users
rem Note: We must use the SIDs directly because "Users" and "Administrators" are localized
icacls "%NEW_DIR%\credentials" /inheritance:r
icacls "%NEW_DIR%\credentials" /grant:r *S-1-5-32-544:(OI)(CI)(F)
icacls "%NEW_DIR%\credentials" /grant:r *S-1-5-32-545:(R)
rem Migrate the covers directory
if exist "%OLD_DIR%\covers\" (
if not exist "%NEW_DIR%\covers\" (
move "%OLD_DIR%\covers" "%NEW_DIR%\"
rem Fix apps.json image path values that point at the old covers directory
powershell -c "(Get-Content '%NEW_DIR%\apps.json').replace('.\/covers\/', '.\/config\/covers\/') | Set-Content '%NEW_DIR%\apps.json'"
)
)
rem Remove log files
del "%OLD_DIR%\*.txt"
del "%OLD_DIR%\*.log"

View File

@@ -0,0 +1,4 @@
@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,41 @@
@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
sc delete sunshinesvc
rem Stop and delete the new SunshineService service
net stop SunshineService
sc delete SunshineService

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