anchor.diff:  if defined DIR goto :dirname.next
   set "DIR=."			&:# If empty, return the current directory
   :dirname.done
  +%PREPVAR% DIR
   endlocal & set "%~2=%DIR%" & exit /b
  +
  +:#----------------------------------------------------------------------------#
  +
  +:IsAdmin
  +>NUL 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
  +exit /b
  +
  +:#----------------------------------------------------------------------------#
  +
  +:# Get the current console code page.
  +:GetCP %1=variable name
  +for /f "tokens=2 delims=:" %%n in ('chcp') do for %%p in (%%n) do set "%1=%%p"
  +exit /b
  +
  +:#----------------------------------------------------------------------------#
  +
  +:# Get a registry value content. Args: KEY NAME [VALUEVAR [TYPEVAR]]
  +:GetRegistryValue
  +%ENTER%
  +setlocal enableextensions enabledelayedexpansion
  +set "KEY=%~1"
  +set "NAME=%~2"
  +set "VALUEVAR=%~3"
  +set "TYPEVAR=%~4"
  +if not defined VALUEVAR set "VALUEVAR=VALUE"
  +set "%VALUEVAR%="
  +:# Returning the type is optional. Do not define a default for TYPEVAR.
  +%ECHOVARS.D% KEY NAME VALUEVAR TYPEVAR
  +if defined NAME (
  +  set CMD=reg query "%KEY%" /v "%NAME%"
  +) else (
  +  set CMD=reg query "%KEY%" /ve
  +)
  +%ECHO.D% %CMD%
  +set "RETCODE=1"
  +:# For each line in CMD output...
  +%FOREACHLINE% %%i in ('%CMD% 2^>NUL') do (
  +  set "RETCODE=0"
  +  set "LINE=%%i"
  +  %ECHOVARS.D% LINE
  +  :# Values are indented by 4 spaces.
  +  set "HEAD=!LINE:~0,4!"
  +  set "LINE=!LINE:~4!"
  +  :# But extra lines of multi-lined values are indented by >20 spaces.
  +  set "HEAD2=!LINE:~0,4!"
  +  if "!HEAD!"=="    " if not "!HEAD2!"=="    " (
  +    :# Some versions of reg.exe use 4 spaces as field separator; others use a TAB. 
  +    :# Change the 4-spaces around the REG_XX type word to a TAB.
  +    set "TOKENS=!LINE:    =	!"
  +    %ECHOVARS.D% TOKENS
  +    :# Extract the value name as the first item before the first TAB.
  +    :# Names can contain spaces, but assume they don't contain TABs.
  +    for /f "tokens=1,2* delims=	" %%j in ("!TOKENS!") do (
  +      set "NAME=%%j"
  +      set "TYPE=%%k"
  +      set "VALUE=%%l"
  +      %ECHOVARS.D% NAME TYPE VALUE
  +    )
  +  )
  +)
  +%PREPVAR% VALUE
  +endlocal & (if defined TYPEVAR set "%TYPEVAR%=%TYPE%") & set "%VALUEVAR%=%VALUE%" & %RETURN% %RETCODE%
  +
  +:#----------------------------------------------------------------------------#
  +
  +:# Append a file pathname to a list of pathnames if it's not already there
  +:FileSet.append %1=LIST_VAR_NAME %2=VALUE
  +setlocal EnableDelayedExpansion
  +set "LIST=!%1!"
  +set "FOUND=0"
  +for %%e in (!LIST!) do if /i "%%~e"=="%~2" set "FOUND=1"
  +if "%FOUND%"=="0" set "LIST=!LIST! %2"
  +%PREPVAR% LIST
  +endlocal & set "%1=%LIST%" & exit /b
   
   :#----------------------------------------------------------------------------#
   
  
positive.code: :#----------------------------------------------------------------------------#
  
  :Main
  set "SRCDIR[x86]=WIN32"
  set "SRCDIR[AMD64]=WIN64"
  
  set "COMMENT=call :Comment"
  set "ECHO=call :Echo"
  set "EXEC=call :Exec"
  set "RETURN=exit /b"
  set "ECHO.D=call :Log"
  set "ECHOVARS.D=call :LogVars"
  
  set "LOG=call :Log"
  set "LOGFILE=%TEMP%\ag_setup.log"
  
  set "QUIET=0"
  
  %LOG% --------------------------------------------------------
  %LOG% %~f0 %*
  :# set >>"%LOGFILE%"
  
  
negative.code: if [%1]==[] goto :start
  if [%1]==[/?] goto :help
  if [%1]==[-?] goto :help
  if [%1]==[-d] call :Debug.on & goto :next_arg
  if [%1]==[-u] call :UninstallAg & %RETURN%
  if [%1]==[-V] (echo %VERSION%) & exit /b 0
  if [%1]==[-X] set "EXEC=echo" & goto :next_arg
  %ERROR% Unexpected argument: %1
  %RETURN% 1
  
  :start
  call :IsAdmin
  if errorlevel 1 (
    %ERROR% This setup script must be run as Administrator
    %RETURN% 1
  )
  
  cd "%SPATH%"
  :# In the winget package, ag.exe is there in the win32 subdirectory.
  :# But when testing setup.bat in the source tree, ag.exe is in "..\..\bin\win32".
  if not exist "win32\ag.exe" if exist "..\..\bin\win32\ag.exe" cd ..\..\bin
  if not exist "win32\ag.exe" (
    %ERROR% Can't find ag.exe masters
    %RETURN% 1
  )
  
  :# Get this new instance version
  call :GetAgVersion "win32\ag.exe"
  