1
0

updater.bat v3.0 FINAL

THE REAL FUCKING DEAL this time - finally! THANKS @claustromaniac !!
This commit is contained in:
earthlng 2017-11-29 23:23:57 +01:00 committed by GitHub
commit 9a4982ec0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -28,10 +28,48 @@ IF /I "%~1"=="-multioverrides" (
IF /I "%~1"=="-merge" ( IF /I "%~1"=="-merge" (
SET _merge=1 SET _merge=1
) )
IF /I "%~1"=="-updatebatch" (
SET _updateb=1
)
SHIFT SHIFT
GOTO parse GOTO parse
:endparse :endparse
ECHO. 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" SET /A "_line=0"
IF NOT EXIST user.js ( IF NOT EXIST user.js (
ECHO user.js not detected in the current directory. ECHO user.js not detected in the current directory.
@ -93,7 +131,9 @@ IF EXIST user.js (
ECHO. ECHO.
) )
ECHO Retrieving latest user.js file from github repository... 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. ECHO.
IF EXIST user.js ( IF EXIST user.js (
IF DEFINED _multi ( IF DEFINED _multi (
@ -106,8 +146,8 @@ IF EXIST user.js (
ECHO. ECHO.
COPY /B /V /Y user.js-overrides\*.js user-overrides COPY /B /V /Y user.js-overrides\*.js user-overrides
CALL :merge user-overrides user-overrides-merged.js CALL :merge user-overrides user-overrides-merged.js
COPY /B /V /Y user.js+user-overrides-merged.js temp2 COPY /B /V /Y user.js+user-overrides-merged.js updatertempfile
CALL :merge temp2 user.js CALL :merge updatertempfile user.js
) ELSE ( ) ELSE (
ECHO. ECHO.
ECHO Appending... ECHO Appending...
@ -120,8 +160,8 @@ IF EXIST user.js (
IF EXIST "user-overrides.js" ( IF EXIST "user-overrides.js" (
IF DEFINED _merge ( IF DEFINED _merge (
ECHO Merging user-overrides.js... ECHO Merging user-overrides.js...
COPY /B /V /Y user.js+user-overrides.js temp2 COPY /B /V /Y user.js+user-overrides.js updatertempfile
CALL :merge temp2 user.js CALL :merge updatertempfile user.js
) ELSE ( ) ELSE (
ECHO Appending user-overrides.js... ECHO Appending user-overrides.js...
ECHO. ECHO.
@ -168,39 +208,40 @@ EXIT /B
REM ###### Merge function ###### REM ###### Merge function ######
:merge :merge
DEL /F %2 2>nul
SETLOCAL disabledelayedexpansion SETLOCAL disabledelayedexpansion
FOR /F "tokens=1,* delims=]" %%G IN ('find /n /v "" ^< "%~1"') DO ( (
SET "_pref=%%H" FOR /F "tokens=1,* delims=]" %%G IN ('find /n /v "" ^< "%~1"') DO (
SETLOCAL enabledelayedexpansion SET "_pref=%%H"
SET "_temp=!_pref: =!" SETLOCAL enabledelayedexpansion
IF /I "user_pref"=="!_temp:~0,9!" ( SET "_temp=!_pref: =!"
IF /I NOT "user.js.parrot"=="!_temp:~12,14!" ( IF /I "user_pref"=="!_temp:~0,9!" (
FOR /F "delims=," %%S IN ("!_pref!") DO ( IF /I NOT "user.js.parrot"=="!_temp:~12,14!" (
SET "_pref=%%S" FOR /F "delims=," %%S IN ("!_pref!") DO (
) SET "_pref=%%S"
SET _pref=!_pref:"=""!
FIND /I "!_pref!" %~2 >nul 2>&1
IF ERRORLEVEL 1 (
FIND /I "!_pref!" %~1 >temp123
FOR /F "tokens=* delims=" %%X IN (temp123) DO (
SET "_temp=%%X"
SET "_temp=!_temp: =!"
IF /I "user_pref"=="!_temp:~0,9!" (
SET "_pref=%%X"
)
) )
ECHO(!_pref!>>%~2 SET _pref=!_pref:"=""!
FIND /I "!_pref!" updatertempfile1 >nul 2>&1
IF ERRORLEVEL 1 (
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!
ECHO(!_pref!>>updatertempfile1
)
) ELSE (
ECHO(!_pref!
) )
) ELSE ( ) ELSE (
ECHO(!_pref!>>%~2 ECHO(!_pref!
) )
) ELSE ( ENDLOCAL
ECHO(!_pref!>>%~2
) )
ENDLOCAL )>%~2
)
ENDLOCAL ENDLOCAL
DEL /F %~1 temp123 >nul DEL /F %1 updatertempfile1 >nul
GOTO :EOF GOTO :EOF
REM ############################ REM ############################