updater.bat v3.0 FINAL
THE REAL FUCKING DEAL this time - finally! THANKS @claustromaniac !!
This commit is contained in:
commit
9a4982ec0e
67
updater.bat
67
updater.bat
@ -28,10 +28,48 @@ IF /I "%~1"=="-multioverrides" (
|
||||
IF /I "%~1"=="-merge" (
|
||||
SET _merge=1
|
||||
)
|
||||
IF /I "%~1"=="-updatebatch" (
|
||||
SET _updateb=1
|
||||
)
|
||||
SHIFT
|
||||
GOTO parse
|
||||
:endparse
|
||||
ECHO.
|
||||
IF DEFINED _updateb (
|
||||
IF NOT "!_myname:~0,9!"=="[updated]" (
|
||||
ECHO Checking updater version...
|
||||
ECHO.
|
||||
IF EXIST "[updated]!_myname!.bat" ( DEL /F "[updated]!_myname!.bat" )
|
||||
REM Uncomment the next line and comment the powershell call for testing.
|
||||
REM COPY /B /V /Y "!_myname!.bat" "[updated]!_myname!.bat"
|
||||
(
|
||||
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/ghacksuserjs/ghacks-user.js/raw/master/updater.bat', '[updated]!_myname!.bat')"
|
||||
) >nul 2>&1
|
||||
IF EXIST "[updated]!_myname!.bat" (
|
||||
START CMD /C "[updated]!_myname!.bat" !_myparams!
|
||||
EXIT /B
|
||||
) ELSE (
|
||||
ECHO Failed. Make sure PowerShell is allowed internet access.
|
||||
ECHO.
|
||||
TIMEOUT 300
|
||||
EXIT /B
|
||||
)
|
||||
) ELSE (
|
||||
IF EXIST "!_myname:~9!.bat" (
|
||||
REN "!_myname:~9!.bat" "!_myname:~9!.old"
|
||||
CALL :begin
|
||||
REN "!_myname!.bat" "!_myname:~9!.bat"
|
||||
DEL /F "!_myname:~9!.old"
|
||||
EXIT /B
|
||||
) ELSE (
|
||||
ECHO.
|
||||
ECHO The [updated] label is reserved. Do not run an [updated] script directly, or rename it to something else before you run it.
|
||||
TIMEOUT 300
|
||||
EXIT /B
|
||||
)
|
||||
)
|
||||
)
|
||||
:begin
|
||||
SET /A "_line=0"
|
||||
IF NOT EXIST user.js (
|
||||
ECHO user.js not detected in the current directory.
|
||||
@ -93,7 +131,9 @@ IF EXIST user.js (
|
||||
ECHO.
|
||||
)
|
||||
ECHO Retrieving latest user.js file from github repository...
|
||||
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/ghacksuserjs/ghacks-user.js/raw/master/user.js', 'user.js')" >nul
|
||||
(
|
||||
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/ghacksuserjs/ghacks-user.js/raw/master/user.js', 'user.js')"
|
||||
) >nul 2>&1
|
||||
ECHO.
|
||||
IF EXIST user.js (
|
||||
IF DEFINED _multi (
|
||||
@ -106,8 +146,8 @@ IF EXIST user.js (
|
||||
ECHO.
|
||||
COPY /B /V /Y user.js-overrides\*.js user-overrides
|
||||
CALL :merge user-overrides user-overrides-merged.js
|
||||
COPY /B /V /Y user.js+user-overrides-merged.js temp2
|
||||
CALL :merge temp2 user.js
|
||||
COPY /B /V /Y user.js+user-overrides-merged.js updatertempfile
|
||||
CALL :merge updatertempfile user.js
|
||||
) ELSE (
|
||||
ECHO.
|
||||
ECHO Appending...
|
||||
@ -120,8 +160,8 @@ IF EXIST user.js (
|
||||
IF EXIST "user-overrides.js" (
|
||||
IF DEFINED _merge (
|
||||
ECHO Merging user-overrides.js...
|
||||
COPY /B /V /Y user.js+user-overrides.js temp2
|
||||
CALL :merge temp2 user.js
|
||||
COPY /B /V /Y user.js+user-overrides.js updatertempfile
|
||||
CALL :merge updatertempfile user.js
|
||||
) ELSE (
|
||||
ECHO Appending user-overrides.js...
|
||||
ECHO.
|
||||
@ -168,8 +208,8 @@ EXIT /B
|
||||
|
||||
REM ###### Merge function ######
|
||||
:merge
|
||||
DEL /F %2 2>nul
|
||||
SETLOCAL disabledelayedexpansion
|
||||
(
|
||||
FOR /F "tokens=1,* delims=]" %%G IN ('find /n /v "" ^< "%~1"') DO (
|
||||
SET "_pref=%%H"
|
||||
SETLOCAL enabledelayedexpansion
|
||||
@ -180,27 +220,28 @@ FOR /F "tokens=1,* delims=]" %%G IN ('find /n /v "" ^< "%~1"') DO (
|
||||
SET "_pref=%%S"
|
||||
)
|
||||
SET _pref=!_pref:"=""!
|
||||
FIND /I "!_pref!" %~2 >nul 2>&1
|
||||
FIND /I "!_pref!" updatertempfile1 >nul 2>&1
|
||||
IF ERRORLEVEL 1 (
|
||||
FIND /I "!_pref!" %~1 >temp123
|
||||
FOR /F "tokens=* delims=" %%X IN (temp123) DO (
|
||||
FOR /F "tokens=* delims=" %%X IN ('FIND /I "!_pref!" %~1') DO (
|
||||
SET "_temp=%%X"
|
||||
SET "_temp=!_temp: =!"
|
||||
IF /I "user_pref"=="!_temp:~0,9!" (
|
||||
SET "_pref=%%X"
|
||||
)
|
||||
)
|
||||
ECHO(!_pref!>>%~2
|
||||
ECHO(!_pref!
|
||||
ECHO(!_pref!>>updatertempfile1
|
||||
)
|
||||
) ELSE (
|
||||
ECHO(!_pref!>>%~2
|
||||
ECHO(!_pref!
|
||||
)
|
||||
) ELSE (
|
||||
ECHO(!_pref!>>%~2
|
||||
ECHO(!_pref!
|
||||
)
|
||||
ENDLOCAL
|
||||
)
|
||||
)>%~2
|
||||
ENDLOCAL
|
||||
DEL /F %~1 temp123 >nul
|
||||
DEL /F %1 updatertempfile1 >nul
|
||||
GOTO :EOF
|
||||
REM ############################
|
||||
|
Loading…
Reference in New Issue
Block a user