-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwatch.cmd
211 lines (152 loc) · 4.37 KB
/
watch.cmd
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
@echo OFF
GOTO EndComment
FileBot Schedule Folder Watch Script v1.4
Written by CapriciousSage (Ithiel), inspired by Katates
Requires Windows 7 or higher.
This file requires Administrative Privileges
FileBot written by rednoah (Reinhard Pointner)
FileBot: http://www.filebot.net
Help Support FileBot!
Please Donate via PayPal: http://www.filebot.net/donate.html
No warranty given or implied, use at your own risk.
Last Updated: 24/02/2014
:EndComment
:ADMIN-CHECK
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
GOTO DirCheck1
) else ( GOTO gotAdmin )
:DirCheck1
copy /Y NUL "%~dp0\.writable" > NUL 2>&1 && set WRITEOK=1
IF DEFINED WRITEOK (
del "%~dp0\.writable"
GOTO UACPrompt1
) else (
echo Checking profile instead...
GOTO DirCheck2
)
:DirCheck2
copy /Y NUL "%USERPROFILE%\.writable" > NUL 2>&1 && set WRITEOK=1
IF DEFINED WRITEOK (
del "%USERPROFILE%\.writable"
GOTO UACPrompt2
) else (
echo Checking temp instead...
GOTO DirCheck3
)
:DirCheck3
copy /Y NUL "%tmp%\.writable" > NUL 2>&1 && set WRITEOK=1
IF DEFINED WRITEOK (
del "%tmp%\.writable"
GOTO UACPrompt3
) else (
GOTO UACFailed
)
:UACPrompt1
echo Set UAC = CreateObject^("Shell.Application"^) > "%~dp0\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params% "%1" "%2"", "", "runas", 1 >> "%~dp0\getadmin.vbs"
"%~dp0\getadmin.vbs"
if '%errorlevel%' NEQ '0' (
del "%~dp0\getadmin.vbs"
GOTO DirCheck2
) else ( GOTO UACPrompt1Complete )
:UACPrompt1Complete
del "%~dp0\getadmin.vbs"
exit /b
GOTO gotAdmin
:UACPrompt2
echo Set UAC = CreateObject^("Shell.Application"^) > "%USERPROFILE%\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params% "%1" "%2"", "", "runas", 1 >> "%USERPROFILE%\getadmin.vbs"
"%USERPROFILE%\getadmin.vbs"
if '%errorlevel%' NEQ '0' (
del "%USERPROFILE%\getadmin.vbs"
GOTO DirCheck3
) else ( GOTO UACPrompt2Complete )
:UACPrompt2Complete
del "%USERPROFILE%\getadmin.vbs"
exit /b
GOTO gotAdmin
:UACPrompt3
echo Set UAC = CreateObject^("Shell.Application"^) > "%tmp%\getadmin.vbs"
set params = %*:"=""
echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params% "%1" "%2"", "", "runas", 1 >> "%tmp%\getadmin.vbs"
"%tmp%\getadmin.vbs"
if '%errorlevel%' NEQ '0' (
del "%tmp%\getadmin.vbs"
GOTO UACFailed
) else ( GOTO UACPrompt3Complete )
:UACPrompt3Complete
del "%tmp%\getadmin.vbs"
exit /b
GOTO gotAdmin
:UACFailed
echo Upgrading to admin privliages failed.
echo Please right click the file and run as administrator.
echo PAUSE
GOTO FINISH
:gotAdmin
pushd "%CD%"
CD /D "%~dp0"
:--------------------------------------
GOTO SETUP
:SETUP
set logfile="%tmp%\filebot_watch_script_log.txt"
set watchsettings="C:\Program Files\FileBot\cmdlets\watch_settings.txt"
GOTO DetermineJobType
:DetermineJobType
:: determine if adding or removing a task
set var1=%1
set var1=%var1:"=%
set var2=%2
set var2=%var2:"=%
set var3=%var1:\=-%
set var3=%var3::=%
if "%var2%"=="setnonmatch" (
goto ScheduleNonMatch
) ELSE (
if "%var2%"=="setmatch" (
goto ScheduleMatch
) ELSE (
GOTO ERR1
)
)
)
GOTO ERR1
:ScheduleNonMatch
set /p nonmatch=<%watchsettings%
call set nonmatch=%%nonmatch:PATH_HERE=%var1%%%
call set nonmatch=%nonmatch:~0,-1%
ECHO Scanning Folder: %var1% >> %logfile%
powershell %nonmatch%; exit
if not errorlevel 0 GOTO ERR1
ECHO Scan Complete Folder: %var1% >> %logfile%
GOTO ALLOK
:ScheduleMatch
for /f "tokens=*" %%i in ('findstr MATCH_VIDEO %watchsettings%') do set match=%%i
call set match=%%match:PATH_HERE=%var1%%%
call set match=%match:~0,-1%
ECHO Scanning Folder: %var1% >> %logfile%
powershell %match%; exit
if not errorlevel 0 GOTO ERR1
ECHO Scan Complete Folder: %var1% >> %logfile%
GOTO ALLOK
:ERR1
echo **** Warning: Something Didn't Work. Please Confirm Settings **** >> %logfile%
echo. >> %logfile%
echo Press any key to terminate install ...
pause>nul
GOTO FINISH
:ALLOK
echo ****** Job completed successfully ***** >> %logfile%
echo. >> %logfile%
GOTO FINISH
:FINISH
:: %logfile%
EXIT /B