1
0

update to v2.0

https://github.com/ghacksuserjs/ghacks-user.js/issues/264#issuecomment-345462158

- It can now handle read-only files.
- it is somewhat more explicit regarding what it's doing in some circumstances. For example, it now informs the user when no changes are made.
- It now accepts two parameters: `-unattended` and `-log`
- Minor improvements here and there.
This commit is contained in:
earthlng 2017-11-19 08:58:47 +01:00 committed by GitHub
parent 450adab519
commit cdeb0abe79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,13 +3,23 @@ TITLE ghacks user.js updater
REM ### ghacks-user.js updater for Windows REM ### ghacks-user.js updater for Windows
REM ## author: @claustromaniac REM ## author: @claustromaniac
REM ## version: 1.0 REM ## version: 2.0
SETLOCAL EnableDelayedExpansion SETLOCAL EnableDelayedExpansion
SET "_ua="
SET "_log="
:parse
IF "%~1"=="" GOTO endparse
IF "%~1"=="-unattended" SET "_ua=true"
IF "%~1"=="-log" SET "_log=true"
SHIFT
GOTO parse
:endparse
SET "_name=" SET "_name="
SET "_date=" SET "_date="
SET "_version=" SET "_version="
SET /A "_line=0" SET /A "_line=0"
ECHO.
IF EXIST user.js ( IF EXIST user.js (
FOR /F "delims=" %%i IN (user.js) DO ( FOR /F "delims=" %%i IN (user.js) DO (
IF !_line! EQU 1 SET "_name=%%i" IF !_line! EQU 1 SET "_name=%%i"
@ -18,7 +28,7 @@ IF EXIST user.js (
SET /A "_line+=1" SET /A "_line+=1"
IF !_line! GEQ 4 GOTO break IF !_line! GEQ 4 GOTO break
) )
:break: :break
IF !_line! GEQ 4 ( IF !_line! GEQ 4 (
IF "ghacks"=="!_name:~8,6!" ( IF "ghacks"=="!_name:~8,6!" (
FOR /F "delims=:" %%G IN ("!_version!") DO SET "_version=%%G" FOR /F "delims=:" %%G IN ("!_version!") DO SET "_version=%%G"
@ -26,15 +36,30 @@ IF EXIST user.js (
SET "_date=!_date:~8!" SET "_date=!_date:~8!"
ECHO ghacks user.js !_version!, !_date! ECHO ghacks user.js !_version!, !_date!
) ELSE ( ECHO Current user.js version not recognised. ) ) ELSE ( ECHO Current user.js version not recognised. )
) ) ELSE ( ECHO Current user.js version not recognised. )
) ELSE ( ECHO user.js not found. ) ) ELSE ( ECHO user.js not detected in the current directory. )
ECHO. ECHO.
ECHO This batch should be run from your Firefox profile directory. It will download the latest version of ghacks user.js from github and then append any of your own changes from user-overrides.js to it. IF NOT "%_ua%"=="true" (
ECHO. ECHO This batch should be run from your Firefox profile directory. It will download the latest version of ghacks user.js from github and then append any of your own changes from user-overrides.js to it.
CHOICE /M "Continue" ECHO.
IF ERRORLEVEL 2 GOTO end REM Visit the wiki for more detailed information.
REM ECHO.
CHOICE /M "Continue"
IF ERRORLEVEL 2 GOTO end
)
CLS CLS
ECHO. ECHO.
IF "%_log%"=="true" (
CALL :log >>user.js-update-log.txt
EXIT /B
)
:log
IF "%_log%"=="true" (
ECHO ##################################################################
ECHO.
ECHO %date%, %time%
ECHO.
)
IF EXIST user.js ( IF EXIST user.js (
IF EXIST user.js.bak REN user.js.bak user.js.old.bak IF EXIST user.js.bak REN user.js.bak user.js.old.bak
REN user.js user.js.bak REN user.js user.js.bak
@ -46,23 +71,39 @@ powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com
ECHO. ECHO.
IF EXIST user.js ( IF EXIST user.js (
IF EXIST "user-overrides.js" ( IF EXIST "user-overrides.js" (
COPY /b user.js+"user-overrides.js" "temp.js" ECHO Appending user-overrides.js...
DEL user.js ECHO.
REN temp.js user.js COPY /B /V /Y user.js+"user-overrides.js" "tempuserjs"
DEL /F user.js
REN tempuserjs user.js
ECHO.
) )
FC user.js.bak user.js >nul && DEL user.js.bak || IF EXIST user.js.old.bak DEL user.js.old.bak ECHO Handling backups...
SET "changed="
IF EXIST user.js.bak ( FC user.js.bak user.js >nul && SET "changed=false" || SET "changed=true" )
ECHO.
ECHO.
IF "!changed!"=="true" (
IF EXIST user.js.old.bak DEL /F user.js.old.bak
ECHO Update complete.
) ELSE (
IF "!changed!"=="false" (
DEL /F user.js.bak
IF EXIST user.js.old.bak REN user.js.old.bak user.js.bak IF EXIST user.js.old.bak REN user.js.old.bak user.js.bak
CLS ECHO Update completed without changes.
) ELSE ECHO Update complete.
)
ECHO. ECHO.
ECHO Successfully updated!
ECHO.
TIMEOUT 10
) ELSE ( ) ELSE (
IF EXIST user.js.bak REN user.js.bak user.js IF EXIST user.js.bak REN user.js.bak user.js
IF EXIST user.js.old.bak REN user.js.old.bak user.js.bak IF EXIST user.js.old.bak REN user.js.old.bak user.js.bak
ECHO. ECHO.
ECHO Update failed. Make sure PowerShell is allowed internet access. ECHO Update failed. Make sure PowerShell is allowed internet access.
ECHO. ECHO.
PAUSE ECHO No changes were made.
ECHO.
)
:end
IF NOT "%_log%"=="true" (
IF NOT "%_ua%"=="true" PAUSE
) )
:end: