-
Notifications
You must be signed in to change notification settings - Fork 0
/
steam_shutdown_helper.bat
144 lines (99 loc) · 3.49 KB
/
steam_shutdown_helper.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
@ECHO off
COLOR 03
REM --- Created by @BWBellairs --- Version: 1.4.8
setlocal EnableExtensions EnableDelayedExpansion
:do_choice
TASKLIST /FI "IMAGENAME eq Steam.exe" 2>NUL | find /I /N "Steam.exe">NULabout:blank#blocked
IF "%ERRORLEVEL%"=="0" (
ECHO Please close Steam or start updating your games in steam now.
ECHO If you don't close steam, you will be taken staight to shutdown options
TIMEOUT /t 20
GOTO :do_shutdown_options
)
SET /P st_delay="Enter Number of Seconds to wait before starting steam: "
SET /A st_delay=%st_delay%
ECHO:
:do_shutdown_options
SET "sh_delay_active=n"
CHOICE /M "Want to shutdown after a delay or use Smart Shutdown?"
IF "%ERRORLEVEL%"=="1" (
SET "sh_delay_active=y"
)
ECHO:
SET "smart_shutdown_enabled="
SET "sh_mode="
SET "sh_delay="
IF "%sh_delay_active%"=="y" (
SET "smart_shutdown_enabled=n"
CHOICE /M "Would you like to enable Smart Shutdown? Computer will shutdown when it has detected that Steam isn't downloading any updates for games."
IF "!ERRORLEVEL!"=="1" (
SET "smart_shutdown_enabled=y"
)
IF NOT "!smart_shutdown_enabled!" EQU "y" (
SET /P "sh_delay=Enter Number of Seconds to wait before shutting down (Do an hour after the download eta) "
SET /A sh_delay=!sh_delay!
)
CHOICE /C rsh /M "Shutdown mode restart(r) shutdown (s) hibernate/sleep (h): "
IF "!ERRORLEVEL!"=="1" (SET "sh_mode=r")
IF "!ERRORLEVEL!"=="2" (SET "sh_mode=s")
IF "!ERRORLEVEL!"=="3" (SET "sh_mode=h")
ECHO:
)
TASKLIST /FI "IMAGENAME eq Steam.exe" 2>NUL | find /I /N "Steam.exe">NUL
IF "%ERRORLEVEL%"=="1" (
ECHO Starting Steam in !st_delay! seconds
TIMEOUT /t !st_delay! /nobreak
ECHO:
ECHO Starting Steam
START steam://
ECHO Steam launched
REM Let's wait 15 seconds before starting the shutdown loop. (if steam updates, that doesn't matter as it will still be using disk/network)
TIMEOUT /t 15 /nobreak
)
If "%sh_delay_active%" EQU "y" (
IF NOT "!smart_shutdown_enabled!" EQU "y" (
ECHO Starting Shutdown delay with mode %sh_mode%
TIMEOUT /t !sh_delay! /nobreak
ECHO Preparing to shutdown... if you wish to stop this, press WINDOWS KEY, type 'shutdown /a' then press ENTER
ECHO Shutting down...
IF "!sh_mode!"=="h" (SHUTDOWN /!sh_mode!
)ELSE (SHUTDOWN /!sh_mode! /t 120)
PAUSE
EXIT
)
)
SET \A shutdown_attempts=0
IF "%sh_delay_active%" EQU "y" (
IF "!smart_shutdown_enabled!" EQU "y" (
ECHO Waiting for Steam to cease activity before shutting down
:start_loop
FOR /f "tokens=2 delims=," %%c in ('typeperf "\Process(Steam)\IO Data Operations/sec" -si 1 -sc 1 ^| find /V "\\"') do (
IF %%c EQU "0.000000%" (
SET /a shutdown_attempts=!shutdown_attempts!+1
) ELSE (
SET /a shutdown_attempts=0
)
PING www.google.com -n 1 -w 1000 > NUL
IF "!ERRORLEVEL!"=="1" (SET internet_connected="false") else (SET internet_connected="true")
IF "!internet_connected!"=="false" (SET /a shutdown_attempts=0)
IF !shutdown_attempts!==10 GOTO :end_loop
GOTO :start_loop
:end_loop
ECHO Preparing to shutdown... if you wish to stop this, press WINDOWS KEY, type 'shutdown /a' then press ENTER
ECHO Shutting down...
IF "!sh_mode!"=="h" (SHUTDOWN /!sh_mode!
)ELSE (SHUTDOWN /!sh_mode! /t 120)
PAUSE
EXIT
)
)
)
ECHO:
ECHO Program finished
ECHO:
ECHO -----------------------------------
ECHO BWBellairs' tips his fedora at you.
ECHO -----------------------------------
ECHO:
ECHO Press any key to exit
PAUSE