Skip to content

Commit

Permalink
updater for Windows v4.5 (#407)
Browse files Browse the repository at this point in the history
support commenting-out active user-prefs with the merge function
  • Loading branch information
earthlng authored Apr 25, 2018
1 parent bb4bf83 commit 94f8646
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions updater.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ TITLE ghacks user.js updater

REM ## ghacks-user.js updater for Windows
REM ## author: @claustromaniac
REM ## version: 4.4
REM ## version: 4.5
REM ## instructions: https://github.com/ghacksuserjs/ghacks-user.js/wiki/3.3-Updater-Scripts

SET _myname=%~n0
Expand Down Expand Up @@ -75,7 +75,7 @@ ECHO:
ECHO: ########################################
ECHO: #### user.js Updater for Windows ####
ECHO: #### by claustromaniac ####
ECHO: #### v4.4 ####
ECHO: #### v4.5 ####
ECHO: ########################################
ECHO:
SET /A "_line=0"
Expand Down Expand Up @@ -191,8 +191,9 @@ GOTO :EOF
REM ############ Merge function ############
:merge
SETLOCAL DisableDelayedExpansion
FOR /F tokens^=2^,^*^ delims^=^'^" %%G IN ('FINDSTR /R /C:"^user_pref[ ]*\([ ]*[\"'].*[\"'][ ]*,.*\)[ ]*;" "%~1"') DO (SET "[%%G]=%%H")
FOR /F tokens^=2^,^*^ delims^=^' %%G IN ('FINDSTR /R /C:"^//// --- comment-out --- '[^'][^']*'.*" "%~1"') DO (SET "__unset__%%G=1")
(
FOR /F tokens^=2^,^*^ delims^=^'^" %%G IN ('FINDSTR /B /R /C:"user_pref.*\)[ ]*;" "%~1"') DO (IF NOT "%%H"=="" (SET "%%G=%%H"))
FOR /F "tokens=1,* delims=:" %%I IN ('FINDSTR /N "^" "%~1"') DO (
SET "_temp=%%J"
SETLOCAL EnableDelayedExpansion
Expand All @@ -205,11 +206,15 @@ SETLOCAL DisableDelayedExpansion
ENDLOCAL
FOR /F tokens^=2^ delims^=^'^" %%K IN ("%%J") DO (
IF NOT "_user.js.parrot"=="%%K" (
IF DEFINED %%K (
SETLOCAL EnableDelayedExpansion
FOR /F "delims=" %%L IN ("!%%K!") DO (
ENDLOCAL & ECHO:user_pref("%%K"%%L
SET "%%K="
IF DEFINED __unset__%%K (
ECHO://%%J
) ELSE (
IF DEFINED [%%K] (
SETLOCAL EnableDelayedExpansion
FOR /F "delims=" %%L IN ("![%%K]!") DO (
ENDLOCAL & ECHO:user_pref("%%K"%%L
SET "[%%K]="
)
)
)
) ELSE (ECHO:%%J)
Expand Down

0 comments on commit 94f8646

Please sign in to comment.