2017-12-16 18:55:08 +01:00
|
|
|
@ECHO OFF & SETLOCAL EnableDelayedExpansion
|
2017-11-17 15:45:16 +01:00
|
|
|
TITLE ghacks user.js updater
|
|
|
|
|
|
|
|
REM ### ghacks-user.js updater for Windows
|
|
|
|
REM ## author: @claustromaniac
|
2017-12-17 16:59:55 +01:00
|
|
|
REM ## version: 4.0
|
2017-11-17 15:45:16 +01:00
|
|
|
|
2017-11-26 15:57:32 +01:00
|
|
|
SET _myname=%~n0
|
|
|
|
SET _myparams=%*
|
2017-11-19 08:58:47 +01:00
|
|
|
:parse
|
2017-12-16 18:55:08 +01:00
|
|
|
IF "%~1"=="" ( GOTO endparse )
|
|
|
|
IF /I "%~1"=="-unattended" ( SET _ua=1 )
|
|
|
|
IF /I "%~1"=="-log" ( SET _log=1 )
|
|
|
|
IF /I "%~1"=="-logp" ( SET _log=1 & SET _logp=1 )
|
|
|
|
IF /I "%~1"=="-multioverrides" ( SET _multi=1 )
|
2017-12-17 13:02:34 +01:00
|
|
|
IF /I "%~1"=="-merge" ( SET _merge=1 )
|
2017-12-16 18:55:08 +01:00
|
|
|
IF /I "%~1"=="-updatebatch" ( SET _updateb=1 )
|
2017-11-19 08:58:47 +01:00
|
|
|
SHIFT
|
|
|
|
GOTO parse
|
|
|
|
:endparse
|
2017-11-28 22:53:20 +01:00
|
|
|
IF DEFINED _updateb (
|
2017-12-03 16:07:15 +01:00
|
|
|
REM The normal flow here goes from phase 1 to phase 2 and then phase 3.
|
2017-11-28 22:53:20 +01:00
|
|
|
IF NOT "!_myname:~0,9!"=="[updated]" (
|
2017-11-30 01:10:01 +01:00
|
|
|
IF EXIST "[updated]!_myname!.bat" (
|
2017-12-09 17:49:42 +01:00
|
|
|
REM ## Phase 3 ##: The new script, with the original name, will:
|
|
|
|
REM * Delete the [updated]*.bat script
|
|
|
|
REM * Begin the normal routine
|
|
|
|
REN "[updated]!_myname!.bat" "[updated]!_myname!.bat.old"
|
2017-12-03 14:35:41 +01:00
|
|
|
DEL /F "[updated]!_myname!.bat.old"
|
2017-12-17 14:46:39 +01:00
|
|
|
CALL :message "Script updated^!"
|
2017-11-30 23:17:58 +01:00
|
|
|
TIMEOUT 3 >nul
|
|
|
|
CLS
|
2017-11-30 01:10:01 +01:00
|
|
|
GOTO begin
|
|
|
|
)
|
2017-12-09 17:49:42 +01:00
|
|
|
REM ## Phase 1 ##
|
|
|
|
REM * Download new batch and name it [updated]*.bat
|
|
|
|
REM * Start that script in a new CMD window
|
|
|
|
REM * Exit
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Updating script..."
|
2017-11-28 22:53:20 +01:00
|
|
|
REM Uncomment the next line and comment the powershell call for testing.
|
|
|
|
REM COPY /B /V /Y "!_myname!.bat" "[updated]!_myname!.bat"
|
2017-11-29 05:56:33 +01:00
|
|
|
(
|
|
|
|
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/ghacksuserjs/ghacks-user.js/raw/master/updater.bat', '[updated]!_myname!.bat')"
|
|
|
|
) >nul 2>&1
|
2017-11-28 22:53:20 +01:00
|
|
|
IF EXIST "[updated]!_myname!.bat" (
|
2017-11-30 01:10:01 +01:00
|
|
|
START /min CMD /C "[updated]!_myname!.bat" !_myparams!
|
2017-11-28 22:53:20 +01:00
|
|
|
EXIT /B
|
|
|
|
) ELSE (
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Failed. Make sure PowerShell is allowed internet access."
|
2017-11-30 23:17:58 +01:00
|
|
|
TIMEOUT 120 >nul
|
2017-11-28 22:53:20 +01:00
|
|
|
EXIT /B
|
|
|
|
)
|
|
|
|
) ELSE (
|
2017-11-30 01:10:01 +01:00
|
|
|
IF "!_myname!"=="[updated]" (
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "The [updated] label is reserved. Rename this script and try again."
|
2017-11-30 23:17:58 +01:00
|
|
|
TIMEOUT 300 >nul
|
2017-11-30 01:10:01 +01:00
|
|
|
) ELSE (
|
2017-12-09 17:49:42 +01:00
|
|
|
REM ## Phase 2 ##: The [updated]*.bat script will:
|
|
|
|
REM * Copy itself overwriting the original batch
|
|
|
|
REM * Start that script in a new CMD instance
|
|
|
|
REM * Exit
|
2017-12-10 02:20:39 +01:00
|
|
|
IF EXIST "!_myname:~9!.bat" (
|
2017-12-09 17:49:42 +01:00
|
|
|
REN "!_myname:~9!.bat" "!_myname:~9!.bat.old"
|
|
|
|
DEL /F "!_myname:~9!.bat.old"
|
2017-12-03 14:35:41 +01:00
|
|
|
)
|
2017-11-30 01:10:01 +01:00
|
|
|
COPY /B /V /Y "!_myname!.bat" "!_myname:~9!.bat"
|
|
|
|
START CMD /C "!_myname:~9!.bat" !_myparams!
|
2017-11-28 22:53:20 +01:00
|
|
|
)
|
2017-11-30 01:10:01 +01:00
|
|
|
EXIT /B
|
2017-11-28 22:53:20 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
:begin
|
2017-12-16 18:55:08 +01:00
|
|
|
ECHO:
|
|
|
|
ECHO:
|
|
|
|
ECHO: ########################################
|
|
|
|
ECHO: #### user.js Updater for Windows ####
|
|
|
|
ECHO: #### by claustromaniac ####
|
|
|
|
ECHO: #### v4.0 ####
|
|
|
|
ECHO: ########################################
|
|
|
|
ECHO:
|
2017-11-26 15:57:32 +01:00
|
|
|
SET /A "_line=0"
|
|
|
|
IF NOT EXIST user.js (
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "user.js not detected in the current directory."
|
2017-11-26 15:57:32 +01:00
|
|
|
) ELSE (
|
|
|
|
FOR /F "skip=1 tokens=1,2 delims=:" %%G IN (user.js) DO (
|
2017-11-17 15:45:16 +01:00
|
|
|
SET /A "_line+=1"
|
2017-12-16 18:55:08 +01:00
|
|
|
IF !_line! GEQ 4 ( GOTO exitloop )
|
|
|
|
IF !_line! EQU 1 ( SET _name=%%H )
|
|
|
|
IF !_line! EQU 2 ( SET _date=%%H )
|
|
|
|
IF !_line! EQU 3 ( SET _version=%%G )
|
2017-11-17 15:45:16 +01:00
|
|
|
)
|
2017-11-26 15:57:32 +01:00
|
|
|
:exitloop
|
2017-11-17 15:45:16 +01:00
|
|
|
IF !_line! GEQ 4 (
|
2017-12-16 18:55:08 +01:00
|
|
|
IF /I NOT "!_name!"=="!_name:ghacks=!" (
|
|
|
|
CALL :message "ghacks user.js !_version:~2!,!_date!"
|
2017-11-26 15:57:32 +01:00
|
|
|
) ELSE (
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Current user.js version not recognised."
|
2017-11-26 15:57:32 +01:00
|
|
|
)
|
|
|
|
) ELSE (
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Current user.js version not recognised."
|
2017-11-26 15:57:32 +01:00
|
|
|
)
|
|
|
|
)
|
2017-12-16 18:55:08 +01:00
|
|
|
ECHO:
|
2017-11-26 15:57:32 +01:00
|
|
|
IF NOT DEFINED _ua (
|
2017-12-17 13:02:34 +01:00
|
|
|
CALL :message "This batch should be run from your Firefox profile directory."
|
2017-12-16 18:55:08 +01:00
|
|
|
ECHO: It will download the latest version of ghacks user.js from github and then
|
|
|
|
CALL :message "append any of your own changes from user-overrides.js to it."
|
|
|
|
CALL :message "Visit the wiki for more detailed information."
|
|
|
|
ECHO:
|
|
|
|
TIMEOUT 1 /nobreak >nul
|
|
|
|
CHOICE /C SHE /N /M "Start [S] Help [H] Exit [E]"
|
|
|
|
CLS
|
|
|
|
IF ERRORLEVEL 3 ( EXIT /B )
|
|
|
|
IF ERRORLEVEL 2 ( GOTO :showhelp )
|
2017-11-19 08:58:47 +01:00
|
|
|
)
|
2017-11-26 15:57:32 +01:00
|
|
|
IF DEFINED _log (
|
|
|
|
CALL :log >>user.js-update-log.txt 2>&1
|
2017-12-17 13:02:34 +01:00
|
|
|
IF DEFINED _logp ( START user.js-update-log.txt )
|
2017-11-19 08:58:47 +01:00
|
|
|
EXIT /B
|
2017-11-19 18:41:19 +01:00
|
|
|
:log
|
2017-12-16 18:55:08 +01:00
|
|
|
ECHO:##################################################################
|
|
|
|
CALL :message "%date%, %time%"
|
2017-11-19 08:58:47 +01:00
|
|
|
)
|
2017-12-03 16:04:41 +01:00
|
|
|
IF EXIST user.js.old.bak ( DEL /F user.js.old.bak )
|
2017-11-17 15:45:16 +01:00
|
|
|
IF EXIST user.js (
|
2017-12-03 16:04:41 +01:00
|
|
|
IF EXIST user.js.bak ( REN user.js.bak user.js.old.bak )
|
2017-11-17 15:45:16 +01:00
|
|
|
REN user.js user.js.bak
|
2017-12-17 13:02:34 +01:00
|
|
|
CALL :message "Current user.js file backed up."
|
2017-11-17 15:45:16 +01:00
|
|
|
)
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Retrieving latest user.js file from github repository..."
|
2017-11-29 05:56:33 +01:00
|
|
|
(
|
|
|
|
powershell -Command "(New-Object Net.WebClient).DownloadFile('https://github.com/ghacksuserjs/ghacks-user.js/raw/master/user.js', 'user.js')"
|
|
|
|
) >nul 2>&1
|
2017-11-17 15:45:16 +01:00
|
|
|
IF EXIST user.js (
|
2017-11-26 15:57:32 +01:00
|
|
|
IF DEFINED _multi (
|
2017-12-17 13:02:34 +01:00
|
|
|
FORFILES /P user.js-overrides /M *.js >nul 2>&1
|
2017-12-16 18:55:08 +01:00
|
|
|
IF NOT ERRORLEVEL 1 (
|
2017-11-26 15:57:32 +01:00
|
|
|
IF DEFINED _merge (
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Merging..."
|
|
|
|
COPY /B /V /Y user.js-overrides\*.js user-overrides-merged.js
|
|
|
|
CALL :merge user-overrides-merged.js
|
|
|
|
COPY /B /V /Y user.js+user-overrides-merged.js user.js
|
|
|
|
CALL :merge user.js
|
2017-11-26 15:57:32 +01:00
|
|
|
) ELSE (
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Appending..."
|
2017-11-26 15:57:32 +01:00
|
|
|
COPY /B /V /Y user.js+"user.js-overrides\*.js" user.js
|
|
|
|
)
|
2017-12-16 18:55:08 +01:00
|
|
|
) ELSE ( CALL :message "No override files found." )
|
|
|
|
ECHO:
|
2017-11-26 15:57:32 +01:00
|
|
|
) ELSE (
|
|
|
|
IF EXIST "user-overrides.js" (
|
2017-12-16 18:55:08 +01:00
|
|
|
COPY /B /V /Y user.js+"user-overrides.js" "user.js"
|
2017-11-26 15:57:32 +01:00
|
|
|
IF DEFINED _merge (
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Merging user-overrides.js..."
|
|
|
|
CALL :merge user.js
|
2017-11-26 15:57:32 +01:00
|
|
|
) ELSE (
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "user-overrides.js appended."
|
2017-11-26 15:57:32 +01:00
|
|
|
)
|
2017-12-16 18:55:08 +01:00
|
|
|
) ELSE ( CALL :message "user-overrides.js not found." )
|
|
|
|
ECHO:
|
2017-11-17 15:45:16 +01:00
|
|
|
)
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Handling backups..."
|
2017-11-19 08:58:47 +01:00
|
|
|
SET "changed="
|
2017-11-26 15:57:32 +01:00
|
|
|
IF EXIST user.js.bak (
|
|
|
|
FC user.js.bak user.js >nul && SET "changed=false" || SET "changed=true"
|
|
|
|
)
|
2017-12-16 18:55:08 +01:00
|
|
|
ECHO:
|
2017-11-19 08:58:47 +01:00
|
|
|
IF "!changed!"=="true" (
|
2017-11-27 14:02:12 +01:00
|
|
|
IF EXIST user.js.old.bak DEL /F user.js.old.bak
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Update complete."
|
2017-11-19 08:58:47 +01:00
|
|
|
) ELSE (
|
|
|
|
IF "!changed!"=="false" (
|
|
|
|
DEL /F user.js.bak
|
|
|
|
IF EXIST user.js.old.bak REN user.js.old.bak user.js.bak
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Update completed without changes."
|
|
|
|
) ELSE ( CALL :message "Update complete." )
|
2017-11-19 08:58:47 +01:00
|
|
|
)
|
2017-12-16 18:55:08 +01:00
|
|
|
ECHO:
|
2017-11-17 15:45:16 +01:00
|
|
|
) ELSE (
|
2017-12-01 05:05:24 +01:00
|
|
|
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 )
|
2017-12-16 18:55:08 +01:00
|
|
|
CALL :message "Update failed. Make sure PowerShell is allowed internet access."
|
|
|
|
CALL :message "No changes were made."
|
2017-11-19 08:58:47 +01:00
|
|
|
)
|
2017-11-26 15:57:32 +01:00
|
|
|
IF NOT DEFINED _log (
|
2017-12-16 18:55:08 +01:00
|
|
|
IF NOT DEFINED _ua ( PAUSE )
|
2017-11-17 15:45:16 +01:00
|
|
|
)
|
2017-11-26 21:47:30 +01:00
|
|
|
EXIT /B
|
|
|
|
|
2017-12-16 18:55:08 +01:00
|
|
|
REM ########### Message Function ###########
|
|
|
|
:message
|
2017-12-17 14:46:39 +01:00
|
|
|
SETLOCAL DisableDelayedExpansion
|
2017-12-16 18:55:08 +01:00
|
|
|
ECHO:
|
|
|
|
ECHO: %~1
|
|
|
|
ECHO:
|
2017-12-17 14:46:39 +01:00
|
|
|
ENDLOCAL
|
2017-12-16 18:55:08 +01:00
|
|
|
GOTO :EOF
|
|
|
|
REM ############ Merge function ############
|
2017-11-27 14:02:12 +01:00
|
|
|
:merge
|
2017-12-16 18:55:08 +01:00
|
|
|
SETLOCAL DisableDelayedExpansion
|
2017-11-29 17:15:20 +01:00
|
|
|
(
|
2017-12-16 18:55:08 +01:00
|
|
|
FOR /F "tokens=1,* delims=," %%G IN ('FINDSTR /B /I /C:"user_pref" "%~1"') DO (SET "%%G=%%H")
|
2017-12-17 16:59:55 +01:00
|
|
|
FOR /F "tokens=1,* delims=:" %%I IN ('FINDSTR /N "^" "%~1"') DO (
|
2017-12-17 16:02:52 +01:00
|
|
|
IF ""=="%%J" (
|
|
|
|
ECHO:
|
|
|
|
) ELSE (
|
|
|
|
FOR /F "delims=," %%K IN ("%%J") DO (
|
|
|
|
IF NOT [user_pref("_user.js.parrot"]==[%%K] (
|
|
|
|
IF DEFINED %%K (
|
|
|
|
SETLOCAL EnableDelayedExpansion
|
|
|
|
FOR /F "delims=" %%L IN ("!%%K!") DO (
|
|
|
|
ENDLOCAL
|
|
|
|
IF NOT "%%L"=="ALREADY MERGED" (
|
|
|
|
ECHO:%%K,%%L
|
|
|
|
SET "%%K=ALREADY MERGED"
|
|
|
|
)
|
2017-12-17 14:46:39 +01:00
|
|
|
)
|
2017-12-17 16:02:52 +01:00
|
|
|
) ELSE (
|
|
|
|
ECHO:%%J
|
2017-11-27 14:02:12 +01:00
|
|
|
)
|
2017-12-16 18:55:08 +01:00
|
|
|
) ELSE (
|
2017-12-17 14:46:39 +01:00
|
|
|
ECHO:%%J
|
2017-12-16 18:55:08 +01:00
|
|
|
)
|
2017-11-26 21:47:30 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2017-12-16 18:55:08 +01:00
|
|
|
)>updatertempfile
|
|
|
|
MOVE /Y updatertempfile "%~1" >nul
|
2017-11-27 14:02:12 +01:00
|
|
|
ENDLOCAL
|
2017-11-28 17:32:32 +01:00
|
|
|
GOTO :EOF
|
2017-12-16 18:55:08 +01:00
|
|
|
REM ############### Help ##################
|
|
|
|
:showhelp
|
|
|
|
MODE 80,38
|
|
|
|
CLS
|
|
|
|
CALL :message "Available switches (case-insensitive):"
|
|
|
|
CALL :message " -log"
|
|
|
|
ECHO: Writes the console output to a logfile (user.js-update-log.txt)
|
|
|
|
CALL :message " -logP"
|
|
|
|
ECHO: Like log, but also opens the logfile after updating.
|
|
|
|
CALL :message " -merge"
|
|
|
|
ECHO: Merges overrides instead of appending them. Comments and _user.js.parrot
|
|
|
|
ECHO: lines are appended normally. Overrides for inactive (commented out)
|
|
|
|
ECHO: user.js prefs will be appended. When -Merge and -MultiOverrides are used
|
|
|
|
ECHO: together, a user-overrides-merged.js file is also generated in the root
|
|
|
|
ECHO: directory for quick reference. It contains only the merged data from
|
|
|
|
ECHO: override files and can be safely discarded after updating, or used as the
|
|
|
|
ECHO: new user-overrides.js. When there are conflicting records for the same
|
|
|
|
ECHO: pref, the value of the last one declared will be used.
|
|
|
|
CALL :message " -multiOverrides"
|
|
|
|
ECHO: uses any and all .js files in a user.js-overrides sub-folder as overrides
|
|
|
|
ECHO: instead of the default user-overrides.js file. Files are appended in
|
|
|
|
ECHO: alphabetical order.
|
|
|
|
CALL :message " -updatebatch"
|
|
|
|
ECHO: The script will update itself on execution.
|
|
|
|
CALL :message ""
|
|
|
|
PAUSE
|
|
|
|
CLS
|
|
|
|
MODE 80,25
|
|
|
|
GOTO :begin
|
|
|
|
REM #####################################
|