-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslm.bat
192 lines (167 loc) · 6.29 KB
/
slm.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
@echo off
cd /d "%~dp0"
setlocal enabledelayedexpansion
:: Set local variables
for %%I in (.) do set "dir_current=%%~fI"
set "dir_download=%dir_current%\slm"
set "dir_existing=%dir_current%\_internal"
set "dir_existing_upgrade=%dir_existing%\program_files"
set "dir_donwload_upgrade=%dir_download%\_internal"
set "handle=%~1"
set "link=https://www.dropbox.com/scl/fi/apw33xi80jjivyjp9rxb4/slm_windows.zip?rlkey=1m5zj7qz9ittguispsi00nyar&dl=1"
set "outfile=slm.zip"
set "executable=slm.exe"
set "executable_path=%dir_current%\%executable%"
set "batch=slm.bat"
set "batch_path='%dir_current%\%batch%'"
set "run_command=powershell -NoProfile -ExecutionPolicy Bypass -Command ^"Start-Process -WindowStyle hidden '%executable_path%'^""
set "scheduled_task=schtasks /create /tn "Streaming Library Manager^" /tr ^"%batch_path%^" /sc onlogon /rl highest /f"
set "temp_batch=%dir_current%\temp.bat"
if [%1] neq [] goto handles
:: Check if the executable file exists
if exist "%executable%" (
:: Run Executable
call %run_command%
) else (
:: Display error message and pause
echo Streaming Library Manager not installed. Please install using 'slm.bat install'.
timeout /T -1
)
goto end
:download
:: Check if the process is running
echo Checking to see if Streaming Library Manager is running...
tasklist /FI "IMAGENAME eq %executable%" 2>NUL | find /I "%executable%" >NUL
:: If the process is found, kill it
if "%ERRORLEVEL%"=="0" (
echo %executable% is running. Attempting to kill it...
echo taskkill /F /IM !executable! > "%temp_batch%"
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process cmd -ArgumentList '/c \"%temp_batch%\"' -Verb RunAs"
echo Killing, please wait...
timeout /NOBREAK /T 5
del /f "%temp_batch%"
echo %executable% has been terminated.
) else (
echo %executable% is not running.
)
:: Download and extract files
echo Downloading Streaming Library Manager files...
powershell -NoProfile -ExecutionPolicy Bypass -Command "Invoke-WebRequest -Uri '%link%' -OutFile '%outfile%'"
timeout /NOBREAK /T 5
echo Extracting Streaming Library Manager files...
powershell -NoProfile -ExecutionPolicy Bypass -Command "Expand-Archive -LiteralPath .\%outfile%"
timeout /NOBREAK /T 5
if "%handle%"=="upgrade" (
if exist "%dir_existing_upgrade%" (
echo Moving user program files...
move /Y "%dir_existing_upgrade%" "%dir_donwload_upgrade%"
timeout /NOBREAK /T 5
)
)
echo Cleaning up files...
del /q "%outfile%"
if exist "%executable%" (
del /Q "%executable%"
)
if exist %dir_existing% (
rd /S /Q "%dir_existing%"
)
timeout /NOBREAK /T 5
echo Moving files to final destination...
xcopy /E /Y /Q "%dir_download%\*" "%dir_current%"
if exist "%dir_download%" rd /S /Q "%dir_download%"
timeout /NOBREAK /T 5
goto %return_path%
:handles
:: Handle additional commands
:: Install
if "%handle%"=="install" (
echo WARNING: Installing will overwrite any existing installation and user files.
:install_prompt
choice /C YN /M "Do you wish to continue"
if errorlevel 2 (
echo Installation canceled.
goto end
) else if errorlevel 1 (
echo Beginning installation...
set "return_path=continue_install"
goto download
:continue_install
echo Installation completed!
goto end
) else (
echo Invalid input. Please enter Y or N.
goto prompt
)
)
:: Upgrade
if "%handle%"=="upgrade" (
echo Beginning upgrade...
set "return_path=continue_upgrade"
goto download
:continue_upgrade
echo Upgrade completed!
goto end
)
:: Startup
if "%handle%"=="startup" (
echo Setting Streaming Library Manager to run on startup...
echo !scheduled_task! > "%temp_batch%"
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process cmd -ArgumentList '/c \"%temp_batch%\"' -Verb RunAs"
echo Creating task, please wait...
timeout /NOBREAK /T 5
del /f "%temp_batch%"
echo Startup task complete. To start now, just run 'slm.bat' with no handles.
goto end
)
:: Port
if "%handle%"=="port" (
:port_input
set /P "port_number=Please enter a port number between 1000 and 9999 (or enter the default 5000): "
echo You entered: [!port_number!]
rem Check if the input is a positive integer between 1000 and 9999
for /F "delims=0123456789" %%A in ("!port_number!") do (
echo Invalid port number. Please enter a positive integer between 1000 and 9999.
goto port_input
)
if !port_number! lss 1000 (
echo Invalid port number. Please enter a positive integer between 1000 and 9999.
goto port_input
)
if !port_number! gtr 9999 (
echo Invalid port number. Please enter a positive integer between 1000 and 9999.
goto port_input
)
rem Create the variable
echo Saving port number to environment variables...
setx "SLM_PORT" "!port_number!"
echo Streaming Library Manager port set to [!port_number!].
rem Add a new inbound rule to Windows Firewall
echo Opening port in Windows firewall...
echo netsh advfirewall firewall add rule name="Streaming Library Manager" dir=in action=allow protocol=TCP localport=!port_number! > "%temp_batch%"
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process cmd -ArgumentList '/c \"%temp_batch%\"' -Verb RunAs"
echo Please wait...
timeout /NOBREAK /T 5
del /f "%temp_batch%"
echo Port !port_number! has been opened in Windows Firewall.
:: Check if the port is open
echo Checking if port !port_number! is open...
netstat -an | find ":!port_number!" >nul
if %errorlevel% neq 0 (
echo Port !port_number! is not open or the server is not listening.
) else (
echo Port !port_number! is open and the server is listening.
)
echo Please completely exit out of this command prompt and restart Streaming Library Manager in a new window for the port to take effect.
goto end
)
:: Invalid handle
if "%handle%" neq "install" (
if "%handle%" neq "upgrade" (
echo Invalid command. Usage: 'slm.bat [install ^| upgrade ^| startup ^| port]'
)
)
:end
:: Exit the script
endlocal
exit /b