@echo]
@echo Switch to super user.
@echo]

@rem Do not use "echo off" to not affect any child calls.
@setlocal

@rem Get the absolute path to the home directory.
@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%

@rem Get the absolute path to the directory of this file.
@set CWD=%~dp0
@set DOTDIR=dotfiles
@set DOTDOTDIR=%CWD%%DOTDIR%
@set WINDIR=winenv
@set DOTWINDIR=%CWD%%WINDIR%

@rem Make a symbolic links from dotfiles and winenv.
@for %%i in (.vimrc .gvimrc) do @mklink %HOME%\%%i %DOTDOTDIR%\%%i
@for %%i in (.doskey) do @copy %DOTWINDIR%\%%i %HOME%

@pause

@echo]
@echo Switch to super user.
@echo]

@rem Do not use "echo off" to not affect any child calls.
@setlocal

@rem Get the absolute path to the home directory.
@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%

@rem Get the absolute path to the directory of this file.
@set CWD=%~dp0
@set DOTDIR=dotfiles
@set DOTDOTDIR=%CWD%%DOTDIR%
@set WINDIR=winenv
@set DOTWINDIR=%CWD%%WINDIR%

@rem Make a symbolic links from dotfiles and winenv.
@for %%i in (.pvimrc .vimrc .gvimrc) do @mklink %HOME%\%%i %DOTDOTDIR%\%%i
@for %%i in (.doskey) do @copy %DOTWINDIR%\%%i %HOME%

@pause

Add reading setting of .pvimrc in mklink.bat


::
:: Microsoft Azure SDK for Net - Generate library code
:: Copyright (C) Microsoft Corporation. All Rights Reserved.
::

@echo off
setlocal

:: help requested?
set pot_help=%1%2
if "%pot_help%"==""            (set req_help=T)
if "%2"=="help"                (set req_help=T)
if "%2"=="-help"               (set req_help=T)
if "%2"=="--help"              (set req_help=T)
if "%2"=="/help"               (set req_help=T)
if "%pot_help%"=="help"        (set req_help=T)
if "%pot_help%"=="-help"       (set req_help=T)
if "%pot_help%"=="--help"      (set req_help=T)
if "%pot_help%"=="/help"       (set req_help=T)
if not x%pot_help%==x%pot_help:?=% (set req_help=T)
if not "%req_help%" == "" (
    echo.
    echo Usage: generate.cmd
    echo             ^<service, e.g. 'network/resource-manager'^>
    echo             ^<AutoRest version, defaults to 'latest'^>
    echo             ^<GitHub user of specs repo, defaults to 'Azure'^>
    echo             ^<Branch or commit ID of specs repo, defaults to 'master'^>
    echo             ^<actual name of specs repo, defaults to 'azure-rest-api-specs'^>
    echo.
    echo Example: generate.cmd monitor/data-plane 1.2.2 olydis new-cool-feature azure-rest-api-specs-pr
    echo Note: If you are calling an SDK's generate.cmd, the first parameter is already provided for you.
    echo.
    echo To display this help, run either of
    echo      generate.cmd help
    echo      generate.cmd -help
    echo      generate.cmd --help
    echo      generate.cmd /help
    echo      generate.cmd ?
    echo      generate.cmd -?
    echo      generate.cmd --?
    echo      generate.cmd /?
    exit /B
)

:: repo information
set rp="%1"
if not "%2" == "" (set version="%2")         else (set version="latest")
if not "%3" == "" (set specsRepoUser="%3")   else (set specsRepoUser="Azure")
if not "%4" == "" (set specsRepoBranch="%4") else (set specsRepoBranch="master")
if not "%5" == "" (set specsRepoName="%5")   else (set specsRepoName="azure-rest-api-specs")
if not "%6" == "" (set sdksFolder="%6")      else (set sdksFolder=%~dp0..\src\SDKS)
set configFile="https://github.com/%specsRepoUser%/%specsRepoName%/blob/%specsRepoBranch%/specification/%rp%/readme.md"

:: installation
if "%7" == "" (call npm i -g autorest)

:: code generation
@echo on
call autorest %configFile% --csharp --csharp-sdks-folder=%sdksFolder% --version=%version% --reflect-api-versions
@echo off

:: metadata
mkdir %~dp0\..\src\SDKs\_metadata >nul 2>&1
call powershell %~dp0\generateMetadata.ps1 %specsRepoUser% %specsRepoBranch% %version% %configFile% > %~dp0\..\src\SDKs\_metadata\%rp:/=_%.txt

endlocal

::
:: Microsoft Azure SDK for Net - Generate library code
:: Copyright (C) Microsoft Corporation. All Rights Reserved.
::

@echo off
setlocal

:: help requested?
set pot_help=%1%2
if "%pot_help%"==""            (set req_help=T)
if "%2"=="help"                (set req_help=T)
if "%2"=="-help"               (set req_help=T)
if "%2"=="--help"              (set req_help=T)
if "%2"=="/help"               (set req_help=T)
if "%pot_help%"=="help"        (set req_help=T)
if "%pot_help%"=="-help"       (set req_help=T)
if "%pot_help%"=="--help"      (set req_help=T)
if "%pot_help%"=="/help"       (set req_help=T)
if not x%pot_help%==x%pot_help:?=% (set req_help=T)
if not "%req_help%" == "" (
    echo.
    echo Usage: generate.cmd
    echo             ^<service, e.g. 'network/resource-manager'^>
    echo             ^<AutoRest version, defaults to 'latest'^>
    echo             ^<GitHub user of specs repo, defaults to 'Azure'^>
    echo             ^<Branch or commit ID of specs repo, defaults to 'master'^>
    echo             ^<actual name of specs repo, defaults to 'azure-rest-api-specs'^>
    echo.
    echo Example: generate.cmd monitor/data-plane 1.2.2 olydis new-cool-feature azure-rest-api-specs-pr
    echo Note: If you are calling an SDK's generate.cmd, the first parameter is already provided for you.
    echo.
    echo To display this help, run either of
    echo      generate.cmd help
    echo      generate.cmd -help
    echo      generate.cmd --help
    echo      generate.cmd /help
    echo      generate.cmd ?
    echo      generate.cmd -?
    echo      generate.cmd --?
    echo      generate.cmd /?
    exit /B
)

:: repo information
set rp="%1"
if not "%2" == "" (set version="%2")         else (set version="latest")
if not "%3" == "" (set specsRepoUser="%3")   else (set specsRepoUser="Azure")
if not "%4" == "" (set specsRepoBranch="%4") else (set specsRepoBranch="master")
if not "%5" == "" (set specsRepoName="%5")   else (set specsRepoName="azure-rest-api-specs")
if not "%6" == "" (set sdksFolder="%6")      else (set sdksFolder=%~dp0..\sdk)
set configFile="https://github.com/%specsRepoUser%/%specsRepoName%/blob/%specsRepoBranch%/specification/%rp%/readme.md"

:: installation
if "%7" == "" (call npm i -g autorest)

:: code generation
@echo on
call autorest %configFile% --csharp --csharp-sdks-folder=%sdksFolder% --version=%version% --reflect-api-versions
@echo off

:: metadata
mkdir %~dp0\..\src\SDKs\_metadata >nul 2>&1
call powershell %~dp0\generateMetadata.ps1 %specsRepoUser% %specsRepoBranch% %version% %configFile% > %~dp0\..\src\SDKs\_metadata\%rp:/=_%.txt

endlocal

Update generate.cmd to work with new directory structure (#6593)


@echo off

:: Init Script for cmd.exe
:: Created as part of cmder project

:: !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED
:: !!! Use "%CMDER_ROOT%\config\user-profile.cmd" to add your own startup commands

:: Use /v command line arg or set to > 0 for verbose output to aid in debugging.
set verbose-output=0
set debug-output=0
set max_depth=1

:: Find root dir
if not defined CMDER_ROOT (
    if defined ConEmuDir (
        for /f "delims=" %%i in ("%ConEmuDir%\..\..") do (
            set "CMDER_ROOT=%%~fi"
        )
    ) else (
        for /f "delims=" %%i in ("%~dp0\..") do (
            set "CMDER_ROOT=%%~fi"
        )
    )
)

:: Remove trailing '\' from %CMDER_ROOT%
if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%"

call "%cmder_root%\vendor\lib\lib_base"
call "%cmder_root%\vendor\lib\lib_path"
call "%cmder_root%\vendor\lib\lib_console"
call "%cmder_root%\vendor\lib\lib_git"
call "%cmder_root%\vendor\lib\lib_profile"

:var_loop
    if "%~1" == "" (
        goto :start
    ) else if /i "%1"=="/v" (
        set verbose-output=1
    ) else if /i "%1"=="/d" (
        set debug-output=1
    ) else if /i "%1" == "/max_depth" (
        if "%~2" geq "1" if "%~2" leq "5" (
            set "max_depth=%~2"
            shift
        ) else (
            %lib_console% show_error "'/max_depth' requires a number between 1 and 5!"
            exit /b
        )
    ) else if /i "%1" == "/c" (
        if exist "%~2" (
            if not exist "%~2\bin" mkdir "%~2\bin"
            set "cmder_user_bin=%~2\bin"
            if not exist "%~2\config\profile.d" mkdir "%~2\config\profile.d"
            set "cmder_user_config=%~2\config"
            shift
        )
    ) else if /i "%1" == "/user_aliases" (
        if exist "%~2" (
            set "user-aliases=%~2"
            shift
        )
    ) else if /i "%1" == "/git_install_root" (
        if exist "%~2" (
            set "GIT_INSTALL_ROOT=%~2"
            shift
        ) else (
            %lib_console% show_error "The Git install root folder "%~2", you specified does not exist!"
            exit /b
        )
    ) else if /i "%1" == "/home" (
        if exist "%~2" (
            set "HOME=%~2"
            shift
        ) else (
            %lib_console% show_error The home folder "%2", you specified does not exist!
            exit /b
        )
    ) else if /i "%1" == "/svn_ssh" (
        set SVN_SSH=%2
        shift
    )
    shift
goto var_loop

:start
%lib_console% debug-output init.bat "Env Var - CMDER_ROOT=%CMDER_ROOT%"
%lib_console% debug-output init.bat "Env Var - debug-output=%debug-output%"

if defined CMDER_USER_CONFIG (
    %lib_console% debug-output init.bat "CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '%CMDER_USER_CONFIG%'!"
)

:: Pick right version of clink
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
    set architecture=86
    set architecture_bits=32
) else (
    set architecture=64
    set architecture_bits=64
)

:: Tell the user about the clink config files...
if defined "%CMDER_USER_CONFIG%\settings" if not exist "%CMDER_USER_CONFIG%\settings" (
    echo Generating clink initial settings in "%CMDER_USER_CONFIG%\settings"
    echo Additional *.lua files in "%CMDER_USER_CONFIG%" are loaded on startup.\

} else if not exist "%CMDER_ROOT%\config\settings" (
    echo Generating clink initial settings in "%CMDER_ROOT%\config\settings"
    echo Additional *.lua files in "%CMDER_ROOT%\config" are loaded on startup.
)

:: Run clink
if defined CMDER_USER_CONFIG (
    "%CMDER_ROOT%\vendor\clink\clink_x%architecture%.exe" inject --quiet --profile "%CMDER_USER_CONFIG%" --scripts "%CMDER_ROOT%\vendor"
) else (
    "%CMDER_ROOT%\vendor\clink\clink_x%architecture%.exe" inject --quiet --profile "%CMDER_ROOT%\config" --scripts "%CMDER_ROOT%\vendor"
)

:: Prepare for git-for-windows

:: I do not even know, copypasted from their .bat
set PLINK_PROTOCOL=ssh
if not defined TERM set TERM=cygwin

:: The idea:
:: * if the users points as to a specific git, use that
:: * test if a git is in path and if yes, use that
:: * last, use our vendored git
:: also check that we have a recent enough version of git by examining the version string
if defined GIT_INSTALL_ROOT (
    if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" goto :FOUND_GIT)
)

:: get the version information for vendored git binary
setlocal enabledelayedexpansion
%lib_git% read_version VENDORED "%CMDER_ROOT%\vendor\git-for-windows\cmd"
%lib_git% validate_version VENDORED !GIT_VERSION_VENDORED!

:: check if git is in path...
for /F "delims=" %%F in ('where git.exe 2^>nul') do (
    :: get the absolute path to the user provided git binary
    pushd %%~dpF
    set "test_dir=!CD!"
    popd

    :: get the version information for the user provided git binary
    %lib_git% read_version USER "!test_dir!"
    %lib_git% validate_version USER !GIT_VERSION_USER!

    if !errorlevel! geq 0 (
        :: compare the user git version against the vendored version
        %lib_git% compare_versions USER VENDORED

        :: use the user provided git if its version is greater than, or equal to the vendored git
        if !errorlevel! geq 0 if exist "!test_dir:~0,-4!\cmd\git.exe" (
            set "GIT_INSTALL_ROOT=!test_dir:~0,-4!"
            set test_dir=
            goto :FOUND_GIT
        ) else if !errorlevel! geq 0 (
            set "GIT_INSTALL_ROOT=!test_dir!"
            set test_dir=
            goto :FOUND_GIT
        ) else (
            call :verbose-output Found old !GIT_VERSION_USER! in "!test_dir!", but not using...
            set test_dir=
        )
    ) else (

        :: if the user provided git executable is not found
        if !errorlevel! equ -255 (
            call :verbose-output No git at "!git_executable!" found.
            set test_dir=
        )

    )

)

:: our last hope: our own git...
:VENDORED_GIT
if exist "%CMDER_ROOT%\vendor\git-for-windows" (
    set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
    %lib_path% enhance_path "!GIT_INSTALL_ROOT!\cmd"
) else (
    goto :NO_GIT
)

:FOUND_GIT
:: Add git to the path
if defined GIT_INSTALL_ROOT (
    rem add the unix commands at the end to not shadow windows commands like more
    if exist "!GIT_INSTALL_ROOT!\cmd\git.exe" %lib_path% enhance_path "!GIT_INSTALL_ROOT!\cmd" append
    if exist "!GIT_INSTALL_ROOT!\mingw32" (
        %lib_path% enhance_path "!GIT_INSTALL_ROOT!\mingw32" append
    ) else if exist "!GIT_INSTALL_ROOT!\mingw64" (
        %lib_path% enhance_path "!GIT_INSTALL_ROOT!\mingw64" append
    )
    %lib_path% enhance_path "%GIT_INSTALL_ROOT%\usr\bin" append

    :: define SVN_SSH so we can use git svn with ssh svn repositories
    if not defined SVN_SSH set "SVN_SSH=%GIT_INSTALL_ROOT:\=\\%\\bin\\ssh.exe"
)

:NO_GIT
endlocal & set "PATH=%PATH%" & set "SVN_SSH=%SVN_SSH%" & set "GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%"
%lib_console% debug-output init.bat "Env Var - GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%"

:: Enhance Path
%lib_path% enhance_path_recursive "%CMDER_ROOT%\bin" %max_depth%
if defined CMDER_USER_BIN (
  %lib_path% enhance_path_recursive "%CMDER_USER_BIN%" %max_depth%
)
%lib_path% enhance_path "%CMDER_ROOT%" append

:: Drop *.bat and *.cmd files into "%CMDER_ROOT%\config\profile.d"
:: to run them at startup.
%lib_profile% run_profile_d "%CMDER_ROOT%\config\profile.d"
if defined CMDER_USER_CONFIG (
  %lib_profile% run_profile_d "%CMDER_USER_CONFIG%\profile.d"
)

:: Allows user to override default aliases store using profile.d
:: scripts run above by setting the 'aliases' env variable.
::
:: Note: If overriding default aliases store file the aliases
:: must also be self executing, see '.\user-aliases.cmd.example',
:: and be in profile.d folder.
if not defined user-aliases (
  if defined CMDER_USER_CONFIG (
     set "user-aliases=%CMDER_USER_CONFIG%\user-aliases.cmd"
  ) else (
     set "user-aliases=%CMDER_ROOT%\config\user-aliases.cmd"
  )
)

:: The aliases environment variable is used by alias.bat to id
:: the default file to store new aliases in.
if not defined aliases (
  set "aliases=%user-aliases%"
)

:: Make sure we have a self-extracting user-aliases.cmd file
setlocal enabledelayedexpansion
if not exist "%user-aliases%" (
    echo Creating initial user-aliases store in "%user-aliases%"...
    copy "%CMDER_ROOT%\vendor\user-aliases.cmd.example" "%user-aliases%"
) else (
    type "%user-aliases%" | findstr /i ";= Add aliases below here" >nul
    if "!errorlevel!" == "1" (
        echo Creating initial user-aliases store in "%user-aliases%"...
        if defined CMDER_USER_CONFIG (
            copy "%user-aliases%" "%user-aliases%.old_format"
            copy "%CMDER_ROOT%\vendor\user-aliases.cmd.example" "%user-aliases%"
        ) else (
            copy "%user-aliases%" "%user-aliases%.old_format"
            copy "%CMDER_ROOT%\vendor\user-aliases.cmd.example" "%user-aliases%"
        )
    )
)

:: Update old 'user-aliases' to new self executing 'user-aliases.cmd'
if exist "%CMDER_ROOT%\config\aliases" (
  echo Updating old "%CMDER_ROOT%\config\aliases" to new format...
  type "%CMDER_ROOT%\config\aliases" >> "%user-aliases%" && del "%CMDER_ROOT%\config\aliases"
) else if exist "%user-aliases%.old_format" (
  echo Updating old "%user-aliases%" to new format...
  type "%user-aliases%.old_format" >> "%user-aliases%" && del "%user-aliases%.old_format"
)
endlocal

:: Add aliases to the environment
call "%user-aliases%"

:: See vendor\git-for-windows\README.portable for why we do this
:: Basically we need to execute this post-install.bat because we are
:: manually extracting the archive rather than executing the 7z sfx
if exist "%GIT_INSTALL_ROOT%\post-install.bat" (
    %lib_console% verbose-output "Running Git for Windows one time Post Install...."
    pushd "%GIT_INSTALL_ROOT%\"
    "%GIT_INSTALL_ROOT%\git-bash.exe" --no-needs-console --hide --no-cd --command=post-install.bat
    popd
)

:: Set home path
if not defined HOME set "HOME=%USERPROFILE%"
%lib_console% debug-output init.bat "Env Var - HOME=%HOME%"

set "initialConfig=%CMDER_ROOT%\config\user-profile.cmd"
if exist "%CMDER_ROOT%\config\user-profile.cmd" (
    REM Create this file and place your own command in there
    call "%CMDER_ROOT%\config\user-profile.cmd" %*
)

if defined CMDER_USER_CONFIG (
  set "initialConfig=%CMDER_USER_CONFIG%\user-profile.cmd"
  if exist "%CMDER_USER_CONFIG%\user-profile.cmd" (
      REM Create this file and place your own command in there
      call "%CMDER_USER_CONFIG%\user-profile.cmd" %*
  )
)

if not exist "%initialConfig%" (
    echo Creating user startup file: "%initialConfig%"
    (
echo :: use this file to run your own startup commands
echo :: use  in front of the command to prevent printing the command
echo.
echo :: uncomment this to have the ssh agent load when cmder starts
echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd"
echo.
echo :: uncomment this next two lines to use pageant as the ssh authentication agent
echo :: SET SSH_AUTH_SOCK=/tmp/.ssh-pageant-auth-sock
echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-pageant.cmd"
echo.
echo :: you can add your plugins to the cmder path like so
echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%"
echo.
echo @echo off
) >"%initialConfig%"
)

set initialConfig=
exit /b

@echo off

:: Init Script for cmd.exe
:: Created as part of cmder project

:: !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED
:: !!! Use "%CMDER_ROOT%\config\user-profile.cmd" to add your own startup commands

:: Use /v command line arg or set to > 0 for verbose output to aid in debugging.
set verbose-output=0
set debug-output=0
set max_depth=1

:: Find root dir
if not defined CMDER_ROOT (
    if defined ConEmuDir (
        for /f "delims=" %%i in ("%ConEmuDir%\..\..") do (
            set "CMDER_ROOT=%%~fi"
        )
    ) else (
        for /f "delims=" %%i in ("%~dp0\..") do (
            set "CMDER_ROOT=%%~fi"
        )
    )
)

:: Remove trailing '\' from %CMDER_ROOT%
if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%"

call "%cmder_root%\vendor\lib\lib_base"
call "%cmder_root%\vendor\lib\lib_path"
call "%cmder_root%\vendor\lib\lib_console"
call "%cmder_root%\vendor\lib\lib_git"
call "%cmder_root%\vendor\lib\lib_profile"

:var_loop
    if "%~1" == "" (
        goto :start
    ) else if /i "%1"=="/v" (
        set verbose-output=1
    ) else if /i "%1"=="/d" (
        set debug-output=1
    ) else if /i "%1" == "/max_depth" (
        if "%~2" geq "1" if "%~2" leq "5" (
            set "max_depth=%~2"
            shift
        ) else (
            %lib_console% show_error "'/max_depth' requires a number between 1 and 5!"
            exit /b
        )
    ) else if /i "%1" == "/c" (
        if exist "%~2" (
            if not exist "%~2\bin" mkdir "%~2\bin"
            set "cmder_user_bin=%~2\bin"
            if not exist "%~2\config\profile.d" mkdir "%~2\config\profile.d"
            set "cmder_user_config=%~2\config"
            shift
        )
    ) else if /i "%1" == "/user_aliases" (
        if exist "%~2" (
            set "user-aliases=%~2"
            shift
        )
    ) else if /i "%1" == "/git_install_root" (
        if exist "%~2" (
            set "GIT_INSTALL_ROOT=%~2"
            shift
        ) else (
            %lib_console% show_error "The Git install root folder "%~2", you specified does not exist!"
            exit /b
        )
    ) else if /i "%1" == "/home" (
        if exist "%~2" (
            set "HOME=%~2"
            shift
        ) else (
            %lib_console% show_error The home folder "%2", you specified does not exist!
            exit /b
        )
    ) else if /i "%1" == "/svn_ssh" (
        set SVN_SSH=%2
        shift
    )
    set "CMDER_FLAGS=%CMDER_FLAGS% %1"
    shift
goto var_loop

:start
%lib_console% debug-output init.bat "Env Var - CMDER_ROOT=%CMDER_ROOT%"
%lib_console% debug-output init.bat "Env Var - debug-output=%debug-output%"

if defined CMDER_USER_CONFIG (
    %lib_console% debug-output init.bat "CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '%CMDER_USER_CONFIG%'!"
)

:: Pick right version of clink
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
    set architecture=86
    set architecture_bits=32
) else (
    set architecture=64
    set architecture_bits=64
)

:: Tell the user about the clink config files...
if defined "%CMDER_USER_CONFIG%\settings" if not exist "%CMDER_USER_CONFIG%\settings" (
    echo Generating clink initial settings in "%CMDER_USER_CONFIG%\settings"
    echo Additional *.lua files in "%CMDER_USER_CONFIG%" are loaded on startup.\

} else if not exist "%CMDER_ROOT%\config\settings" (
    echo Generating clink initial settings in "%CMDER_ROOT%\config\settings"
    echo Additional *.lua files in "%CMDER_ROOT%\config" are loaded on startup.
)

:: Run clink
if defined CMDER_USER_CONFIG (
    "%CMDER_ROOT%\vendor\clink\clink_x%architecture%.exe" inject --quiet --profile "%CMDER_USER_CONFIG%" --scripts "%CMDER_ROOT%\vendor"
) else (
    "%CMDER_ROOT%\vendor\clink\clink_x%architecture%.exe" inject --quiet --profile "%CMDER_ROOT%\config" --scripts "%CMDER_ROOT%\vendor"
)

:: Prepare for git-for-windows

:: I do not even know, copypasted from their .bat
set PLINK_PROTOCOL=ssh
if not defined TERM set TERM=cygwin

:: The idea:
:: * if the users points as to a specific git, use that
:: * test if a git is in path and if yes, use that
:: * last, use our vendored git
:: also check that we have a recent enough version of git by examining the version string
if defined GIT_INSTALL_ROOT (
    if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" goto :FOUND_GIT)
)

:: get the version information for vendored git binary
setlocal enabledelayedexpansion
%lib_git% read_version VENDORED "%CMDER_ROOT%\vendor\git-for-windows\cmd"
%lib_git% validate_version VENDORED !GIT_VERSION_VENDORED!

:: check if git is in path...
for /F "delims=" %%F in ('where git.exe 2^>nul') do (
    :: get the absolute path to the user provided git binary
    pushd %%~dpF
    set "test_dir=!CD!"
    popd

    :: get the version information for the user provided git binary
    %lib_git% read_version USER "!test_dir!"
    %lib_git% validate_version USER !GIT_VERSION_USER!

    if !errorlevel! geq 0 (
        :: compare the user git version against the vendored version
        %lib_git% compare_versions USER VENDORED

        :: use the user provided git if its version is greater than, or equal to the vendored git
        if !errorlevel! geq 0 if exist "!test_dir:~0,-4!\cmd\git.exe" (
            set "GIT_INSTALL_ROOT=!test_dir:~0,-4!"
            set test_dir=
            goto :FOUND_GIT
        ) else if !errorlevel! geq 0 (
            set "GIT_INSTALL_ROOT=!test_dir!"
            set test_dir=
            goto :FOUND_GIT
        ) else (
            call :verbose-output Found old !GIT_VERSION_USER! in "!test_dir!", but not using...
            set test_dir=
        )
    ) else (

        :: if the user provided git executable is not found
        if !errorlevel! equ -255 (
            call :verbose-output No git at "!git_executable!" found.
            set test_dir=
        )

    )

)

:: our last hope: our own git...
:VENDORED_GIT
if exist "%CMDER_ROOT%\vendor\git-for-windows" (
    set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
    %lib_path% enhance_path "!GIT_INSTALL_ROOT!\cmd"
) else (
    goto :NO_GIT
)

:FOUND_GIT
:: Add git to the path
if defined GIT_INSTALL_ROOT (
    rem add the unix commands at the end to not shadow windows commands like more
    if exist "!GIT_INSTALL_ROOT!\cmd\git.exe" %lib_path% enhance_path "!GIT_INSTALL_ROOT!\cmd" append
    if exist "!GIT_INSTALL_ROOT!\mingw32" (
        %lib_path% enhance_path "!GIT_INSTALL_ROOT!\mingw32" append
    ) else if exist "!GIT_INSTALL_ROOT!\mingw64" (
        %lib_path% enhance_path "!GIT_INSTALL_ROOT!\mingw64" append
    )
    %lib_path% enhance_path "%GIT_INSTALL_ROOT%\usr\bin" append

    :: define SVN_SSH so we can use git svn with ssh svn repositories
    if not defined SVN_SSH set "SVN_SSH=%GIT_INSTALL_ROOT:\=\\%\\bin\\ssh.exe"
)

:NO_GIT
endlocal & set "PATH=%PATH%" & set "SVN_SSH=%SVN_SSH%" & set "GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%"
%lib_console% debug-output init.bat "Env Var - GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%"

:: Enhance Path
%lib_path% enhance_path_recursive "%CMDER_ROOT%\bin" %max_depth%
if defined CMDER_USER_BIN (
  %lib_path% enhance_path_recursive "%CMDER_USER_BIN%" %max_depth%
)
%lib_path% enhance_path "%CMDER_ROOT%" append

:: Drop *.bat and *.cmd files into "%CMDER_ROOT%\config\profile.d"
:: to run them at startup.
%lib_profile% run_profile_d "%CMDER_ROOT%\config\profile.d"
if defined CMDER_USER_CONFIG (
  %lib_profile% run_profile_d "%CMDER_USER_CONFIG%\profile.d"
)

:: Allows user to override default aliases store using profile.d
:: scripts run above by setting the 'aliases' env variable.
::
:: Note: If overriding default aliases store file the aliases
:: must also be self executing, see '.\user-aliases.cmd.example',
:: and be in profile.d folder.
if not defined user-aliases (
  if defined CMDER_USER_CONFIG (
     set "user-aliases=%CMDER_USER_CONFIG%\user-aliases.cmd"
  ) else (
     set "user-aliases=%CMDER_ROOT%\config\user-aliases.cmd"
  )
)

:: The aliases environment variable is used by alias.bat to id
:: the default file to store new aliases in.
if not defined aliases (
  set "aliases=%user-aliases%"
)

:: Make sure we have a self-extracting user-aliases.cmd file
setlocal enabledelayedexpansion
if not exist "%user-aliases%" (
    echo Creating initial user-aliases store in "%user-aliases%"...
    copy "%CMDER_ROOT%\vendor\user-aliases.cmd.example" "%user-aliases%"
) else (
    type "%user-aliases%" | findstr /i ";= Add aliases below here" >nul
    if "!errorlevel!" == "1" (
        echo Creating initial user-aliases store in "%user-aliases%"...
        if defined CMDER_USER_CONFIG (
            copy "%user-aliases%" "%user-aliases%.old_format"
            copy "%CMDER_ROOT%\vendor\user-aliases.cmd.example" "%user-aliases%"
        ) else (
            copy "%user-aliases%" "%user-aliases%.old_format"
            copy "%CMDER_ROOT%\vendor\user-aliases.cmd.example" "%user-aliases%"
        )
    )
)

:: Update old 'user-aliases' to new self executing 'user-aliases.cmd'
if exist "%CMDER_ROOT%\config\aliases" (
  echo Updating old "%CMDER_ROOT%\config\aliases" to new format...
  type "%CMDER_ROOT%\config\aliases" >> "%user-aliases%" && del "%CMDER_ROOT%\config\aliases"
) else if exist "%user-aliases%.old_format" (
  echo Updating old "%user-aliases%" to new format...
  type "%user-aliases%.old_format" >> "%user-aliases%" && del "%user-aliases%.old_format"
)
endlocal

:: Add aliases to the environment
call "%user-aliases%"

:: See vendor\git-for-windows\README.portable for why we do this
:: Basically we need to execute this post-install.bat because we are
:: manually extracting the archive rather than executing the 7z sfx
if exist "%GIT_INSTALL_ROOT%\post-install.bat" (
    %lib_console% verbose-output "Running Git for Windows one time Post Install...."
    pushd "%GIT_INSTALL_ROOT%\"
    "%GIT_INSTALL_ROOT%\git-bash.exe" --no-needs-console --hide --no-cd --command=post-install.bat
    popd
)

:: Set home path
if not defined HOME set "HOME=%USERPROFILE%"
%lib_console% debug-output init.bat "Env Var - HOME=%HOME%"

set "initialConfig=%CMDER_ROOT%\config\user-profile.cmd"
if exist "%CMDER_ROOT%\config\user-profile.cmd" (
    REM Create this file and place your own command in there
    call "%CMDER_ROOT%\config\user-profile.cmd" %CMDER_FLAGS%
)

if defined CMDER_USER_CONFIG (
  set "initialConfig=%CMDER_USER_CONFIG%\user-profile.cmd"
  if exist "%CMDER_USER_CONFIG%\user-profile.cmd" (
      REM Create this file and place your own command in there
      call "%CMDER_USER_CONFIG%\user-profile.cmd" %CMDER_FLAGS%
  )
)

if not exist "%initialConfig%" (
    echo Creating user startup file: "%initialConfig%"
    (
echo :: use this file to run your own startup commands
echo :: use  in front of the command to prevent printing the command
echo.
echo :: uncomment this to have the ssh agent load when cmder starts
echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd"
echo.
echo :: uncomment this next two lines to use pageant as the ssh authentication agent
echo :: SET SSH_AUTH_SOCK=/tmp/.ssh-pageant-auth-sock
echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-pageant.cmd"
echo.
echo :: you can add your plugins to the cmder path like so
echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%"
echo.
echo :: pass your custom arguments to init.bat, and you can parse them like so
echo :: echo %* | find /i "/noautorun">nul
echo :: if "%ERRORLEVEL%" == "1" (
echo ::   call vsCode
echo :: )
echo.
echo @echo off
) >"%initialConfig%"
)

set initialConfig=
exit /b

fix conflict with init.bat build-in command parser, update user-profile.cmd


@echo off
rem Enables Hyper-V on non-Win 10 Pro and up
rem Run systeminfo command before running this file and verify that under Hyper-V Requirements:
rem 1) VM Monitor Mode Extensions: Yes
rem 2) Virtualization Enabled In Firmware: Yes
rem 3) Second Level Address Translation: Yes
rem 4) Data Execution Prevention Available: Yes
rem Once all of those say yes, run this file as Administrator
rem Original sources: https://pastebin.com/cX6nupy4 and https://github.com/MicrosoftDocs/Virtualization-Documentation/issues/915

pushd "%~dp0"

dir /b %SystemRoot%\servicing\Packages\*Hyper-V*.mum >hyper-v.txt

for /f %%i in ('findstr /i . hyper-v.txt 2^>nul') do dism /online /norestart /add-package:"%SystemRoot%\servicing\Packages\%%i"

del hyper-v.txt

Dism /online /enable-feature /featurename:Microsoft-Hyper-V-All /LimitAccess /ALL

add enable hyper-v script

add enable hyper-v script


@ECHO OFF
TITLE ghacks user.js updater

REM ### ghacks-user.js updater for Windows
REM ## author: @claustromaniac
REM ## version: 3.0

SET _myname=%~n0
SET _myparams=%*
SETLOCAL EnableDelayedExpansion
:parse
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
)
IF /I "%~1"=="-merge" (
	SET _merge=1
)
IF /I "%~1"=="-updatebatch" (
	SET _updateb=1
)
SHIFT
GOTO parse
:endparse
ECHO.
IF DEFINED _updateb (
	IF NOT "!_myname:~0,9!"=="[updated]" (
		ECHO Checking updater version...
		ECHO.
		DEL /F "[updated]!_myname!.bat" 2>nul
		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.
			PING -n 301 127.0.0.1>nul
			EXIT /B
		)
	) ELSE (
		IF EXIST "!_myname:~9!.bat" (
			DEL /F "!_myname:~9!.bat"
			CALL :begin
			REN "!_myname!.bat" "!_myname:~9!.bat"
			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.
			PING -n 301 127.0.0.1>nul
			EXIT /B
		)
	)
)
:begin
SET /A "_line=0"
IF NOT EXIST user.js (
	ECHO user.js not detected in the current directory.
) ELSE (
	FOR /F "skip=1 tokens=1,2 delims=:" %%G IN (user.js) DO (
		SET /A "_line+=1"
		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
		)
	)
	:exitloop
	IF !_line! GEQ 4 (
		IF /I NOT "!_name!"=="!_name:ghacks=X!" (
			ECHO ghacks user.js !_version:~2!,!_date!
		) ELSE (
			ECHO Current user.js version not recognised.
		)
	) ELSE (
		ECHO Current user.js version not recognised.
	)
)
ECHO.
IF NOT DEFINED _ua (
	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.
	ECHO.
	REM ECHO Visit the wiki for more detailed information.
	REM ECHO.
	CHOICE /M "Continue"
	IF ERRORLEVEL 2 EXIT /B
)
CLS
ECHO.
IF DEFINED _log (
	CALL :log >>user.js-update-log.txt 2>&1
	IF DEFINED _logp (
		START user.js-update-log.txt
	)
	EXIT /B
	:log
	ECHO ##################################################################
	ECHO.
	ECHO %date%, %time%
	ECHO.
)
IF EXIST user.js (
	IF EXIST user.js.bak REN user.js.bak user.js.old.bak
	REN user.js user.js.bak
	ECHO Current user.js file backed up.
	ECHO.
)
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 2>&1
ECHO.
IF EXIST user.js (
	IF DEFINED _multi (
		ECHO Multiple overrides enabled. List of files found:
		FORFILES /P user.js-overrides /M *.js
		IF %ERRORLEVEL% EQU 0 (
			IF DEFINED _merge (
				ECHO.
				ECHO Merging...
				ECHO.
				COPY /B /V /Y user.js-overrides\*.js user-overrides
				CALL :merge user-overrides user-overrides-merged.js
				COPY /B /V /Y user.js+user-overrides-merged.js updatertempfile
				CALL :merge updatertempfile user.js
			) ELSE (
				ECHO.
				ECHO Appending...
				ECHO.
				COPY /B /V /Y user.js+"user.js-overrides\*.js" user.js
			)
		)
		ECHO.
	) ELSE (
		IF EXIST "user-overrides.js" (
			IF DEFINED _merge (
				ECHO Merging user-overrides.js...
				COPY /B /V /Y user.js+user-overrides.js updatertempfile
				CALL :merge updatertempfile user.js
			) ELSE (
				ECHO Appending user-overrides.js...
				ECHO.
				COPY /B /V /Y user.js+"user-overrides.js" "user.js"
			)
		) ELSE (
			ECHO user-overrides.js not found.
		)
		ECHO.
	)
	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
			ECHO Update completed without changes.
		) ELSE (
			ECHO Update complete.
		)
	)
	ECHO.
) ELSE (
	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
	ECHO.
	ECHO Update failed. Make sure PowerShell is allowed internet access.
	ECHO.
	ECHO No changes were made.
	ECHO.
)
IF NOT DEFINED _log (
	IF NOT DEFINED _ua PAUSE
)
EXIT /B

REM ###### Merge function ######
:merge
DEL /F %2 2>nul
SETLOCAL disabledelayedexpansion
FOR /F "tokens=1,* delims=]" %%G IN ('find /n /v "" ^< "%~1"') DO (
	SET "_pref=%%H"
	SETLOCAL enabledelayedexpansion
	SET "_temp=!_pref: =!"
	IF /I "user_pref"=="!_temp:~0,9!" (
		IF /I NOT "user.js.parrot"=="!_temp:~12,14!" (
			FOR /F "delims=," %%S IN ("!_pref!") DO (
				SET "_pref=%%S"
			)
			SET _pref=!_pref:"=""!
			FIND /I "!_pref!" %~2 >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!>>%~2
			)
		) ELSE (
			ECHO(!_pref!>>%~2
		)
	) ELSE (
		ECHO(!_pref!>>%~2
	)
	ENDLOCAL
)
ENDLOCAL
DEL /F %1 >nul
GOTO :EOF
REM ############################

@ECHO OFF
TITLE ghacks user.js updater

REM ### ghacks-user.js updater for Windows
REM ## author: @claustromaniac
REM ## version: 3.0

SET _myname=%~n0
SET _myparams=%*
SETLOCAL EnableDelayedExpansion
:parse
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
)
IF /I "%~1"=="-merge" (
	SET _merge=1
)
IF /I "%~1"=="-updatebatch" (
	SET _updateb=1
)
SHIFT
GOTO parse
:endparse
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" (
			DEL /F "!_myname:~9!.bat"
			CALL :begin
			REN "!_myname!.bat" "!_myname:~9!.bat"
			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"
IF NOT EXIST user.js (
	ECHO user.js not detected in the current directory.
) ELSE (
	FOR /F "skip=1 tokens=1,2 delims=:" %%G IN (user.js) DO (
		SET /A "_line+=1"
		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
		)
	)
	:exitloop
	IF !_line! GEQ 4 (
		IF /I NOT "!_name!"=="!_name:ghacks=X!" (
			ECHO ghacks user.js !_version:~2!,!_date!
		) ELSE (
			ECHO Current user.js version not recognised.
		)
	) ELSE (
		ECHO Current user.js version not recognised.
	)
)
ECHO.
IF NOT DEFINED _ua (
	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.
	ECHO.
	REM ECHO Visit the wiki for more detailed information.
	REM ECHO.
	CHOICE /M "Continue"
	IF ERRORLEVEL 2 EXIT /B
)
CLS
ECHO.
IF DEFINED _log (
	CALL :log >>user.js-update-log.txt 2>&1
	IF DEFINED _logp (
		START user.js-update-log.txt
	)
	EXIT /B
	:log
	ECHO ##################################################################
	ECHO.
	ECHO %date%, %time%
	ECHO.
)
IF EXIST user.js (
	IF EXIST user.js.bak REN user.js.bak user.js.old.bak
	REN user.js user.js.bak
	ECHO Current user.js file backed up.
	ECHO.
)
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 2>&1
ECHO.
IF EXIST user.js (
	IF DEFINED _multi (
		ECHO Multiple overrides enabled. List of files found:
		FORFILES /P user.js-overrides /M *.js
		IF %ERRORLEVEL% EQU 0 (
			IF DEFINED _merge (
				ECHO.
				ECHO Merging...
				ECHO.
				COPY /B /V /Y user.js-overrides\*.js user-overrides
				CALL :merge user-overrides user-overrides-merged.js
				COPY /B /V /Y user.js+user-overrides-merged.js updatertempfile
				CALL :merge updatertempfile user.js
			) ELSE (
				ECHO.
				ECHO Appending...
				ECHO.
				COPY /B /V /Y user.js+"user.js-overrides\*.js" user.js
			)
		)
		ECHO.
	) ELSE (
		IF EXIST "user-overrides.js" (
			IF DEFINED _merge (
				ECHO Merging user-overrides.js...
				COPY /B /V /Y user.js+user-overrides.js updatertempfile
				CALL :merge updatertempfile user.js
			) ELSE (
				ECHO Appending user-overrides.js...
				ECHO.
				COPY /B /V /Y user.js+"user-overrides.js" "user.js"
			)
		) ELSE (
			ECHO user-overrides.js not found.
		)
		ECHO.
	)
	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
			ECHO Update completed without changes.
		) ELSE (
			ECHO Update complete.
		)
	)
	ECHO.
) ELSE (
	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
	ECHO.
	ECHO Update failed. Make sure PowerShell is allowed internet access.
	ECHO.
	ECHO No changes were made.
	ECHO.
)
IF NOT DEFINED _log (
	IF NOT DEFINED _ua PAUSE
)
EXIT /B

REM ###### Merge function ######
:merge
DEL /F %2 2>nul
SETLOCAL disabledelayedexpansion
FOR /F "tokens=1,* delims=]" %%G IN ('find /n /v "" ^< "%~1"') DO (
	SET "_pref=%%H"
	SETLOCAL enabledelayedexpansion
	SET "_temp=!_pref: =!"
	IF /I "user_pref"=="!_temp:~0,9!" (
		IF /I NOT "user.js.parrot"=="!_temp:~12,14!" (
			FOR /F "delims=," %%S IN ("!_pref!") DO (
				SET "_pref=%%S"
			)
			SET _pref=!_pref:"=""!
			FIND /I "!_pref!" %~2 >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!>>%~2
			)
		) ELSE (
			ECHO(!_pref!>>%~2
		)
	) ELSE (
		ECHO(!_pref!>>%~2
	)
	ENDLOCAL
)
ENDLOCAL
DEL /F %1 >nul
GOTO :EOF
REM ############################

Replace PING with TIMEOUT

Replace PING with TIMEOUT

Otherwise earthing's nosy firewall bitches about it.


:: MSBuild.exe %*

@echo off
setlocal
:: cd /d %~dp0

set PF32=%ProgramFiles(x86)%
if not exist "%PF32%" set PF32=%ProgramFiles%

set VsWherePath="%PF32%\Microsoft Visual Studio\Installer\vswhere.exe"

:: vs2019 or later
for /f "usebackq tokens=*" %%i in (`%VsWherePath% -latest -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe`) do (
    if exist "%%i" (
        set MSBuildPath="%%i"
        goto :run
    )
)

:: vs2017 or earlier
for /f "usebackq tokens=1* delims=: " %%i in (`%VsWherePath% -latest -requires Microsoft.Component.MSBuild`) do (
    if /i "%%i"=="installationPath" (
        if exist "%%j\MSBuild\15.0\Bin\MSBuild.exe" (
            set MSBuildPath="%%j\MSBuild\15.0\Bin\MSBuild.exe"
            goto :run
        )
        if exist "%%j\MSBuild\14.0\Bin\MSBuild.exe" (
            set MSBuildPath="%%j\MSBuild\14.0\Bin\MSBuild.exe"
            goto :run
        )
        if exist "%%j\MSBuild\12.0\Bin\MSBuild.exe" (
            set MSBuildPath="%%j\MSBuild\12.0\Bin\MSBuild.exe"
            goto :run
        )
    )
)

:run
if not exist %MSBuildPath% (
    echo "MSBuild.exe not find"
    exit /b 1
)

echo on
%MSBuildPath% %*

Add MSBuild.bat

Add MSBuild.bat


@echo off
setlocal

%TB-PLATFORM-PROJECTS-DRIVE%
path %TB-PLATFORM-PROJECTS-DRIVE%%TB-PLATFORM-PROJECTS-PATH%\Build\Subscripts;%PATH%

set BIN-PATH=%TB-PLATFORM-PROJECTS-PATH%\Bin

call setMyVersion.bat

set DEP=/DEP:%TB-PLATFORM-PROJECTS-DRIVE%%TB-PLATFORM-PROJECTS-PATH%\Build\ExternalDependencies.txt

if "%~1" == "V" (
	set SET_VERSION=/V
) else if not "%~1"=="" (
	if "%2" == "V" set SET_VERSION=/V
	pushd %TB-PLATFORM-PROJECTS-PATH%\src\CommandLineUtils
	echo =================================
	echo Making command line utility project %~1
	call makeExe.bat %~1 %~1 /CONSOLE /NOV6CC /M:E %DEP% /V
	popd
	exit /B
)

echo =================================
echo Making command line utility projects

pushd %TB-PLATFORM-PROJECTS-PATH%\src\CommandLineUtils

call makeExe.bat gbd gbd /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

call makeExe.bat gccd gccd /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

call makeExe.bat gcd gcd /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

call makeExe.bat gsd gsd /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

call makeExe.bat gtd gtd /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

call makeExe.bat gxd gxd /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

call makeExe.bat ltz ltz /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

call makeExe.bat plord plord /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

call makeExe.bat uccd uccd /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

call makeExe.bat ucd ucd /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

call makeExe.bat uxd uxd /CONSOLE /NOV6CC /M:E %DEP% /V
if errorlevel 1 pause

:: temporary solution to building the Chart program
pushd Chart
msbuild Chart.sln -t:Rebuild -p:Configuration=Debug -verbosity:m
if errorlevel 1 pause
popd

popd

@echo off
setlocal

%TB-PLATFORM-PROJECTS-DRIVE%
path %TB-PLATFORM-PROJECTS-DRIVE%%TB-PLATFORM-PROJECTS-PATH%\Build\Subscripts;%PATH%

set BIN-PATH=%TB-PLATFORM-PROJECTS-PATH%\Bin

call setMyVersion.bat

set DEP=/DEP:%TB-PLATFORM-PROJECTS-DRIVE%%TB-PLATFORM-PROJECTS-PATH%\Build\ExternalDependencies.txt

if not "%~1"=="" (
	pushd %TB-PLATFORM-PROJECTS-PATH%\src\CommandLineUtils
	echo =================================
	echo Making command line utility project %~1
	call makeExe.bat %~1 %~1 /CONSOLE /NOV6CC /M:E %DEP%
	popd
	exit /B
)

echo =================================
echo Making command line utility projects

pushd %TB-PLATFORM-PROJECTS-PATH%\src\CommandLineUtils

call makeExe.bat gbd gbd /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

call makeExe.bat gccd gccd /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

call makeExe.bat gcd gcd /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

call makeExe.bat gsd gsd /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

call makeExe.bat gtd gtd /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

call makeExe.bat gxd gxd /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

call makeExe.bat ltz ltz /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

call makeExe.bat plord plord /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

call makeExe.bat uccd uccd /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

call makeExe.bat ucd ucd /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

call makeExe.bat uxd uxd /CONSOLE /NOV6CC /M:E %DEP%
if errorlevel 1 pause

:: temporary solution to building the Chart program
pushd Chart
echo =================================
echo Building Chart\Chart.exe
msbuild Chart.sln -t:Rebuild -p:Configuration=Debug -verbosity:m
if errorlevel 1 pause
popd

popd

Fix command line tool build file

Fix command line tool build file


@echo off
title Dotfiles installation script

rem Start program ----------------------------------------------------------
:init
  set source=%~dp0
  goto check_permissions

rem Check administrator permissions ----------------------------------------
:check_permissions
  echo Administrative permissions required. Detecting permissions...
  net session >nul 2>&1

  if %errorLevel% == 0 (
    echo Success: Administrative permissions confirmed.
    echo.
    goto select_links
  ) else (
    echo Requesting administrative privileges...
    goto UAC_prompt
  )

rem Show admin prompt ------------------------------------------------------
:UAC_prompt
  echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  set params=%~1
  echo UAC.ShellExecute "%~s0", "%params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

  "%temp%\getadmin.vbs" >nul
  if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
  exit /B

rem Select what to link ----------------------------------------------------
:select_links
  if "%~1"=="" (
    echo Please select what you want to do:
    echo 1. Link vim files
    echo 2. Link vimperator files
    echo 3. Link all files
    echo.

    set /p choose=
    echo.
  ) else (
    set choose=%~1
  )

  if "%choose%" == "1" ( goto link_vim )
  if "%choose%" == "2" ( goto link_vimp )
  if "%choose%" == "3" ( goto link_vim )

  if "%choose%" == "vim" ( goto link_vim )
  if "%choose%" == "vimp" ( goto link_vimp )
  if "%choose%" == "all" (
    set choose=3
    goto link_vim
  )

  goto error

rem Link vim files ---------------------------------------------------------
:link_vim
  rem Go to home directory
  cd %USERPROFILE%

  echo Linking vim files...
  echo.

  if exist vimfiles (
    echo vimfiles folder already exists. Skipping to next file.
  ) else (
    mklink /D vimfiles %source%vim
  )

  if "%choose%" == "3" (
    echo.
    goto link_vimp
  )

  if %errorLevel% == 0 (
    goto success
  ) else (
    goto error
  )

rem Link vimperator files --------------------------------------------------
:link_vimp
  rem Go to home directory
  cd %USERPROFILE%

  echo Linking vimperator files...
  echo.

  if exist vimperator (
    echo vimperator folder already exists. Skipping to next file.
  ) else (
    mklink /D vimperator %source%vimperator
  )
  if exist _vimperatorrc (
    echo _vimperatorrc file already exists. Skipping to next file.
  ) else (
    mklink _vimperatorrc %source%vimperator\vimperatorrc
  )

  if %errorLevel% == 0 (
    goto success
  ) else (
    goto error
  )

rem End program ------------------------------------------------------------
:error
  echo.
  echo Error: Something went wrong.
  goto end

:success
  echo.
  echo Success: All files liked correctly.
  goto end

:end
  pause >nul
  cls
  exit /B

@echo off
title Dotfiles installation script

rem Start program ---------------------------------------------------------
:init
  set location=%~dp0
  goto check_permissions

rem Check administrator permissions ---------------------------------------
:check_permissions
  echo Administrative permissions required. Detecting permissions...
  net session >nul 2>&1

  if %errorLevel% == 0 (
    echo Success: Administrative permissions confirmed.
    echo.
    goto select_links
  ) else (
    echo Requesting administrative privileges...
    goto UAC_prompt
  )

rem Show admin prompt -----------------------------------------------------
:UAC_prompt
  echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  set params=%~1
  echo UAC.ShellExecute "%~s0", "%params%", "", "runas", 1 >> "%temp%\getadmin.vbs"

  "%temp%\getadmin.vbs" >nul
  if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
  exit /B

rem Select what to link ---------------------------------------------------
:select_links
  if "%~1"=="" (
    echo Please select what you want to do:
    echo 1. Link vim files
    echo 2. Link vimperator files
    echo 3. Link all files
    echo 4. Create pathrc file
    echo.

    set /p choose=
    echo.
  ) else (
    set choose=%~1
  )

  if "%choose%" == "1" ( goto link_vim )
  if "%choose%" == "2" ( goto link_vimp )
  if "%choose%" == "3" ( goto link_vimp )
  if "%choose%" == "4" ( goto create_pathrc )

  if "%choose%" == "vim" ( goto link_vim )
  if "%choose%" == "vimp" ( goto link_vimp )
  if "%choose%" == "pathrc" ( goto create_pathrc )
  if "%choose%" == "all" (
    set choose=3
    goto link_vimp
  )

  goto error

rem Link vimperator files -------------------------------------------------
:link_vimp
  rem Go to home directory
  cd %USERPROFILE%

  echo Linking vimperator files...
  echo.

  if exist vimperator (
    echo vimperator folder already exists. Skipping to next file.
  ) else (
    mklink /D vimperator %location%vimperator
  )
  if exist _vimperatorrc (
    echo _vimperatorrc file already exists. Skipping to next file.
  ) else (
    mklink _vimperatorrc %location%vimperator\vimperatorrc
  )

  if "%choose%" == "3" (
    echo.
    goto link_vim
  )

  if %errorLevel% == 0 (
    goto success
  ) else (
    goto error
  )

rem Link vim files --------------------------------------------------------
:link_vim
  rem Go to home directory
  cd %USERPROFILE%

  echo Linking vim files...
  echo.

  if exist vimfiles (
    echo vimfiles folder already exists. Skipping to next file.
  ) else (
    mklink /D vimfiles %location%vim
  )

  goto create_pathrc

rem Create pathrc file ----------------------------------------------------
:create_pathrc
  echo.
  echo Creating pathrc file...
  rem Variables

  set file=%location%vim\pathrc.vim

  set vimrc=%location%vim\vimrc
  set vimprc=%location%vimperator\vimperatorrc
  set color=%location%vim\colors\customized.vim
  set bundle=%location%vim\bundle\

  rem Target content

  >%file% echo ^" File containing all path specific options

  >>%file% echo.
  >>%file% echo ^" Vundle paths ------------------------------------------------------------

  >>%file% echo.
  >>%file% echo set rtp+=%bundle%vundle
  >>%file% echo call vundle#rc('%bundle%')

  >>%file% echo.
  >>%file% echo ^" Mappings ----------------------------------------------------------------

  >>%file% echo.
  >>%file% echo ^" Open vimrc mapping
  >>%file% echo nnoremap ^<leader^>vv :split %vimrc%^<CR^>

  >>%file% echo.
  >>%file% echo ^" Open vimperatorrc mapping
  >>%file% echo nnoremap ^<leader^>vp :split %vimprc%^<CR^>

  >>%file% echo.
  >>%file% echo ^" Open customized colorscheme mapping
  >>%file% echo nnoremap ^<leader^>vt :split %color%^<CR^>

  if %errorLevel% == 0 (
    goto success
  ) else (
    goto error
  )

rem End program -----------------------------------------------------------
:error
  echo.
  echo Error: Something went wrong.
  goto end

:success
  echo.
  echo Success: Everything finished.
  goto end

:end
  pause >nul
  cls
  exit /B

Add option to create pathrc file

Add option to create pathrc file


rem ensures conda is installed and installs gdsfactory package
rem https://gist.github.com/nimaid/a7d6d793f2eba4020135208a57f5c532
@echo off

set ORIGDIR="%CD%"

set MINICONDAPATH=%USERPROFILE%\Miniconda3
set CONDAEXE=%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%-condainstall.exe
set "OS="
set "MCLINK="

where conda >nul 2>nul
if %ERRORLEVEL% EQU 0 goto CONDAFOUND

:INSTALLCONDA
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
if %OS%==32BIT set MCLINK=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86.exe
if %OS%==64BIT set MCLINK=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe

echo Downloading Miniconda3 (This will take while, please wait)...
powershell -Command "(New-Object Net.WebClient).DownloadFile('%MCLINK%', '%CONDAEXE%')" >nul 2>nul
if errorlevel 1 goto CONDAERROR

echo Installing Miniconda3 (This will also take a while, please wait)...
start /wait /min "Installing Miniconda3..." "%CONDAEXE%" /InstallationType=JustMe /S /D="%MINICONDAPATH%"
del "%CONDAEXE%"
if not exist "%MINICONDAPATH%\" (goto CONDAERROR)

"%MINICONDAPATH%\Scripts\conda.exe" init
if errorlevel 1 goto CONDAERROR

echo Miniconda3 has been installed!
goto END

:CONDAERROR
echo Miniconda3 install failed!
exit /B 1

:CONDAFOUND
echo Conda is already installed!

rem https://gist.github.com/maximlt/531419545b039fa33f8845e5bc92edd6
call conda create -f environment.yml
call conda activate gdsfactory

git clone https://github.com/gdsfactory/gdslib.git -b data
pre-commit install
gf tool install

:END
exit /B 0

rem ensures conda is installed and installs gdsfactory package
rem https://gist.github.com/nimaid/a7d6d793f2eba4020135208a57f5c532
@echo off

set ORIGDIR="%CD%"

set MINICONDAPATH=%USERPROFILE%\Miniconda3
set CONDAEXE=%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%-condainstall.exe
set "OS="
set "MCLINK="

where conda >nul 2>nul
if %ERRORLEVEL% EQU 0 goto CONDAFOUND

:INSTALLCONDA
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
if %OS%==32BIT set MCLINK=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86.exe
if %OS%==64BIT set MCLINK=https://repo.anaconda.com/miniconda/Miniconda3-latest-Windows-x86_64.exe

echo Downloading Miniconda3 (This will take while, please wait)...
powershell -Command "(New-Object Net.WebClient).DownloadFile('%MCLINK%', '%CONDAEXE%')" >nul 2>nul
if errorlevel 1 goto CONDAERROR

echo Installing Miniconda3 (This will also take a while, please wait)...
start /wait /min "Installing Miniconda3..." "%CONDAEXE%" /InstallationType=JustMe /S /D="%MINICONDAPATH%"
del "%CONDAEXE%"
if not exist "%MINICONDAPATH%\" (goto CONDAERROR)

"%MINICONDAPATH%\Scripts\conda.exe" init
if errorlevel 1 goto CONDAERROR

echo Miniconda3 has been installed!

:CONDAFOUND
echo Conda is already installed!

rem https://gist.github.com/maximlt/531419545b039fa33f8845e5bc92edd6
call conda create -f environment.yml
call conda activate gdsfactory

git clone https://github.com/gdsfactory/gdslib.git -b data
pre-commit install
gf tool install

:END
exit /B 0

:CONDAERROR
echo Miniconda3 install failed!
exit /B 1

fix install.bat

fix install.bat


@ECHO OFF
:: don't leak env variables into the calling interpreter...
setlocal
:: better defaults for dealing with quotes...
:: You need to escape ! afterwards with ^^! or "^!"
SETLOCAL enabledelayedexpansion

:: A comment on quotes around file path variables:
:: only add quotes around the variable when you use the variable
:: as a file path (exists, type, pipe,...) and the parenthesis of a
:: for, not when used as a string (-> setting variables)

:: more does not work if the codepage is set to unicode 65001
for /F "tokens=*" %%F in ('chcp') do (
    for %%A in (%%F) do (set _last=%%A)
)
SET CP=%_last:~0%
if "!CP:~-1!"=="." (
    SET CP=!CP:~0,-1!
)
chcp 850 > NUL
:: echo %CP%

:: not so sane default...
SET PREFIX=C:\SCM\PortableGit\mingw64

:: find a git.exe in path and use that as a default dir
where /Q git.exe
if errorlevel 1 goto :defaultpath

for /F "delims=" %%F in ('where git.exe') do (
    set bindir=%%~dpF
    rem break after the first, so that we get the first in path
    goto :break
)
goto :defaultpath

:break
rem remove the last slash
SET bindir=%bindir:~0,-1%
for %%G in ("%bindir%") do set installdir=%%~dpG
set PREFIX=%installdir%mingw64
goto :foundprefix

:defaultpath
:: default for Git for Windows 2.x
if exist "%ProgramFiles%\Git" (
    set PREFIX=%ProgramFiles%\Git\mingw64
)

:foundprefix
:: overwrite with whatever the user supplied...
IF NOT "%~1"=="" (
    REM make it easier for the user to specify a prefix:
    REM just supplying the git dir is enough...
    if exist "%~1\mingw64" (
        set PREFIX=%~1\mingw64
    ) else (
        echo Using git install path "%~1" as PREFIX, please make sure it's really a
        echo path to the mingw64 directory...
        echo.
        SET PREFIX=%~1
    )
)
:: remove a trailing slash, but only after removing quotes...
set PREFIX=!PREFIX:"=!
IF %PREFIX:~-1%==\ SET PREFIX=%PREFIX:~0,-1%

for %%H in ("%PREFIX%") do set GIT_INSTALL_DIR=%%~dpH

set GIT_INSTALL_DIR=!GIT_INSTALL_DIR:"=!
IF %GIT_INSTALL_DIR:~-1%==\ SET GIT_INSTALL_DIR=%GIT_INSTALL_DIR:~0,-1%

if not exist "%GIT_INSTALL_DIR%\mingw64" (
    echo No mingw64 folder found in %GIT_INSTALL_DIR%.
    echo.
    echo Please supply a proper "Git for Windows 2.x" install path:
    echo "install.cmd c:\[git-install-path]"
    set ERROR=1
    goto :exit
)

echo Installing to %PREFIX%
SET HTMLDIR=%PREFIX%\share\doc\git-doc
SET GITEXTRAS=%~dp0

IF NOT EXIST "%PREFIX%\bin" MKDIR "%PREFIX%\bin"

:: Check that we can install into that dir or need admin rights...
set _testfile=%PREFIX%\bin\testfile_to_check_if_dir_is_writeable-577423947123.~
copy NUL "%_testfile%" >NUL 2>&1
IF EXIST "%_testfile%" (
    set IS_WRITEABLE=yes
    del "%_testfile%"
) else (
    set IS_WRITEABLE=no
)
if "%IS_WRITEABLE%"=="no" (
    echo.
    echo Directory for binaries ["%PREFIX%\bin"] is not writeable by install.cmd.
    echo.
    echo You probably need to run install.cmd from an admin prompt.
    set ERROR=1
    goto :exit
)

SET COMMANDS_WITHOUT_REPO=git-alias git-extras git-fork git-setup

echo Installing binaries...
FOR /R "%GITEXTRAS%\bin" %%i in (*.*) DO (
    IF "%DEBUG%=="true" ( ECHO "Writing File: %PREFIX%\bin\%%~ni" )

    ECHO #^^!/usr/bin/env bash > "%PREFIX%\bin\%%~ni"
    TYPE "%GITEXTRAS%\helper\reset-env" >> "%PREFIX%\bin\%%~ni"
    TYPE "%GITEXTRAS%\helper\git-extra-utility" >> "%PREFIX%\bin\%%~ni"
    TYPE "%GITEXTRAS%\helper\is-git-repo" >> "%PREFIX%\bin\%%~ni"

    REM Added /E option for installation fix on Windows 10.0.17134 and higher
    MORE /E +2 "%GITEXTRAS%\bin\%%~ni" >> "%PREFIX%\bin\%%~ni"
)

FOR %%i in (%COMMANDS_WITHOUT_REPO%) DO (
    IF "%DEBUG%=="true" ( ECHO "Writing File: %PREFIX%\bin\%%i" )

    ECHO #^^!/usr/bin/env bash > "%PREFIX%\bin\%%i"
    TYPE "%GITEXTRAS%\helper\reset-env" >> "%PREFIX%\bin\%%i"
    TYPE "%GITEXTRAS%\helper\git-extra-utility" >> "%PREFIX%\bin\%%i"

    REM Added /E option for installation fix on Windows 10.0.17134 and higher
    MORE /E +2 "%GITEXTRAS%\bin\%%i" >> "%PREFIX%\bin\%%i"
)

echo Installing man pages...
set _QUIET=/NP /NFL /NDL /NJS /NJH
ROBOCOPY %_QUIET% /IS "%GITEXTRAS%\man" "%HTMLDIR%" *.html
IF %ERRORLEVEL% GTR 7 (
    echo Not all html docs could be copied to "%GITEXTRAS%\man".
    echo.
    echo You probably need to run the install.cmd script from an admin prompt.
    set ERROR=1
    goto :exit
)
echo done

if not exist "%GIT_INSTALL_DIR%\usr\bin\column.exe" (
    where /Q column.exe
    if errorlevel 1 (
        echo.
        echo column.exe is missing: Not in "%GIT_INSTALL_DIR%\usr\bin" or in PATH!
        echo.
        echo "git summary", "git summary-line" and "git ignore-io" do not work without.
        echo If you need these commands, please install Git for Windows > 2.7.0.
        echo.
    )
)

:exit
@chcp %CP% > NUL
@endlocal enabledelayedexpansion
@endlocal
@exit /b %ERROR%

@ECHO OFF
:: don't leak env variables into the calling interpreter...
setlocal
:: better defaults for dealing with quotes...
:: You need to escape ! afterwards with ^^! or "^!"
SETLOCAL enabledelayedexpansion

:: A comment on quotes around file path variables:
:: only add quotes around the variable when you use the variable
:: as a file path (exists, type, pipe,...) and the parenthesis of a
:: for, not when used as a string (-> setting variables)

:: more does not work if the codepage is set to unicode 65001
for /F "tokens=*" %%F in ('chcp') do (
    for %%A in (%%F) do (set _last=%%A)
)
SET CP=%_last:~0%
if "!CP:~-1!"=="." (
    SET CP=!CP:~0,-1!
)
chcp 850 > NUL
:: echo %CP%

:: not so sane default...
SET PREFIX=C:\SCM\PortableGit\mingw64

:: find a git.exe in path and use that as a default dir
where /Q git.exe
if errorlevel 1 goto :defaultpath

for /F "delims=" %%F in ('where git.exe') do (
    set bindir=%%~dpF
    rem break after the first, so that we get the first in path
    goto :break
)
goto :defaultpath

:break
rem remove the last slash
SET bindir=%bindir:~0,-1%
for %%G in ("%bindir%") do set installdir=%%~dpG
set PREFIX=%installdir%mingw64
goto :foundprefix

:defaultpath
:: default for Git for Windows 2.x
if exist "%ProgramFiles%\Git" (
    set PREFIX=%ProgramFiles%\Git\mingw64
)

:foundprefix
:: overwrite with whatever the user supplied...
IF NOT "%~1"=="" (
    REM make it easier for the user to specify a prefix:
    REM just supplying the git dir is enough...
    if exist "%~1\mingw64" (
        set PREFIX=%~1\mingw64
    ) else (
        echo Using git install path "%~1" as PREFIX, please make sure it's really a
        echo path to the mingw64 directory...
        echo.
        SET PREFIX=%~1
    )
)
:: remove a trailing slash, but only after removing quotes...
set PREFIX=!PREFIX:"=!
IF %PREFIX:~-1%==\ SET PREFIX=%PREFIX:~0,-1%

for %%H in ("%PREFIX%") do set GIT_INSTALL_DIR=%%~dpH

set GIT_INSTALL_DIR=!GIT_INSTALL_DIR:"=!
IF %GIT_INSTALL_DIR:~-1%==\ SET GIT_INSTALL_DIR=%GIT_INSTALL_DIR:~0,-1%

if not exist "%GIT_INSTALL_DIR%\mingw64" (
    echo No mingw64 folder found in %GIT_INSTALL_DIR%.
    echo.
    echo Please supply a proper "Git for Windows 2.x" install path:
    echo "install.cmd c:\[git-install-path]"
    set ERROR=1
    goto :exit
)

echo Installing to %PREFIX%
SET HTMLDIR=%PREFIX%\share\doc\git-doc
SET GITEXTRAS=%~dp0

IF NOT EXIST "%PREFIX%\bin" MKDIR "%PREFIX%\bin"

:: Check that we can install into that dir or need admin rights...
set _testfile=%PREFIX%\bin\testfile_to_check_if_dir_is_writeable-577423947123.~
copy NUL "%_testfile%" >NUL 2>&1
IF EXIST "%_testfile%" (
    set IS_WRITEABLE=yes
    del "%_testfile%"
) else (
    set IS_WRITEABLE=no
)
if "%IS_WRITEABLE%"=="no" (
    echo.
    echo Directory for binaries ["%PREFIX%\bin"] is not writeable by install.cmd.
    echo.
    echo You probably need to run install.cmd from an admin prompt.
    set ERROR=1
    goto :exit
)

SET COMMANDS_WITHOUT_REPO=git-alias git-extras git-fork git-setup

echo Installing binaries...
FOR /R "%GITEXTRAS%\bin" %%i in (*.*) DO (
    IF "%DEBUG%"=="true" ( ECHO "Writing File: %PREFIX%\bin\%%~ni" )

    ECHO #^^!/usr/bin/env bash > "%PREFIX%\bin\%%~ni"
    TYPE "%GITEXTRAS%\helper\reset-env" >> "%PREFIX%\bin\%%~ni"
    TYPE "%GITEXTRAS%\helper\git-extra-utility" >> "%PREFIX%\bin\%%~ni"
    TYPE "%GITEXTRAS%\helper\is-git-repo" >> "%PREFIX%\bin\%%~ni"

    REM Added /E option for installation fix on Windows 10.0.17134 and higher
    MORE /E +2 "%GITEXTRAS%\bin\%%~ni" >> "%PREFIX%\bin\%%~ni"
)

FOR %%i in (%COMMANDS_WITHOUT_REPO%) DO (
    IF "%DEBUG%"=="true" ( ECHO "Writing File: %PREFIX%\bin\%%i" )

    ECHO #^^!/usr/bin/env bash > "%PREFIX%\bin\%%i"
    TYPE "%GITEXTRAS%\helper\reset-env" >> "%PREFIX%\bin\%%i"
    TYPE "%GITEXTRAS%\helper\git-extra-utility" >> "%PREFIX%\bin\%%i"

    REM Added /E option for installation fix on Windows 10.0.17134 and higher
    MORE /E +2 "%GITEXTRAS%\bin\%%i" >> "%PREFIX%\bin\%%i"
)

echo Installing man pages...
set _QUIET=/NP /NFL /NDL /NJS /NJH
ROBOCOPY %_QUIET% /IS "%GITEXTRAS%\man" "%HTMLDIR%" *.html
IF %ERRORLEVEL% GTR 7 (
    echo Not all html docs could be copied to "%GITEXTRAS%\man".
    echo.
    echo You probably need to run the install.cmd script from an admin prompt.
    set ERROR=1
    goto :exit
)
echo done

if not exist "%GIT_INSTALL_DIR%\usr\bin\column.exe" (
    where /Q column.exe
    if errorlevel 1 (
        echo.
        echo column.exe is missing: Not in "%GIT_INSTALL_DIR%\usr\bin" or in PATH!
        echo.
        echo "git summary", "git summary-line" and "git ignore-io" do not work without.
        echo If you need these commands, please install Git for Windows > 2.7.0.
        echo.
    )
)

:exit
@chcp %CP% > NUL
@endlocal enabledelayedexpansion
@endlocal
@exit /b %ERROR%

Fix missing double quotes after %DEBUG%

Fix missing double quotes after %DEBUG%


cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%LIBRARY_PREFIX% %SRC_DIR%
if errorlevel 1 exit 1

nmake
if errorlevel 1 exit 1

nmake install
if errorlevel 1 exit 1

Add bld.bat for Windows builds

Add bld.bat for Windows builds


echo off
IF %1.==. GOTO Build
IF %1==clean (
	GOTO Clean
) ELSE (
	GOTO Build
)
:Build
	for /f %%b IN ('msbuildpath.exe') do %%bMSBuild.exe libuv\msvs\libuv.sln
	call "%VS100COMNTOOLS%vsvars32.bat"
	FOR /F %%a IN ('msbuildpath.exe') DO %%aMSBuild.exe webserver.csproj
	"%VCINSTALLDIR%bin\cl.exe" uv_wrap.c /o build/uvwrap.dll libuv/build/Win32/Debug/libuv.lib ws2_32.lib advapi32.lib /link /DLL /EXPORT:uv_init /EXPORT:manos_uv_tcp_t_size /EXPORT:uv_tcp_init /EXPORT:uv_tcp_listen /EXPORT:uv_accept /EXPORT:manos_uv_read_start /EXPORT:uv_run /EXPORT:manos_uv_tcp_bind
GOTO :EOF
:Clean
	rmdir /S /Q build
	rmdir /S /Q libuv\build
	del /Q uv_wrap.obj
GOTO :EOF

echo off
IF %1.==. GOTO Build
IF %1==clean (
	GOTO Clean
) ELSE (
	GOTO Build
)
:Build
	for /f %%b IN ('msbuildpath.exe') do %%bMSBuild.exe libuv\msvs\libuv.sln
	call "%VS100COMNTOOLS%vsvars32.bat"
	FOR /F %%a IN ('msbuildpath.exe') DO %%aMSBuild.exe webserver.csproj
	"%VCINSTALLDIR%bin\cl.exe" uv_wrap.c /o build/uvwrap.dll libuv/build/Win32/Debug/libuv.lib ws2_32.lib advapi32.lib /link /DLL /EXPORT:uv_init /EXPORT:uv_tcp_init /EXPORT:uv_tcp_listen /EXPORT:uv_accept /EXPORT:manos_uv_read_start /EXPORT:uv_run /EXPORT:manos_uv_tcp_bind /EXPORT:manos_uv_tcp_t_create /EXPORT:manos_uv_tcp_t_destroy /EXPORT:manos_uv_write
GOTO :EOF
:Clean
	rmdir /S /Q build
	rmdir /S /Q libuv\build
	del /Q uv_wrap.obj
GOTO :EOF

update win build

update win build


SET "memParams=-Xms2g -Xmx4g"
 rem SET "debugParams=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8080"
 SET debugParams=

java -jar %memParams% %debugParams% target\RF2toRF1Converter.jar -u D:\ -v G:\incoming\SnomedCT_RF2Release_INT_20160131.zip

SET "memParams=-Xms4g -Xmx8g"
rem SET "debugParams=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8080"
SET debugParams=

java -jar %memParams% %debugParams% target\RF2toRF1Converter.jar -u D:\ -v G:\incoming\SnomedCT_RF2Release_INT_20160131.zip

Increase memory for PC startup file

Increase memory for PC startup file


@echo off

rem This is a small script to stitch panorama images produced  by Samsung Gear360
rem Could be adopted to use with other cameras after creating pto file (Hugin
rem template)
rem
rem https://github.com/ultramango/gear360pano

rem http://stackoverflow.com/questions/673523/how-to-measure-execution-time-of-command-in-windows-command-line
set start=%time%
set HUGINPATH=C:\Program Files\Hugin\bin
set HUGINPATH32=C:\Program Files (x86)\Hugin\bin
set GALLERYDIR=html
set GALLERYFILELIST=filelist.txt
rem This is to avoid some weird bug (???) %~dp0 doesn't work in a loop (effect of shift?)
set SCRIPTNAME=%0
set SCRIPTPATH=%~dp0
set OUTTMPNAME=out
set PTOTMPL_SM_C200="%SCRIPTPATH%gear360sm-c200.pto"
set PTOTMPL_SM_R210="%SCRIPTPATH%gear360sm-r210.pto"
set INNAME=
set PTOTMPL=
set OUTDIR=%SCRIPTPATH%html\data
set JPGQUALITY=97
set PTOJPGFILENAME=dummy.jpg
set IGNOREPROCESSED=yes
rem Default temporary directory
set MYTEMPDIR=%TEMP%
rem We define default here
set BLENDPROG=enblend.exe
set MULTIBLENDEXE=multiblend_x64.exe
rem By default use gpu
set EXTRANONAOPTIONS="-g"
set EXTRAENBLENDOPTIONS="--gpu"
rem Should we remove source file?
set REMOVESRCFILE=no
rem Debug enable ("yes")/disable
set DEBUG=""
set EXITCODE=0

rem Process arguments
set PARAMCOUNT=0
rem We need this due to stupid parameter substitution
setlocal enabledelayedexpansion
:PARAMLOOP
rem Small hack as substring doesn't work on %1 (need to use delayed sub.?)
set _TMP=%1
set FIRSTCHAR=%_TMP:~0,1%
rem No arguments?
rem call :PRINT_DEBUG Current arg: %_TMP%
if '%_TMP%' == '' goto PARAMDONE
rem This is to fix weird "bug" when passing quoted files
rem https://stackoverflow.com/questions/31358869/problems-checking-if-string-is-quoted-and-adding-quotes-to-string
if !_TMP:~0^,1!!_TMP:~-1! equ "" set FIRSTCHAR="x"
rem Process arguments
if "%FIRSTCHAR%" == "/" (
  set SWITCH=!_TMP:~1,2!
  rem call :PRINT_DEBUG Current switch: !SWITCH!
  rem Switch processing
  if /i "!SWITCH!" == "q" (
    shift
    rem call :PRINT_DEBUG Setting JPEG quality to: %2
    rem shift has no effect (delayed expansion not working on %1?) we have to use %2
    set JPGQUALITY=%2
  )
  if /i "!SWITCH!" == "h" (
    rem call :PRINT_DEBUG Printing help
    goto NOARGS
  )
  if /i "!SWITCH!" == "o" (
    shift
    rem call :PRINT_DEBUG Setting output directory to: %2
    set OUTDIR=%2
  )
  if /i "!SWITCH!" == "g" (
    rem call :PRINT_DEBUG Will update gallery panorama list file
    set CREATEGALLERY=yes
  )
  if /i "!SWITCH!" == "a" (
    rem call :PRINT_DEBUG Forcing processing of all files
    set IGNOREPROCESSED=no
  )
  if /i "!SWITCH!" == "t" (
    shift
    rem call :PRINT_DEBUG Setting temporary dir: %2
    if not exist "%2" (
      echo Directory "%2" does not exist, using system default
    ) else (
      set MYTEMPDIR=%2
    )
  )
  if /i "!SWITCH!" == "r" (
    echo "Mark 7"
    rem call :PRINT_DEBUG Will remove source file(s)
    set REMOVESRCFILE=yes
  )
  if /i "!SWITCH!" == "m" (
    rem call :PRINT_DEBUG Using multiblend as blending program
    set BLENDPROG=%MULTIBLENDEXE%
  )
  if /i "!SWITCH!" == "n" (
    rem call :PRINT_DEBUG Disabling GPU usage
    rem Clear any options enabling usage of gpu
    set EXTRANONAOPTIONS=
    set EXTRAENBLENDOPTIONS=
  )
) else (
  if !PARAMCOUNT! EQU 0 (
    rem call :PRINT_DEBUG Input file: %_TMP%
    set PROTOINNAME=%_TMP%
  )
  if !PARAMCOUNT! EQU 1 (
    rem call :PRINT_DEBUG Setting PTO: %_TMP%
    set PTOTMPL=%_TMP%
  )
  set /a PARAMCOUNT+=1
)
shift & goto PARAMLOOP
:PARAMDONE

rem Check arguments and assume defaults
if "%PROTOINNAME%" == "" goto NOARGS

rem Where's Hugin? Prefer 64 bits
rem Haha, weird bug, it doesn't work when using brackets (spaces in path)
if exist "%HUGINPATH%/nona.exe" goto HUGINOK
rem 64 bits not found? Check x86
if not exist "%HUGINPATH32%/nona.exe" goto NOHUGIN
rem Found x86, overwrite original path
set HUGINPATH=%HUGINPATH32%
:HUGINOK
rem Check blending software (now it can be different)
if "%BLENDPROG%" == "%MULTIBLENDEXE%" if not exist "%HUGINPATH%/%BLENDPROG%" goto NOBLEND

rem Warn early about the gallery
if "%CREATEGALLERY%" == "yes" if not "%OUTDIR%" == "html\data" (
  if /i not "%OUTDIR%" == "html\data" (
    echo.
    echo Gallery file list will be updated but output directory is not set to html\data
    echo.
  )
)

rem Loop over input files
for %%f in (%PROTOINNAME%) do (
  set INNAME=%%f
  set OUTNAME=%OUTDIR%\%%~nf_pano.jpg

  rem Why a flag? No continue for "for", use goto, labels
  rem inside for break the loop, use if and "and/or", doesn't
  rem work (can't use poorman's and - double if)
  set PROCESSFILE=yes

  rem Check if this file was already processed
  if "%IGNOREPROCESSED%" == "yes" if exist "!OUTNAME!" (
    rem Can't use brackets for "override with /a" - breaks stuff
    echo File !INNAME! already processed, skipping... override with /a
    set PROCESSFILE=no
  )

  if "!PROCESSFILE!" == "yes" (
    "%HUGINPATH%/exiftool.exe" -s -s -s -Model !INNAME! > modelname.tmp
    set /p MODELNAME=<modelname.tmp
    del modelname.tmp
    rem This is default
    set LOCALPTOTMPL=%PTOTMPL_SM_C200%
    if "!PTOTMPL!" == "" (
      rem call :PRINT_DEBUG Detected model: !MODELNAME!
      if "!MODELNAME!" == "SM-C200" set LOCALPTOTMPL=%PTOTMPL_SM_C200%
      if "!MODELNAME!" == "SM-R210" set LOCALPTOTMPL=%PTOTMPL_SM_R210%
    ) else (
      rem call :PRINT_DEBUG Using command line PTO: !PTOTMPL!
      set LOCALPTOTMPL=!PTOTMPL!
    )

    echo Processing file: !INNAME!
    call :PROCESSPANORAMA !INNAME! !OUTNAME! !LOCALPTOTMPL!

    if "%REMOVESRCFILE%" == "yes" (
      rem call :PRINT_DEBUG Removing source file: !INNAME!
      del !INNAME!
    )
  )
)

if "%CREATEGALLERY%" == "yes" (
  rem This could be a bit more elegant, but this is the easiest
  cd $GALLERYDIR
  echo Updating gallery file list
  rem Yep, repetition...
  rem https://superuser.com/questions/1029558/list-files-in-a-subdirectory-and-get-relative-paths-only-with-windows-command-li
  for %%X IN ('data') DO FOR /F "TOKENS=*" %%F IN (
    'dir /B /A-D ".\%%~X\*.jpg"'
  ) do echo .\%%~X\%%~F > "%GALLERYFILELIST%"
  for %%X IN ('data') DO FOR /F "TOKENS=*" %%F IN (
    'dir /B /A-D ".\%%~X\*.jpeg"'
  ) do echo .\%%~X\%%~F >> "%GALLERYFILELIST%"
  for %%X IN ('data') DO FOR /F "TOKENS=*" %%F IN (
    'dir /B /A-D ".\%%~X\*.mp4"'
  ) do echo .\%%~X\%%~F >> "%GALLERYFILELIST%"
  cd ..
)

rem Time calculation
set end=%time%
set options="tokens=1-4 delims=:.,"
rem Don't try to break lines here, it will most probably not work
for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100

set /a hours=%end_h%-%start_h%
set /a mins=%end_m%-%start_m%
set /a secs=%end_s%-%start_s%
set /a ms=%end_ms%-%start_ms%
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
if %hours% lss 0 set /a hours = 24%hours%
if 1%ms% lss 100 set ms=0%ms%

rem mission accomplished
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%

echo Processing took: %totalsecs% s
echo Processed files are in %OUTDIR%

goto eof

:NOARGS

echo.
echo Script to stitch raw panorama files.
echo Raw meaning two fisheye images side by side.
echo Script originally writen for Samsung Gear 360.
echo.
echo Usage:
echo %SCRIPTNAME% [options] infile [hugintemplate]
echo.
echo Where infile is a panorama file from camera, it can
echo be a wildcard (ex. *.JPG). hugintemplate is optional.
echo.
echo Panorama will be written to a file with appended _pano,
echo example: 360_010.JPG -> 360_010_pano.JPG
echo.
echo /a process all files, by default already processed images
echo    are ignored (in output directory)
echo /g update gallery file list
echo /m use multiblend (http://horman.net/multiblend/) instead
echo    of enblend for final image stitching
echo /o sets output directory for stitched panoramas
echo    default: html\data
echo /q sets output jpeg quality
echo /t sets temporary directory (default: use systems' default
echo    temporary directory)
echo /h prints this help
echo.
goto eof

:NOHUGIN
echo.
echo Hugin is not installed or installed in non-standard directory
echo Download and install Hugin from: http://hugin.sourceforge.net/
echo Was looking in: %HUGINPATH%
echo and: %HUGINPATH32%
set EXITCODE=1
goto eof

:NOBLEND
echo.
echo Could not find requested blending program:
echo %HUGINPATH%\%BLENDPROG%
echo Please install missing software
set EXITCODE=1
goto eof

:NONAERROR
echo nona failed, panorama not created
set EXITCODE=1
goto eof

:ENBLENDERROR
echo enblend failed, panorama not created
set EXITCODE=1
goto eof

rem Function to stich panorama, parameters:
rem 1: input (two fisheye)
rem 2: output filename
rem 3: pto (Hugin template) file to use
:PROCESSPANORAMA
set LOCALINNAME=%1
set LOCALOUTNAME=%2
set LOCALPTOTMPL=%3

rem Execute commands (as simple as it is)
echo Processing input images (nona)
rem call :PRINT_DEBUG Extra nona options: %EXTRANONAOPTIONS%
rem call :PRINT_DEBUG Output: %MYTEMPDIR%\%OUTTMPNAME%
rem call :PRINT_DEBUG PTO: %LOCALPTOTMPL%
rem call :PRINT_DEBUG Local input: %LOCALINNAME%
"%HUGINPATH%/nona.exe" ^
              %EXTRANONAOPTIONS% ^
              -o %MYTEMPDIR%\%OUTTMPNAME% ^
              -m TIFF_m ^
              -z LZW ^
              %LOCALPTOTMPL% ^
              %LOCALINNAME% ^
              %LOCALINNAME%
if %ERRORLEVEL% equ 1 goto NONAERROR

rem Extra options for multiblend
if "%BLENDPROG%" == "multiblend_x64.exe" (
  set EXTRABLENDOPTS=--quiet
)
rem Add extra options for enblend (ex. gpu)
if "%BLENDPROG%" == "enblend.exe" (
  set EXTRABLENDOPTS=%EXTRAENBLENDOPTIONS%
)

rem call :PRINT_DEBUG Extra blend prog options: %EXTRABLENDOPTS%

echo Stitching input images
"%HUGINPATH%\%BLENDPROG%" ^
              %EXTRABLENDOPTS% ^
              --compression=%JPGQUALITY% ^
              -o %2 ^
              %MYTEMPDIR%\%OUTTMPNAME%0000.tif ^
              %MYTEMPDIR%\%OUTTMPNAME%0001.tif
if %ERRORLEVEL% equ 1 goto ENBLENDERROR

rem Check if we have exiftool...
echo Setting EXIF data (exiftool)
set IMG_WIDTH=7776
set IMG_HEIGHT=3888
"%HUGINPATH%/exiftool.exe" -ProjectionType=equirectangular ^
                            -q ^
                            -m ^
                            -TagsFromFile "%LOCALINNAME%" ^
                            -exif:all ^
                            -ExifByteOrder=II ^
                            -FullPanoWidthPixels=%IMG_WIDTH% ^
                            -FullPanoHeightPixels=%IMG_HEIGHT% ^
                            -CroppedAreaImageWidthPixels=%IMG_WIDTH% ^
                            -CroppedAreaImageHeightPixels=%IMG_HEIGHT% ^
                            -CroppedAreaLeftPixels=0 ^
                            -CroppedAreaTopPixels=0 ^
                            --FocalLength ^
                            --FieldOfView ^
                            --ThumbnailImage ^
                            --PreviewImage ^
                            --EncodingProcess ^
                            --YCbCrSubSampling ^
                            --Compression ^
                            "%LOCALOUTNAME%"
if "%ERRORLEVEL%" EQU 1 echo Setting EXIF failed, ignoring

rem There are problems with -delete_original in exiftool, manually remove the file
del "%LOCALOUTNAME%_original"
exit /b 0

:PRINT_DEBUG
if %DEBUG% == "yes" (
  echo DEBUG: %1 %2 %3 %4 %5 %6 %7 %8 %9
)
exit /b 0

:eof
exit /b %EXITCODE%

@echo off

rem This is a small script to stitch panorama images produced  by Samsung Gear360
rem Could be adopted to use with other cameras after creating pto file (Hugin
rem template)
rem
rem https://github.com/ultramango/gear360pano

rem http://stackoverflow.com/questions/673523/how-to-measure-execution-time-of-command-in-windows-command-line
set start=%time%
set HUGINPATH=C:\Program Files\Hugin\bin
set HUGINPATH32=C:\Program Files (x86)\Hugin\bin
set GALLERYDIR=html
set GALLERYFILELIST=filelist.txt
rem This is to avoid some weird bug (???) %~dp0 doesn't work in a loop (effect of shift?)
set SCRIPTNAME=%0
set SCRIPTPATH=%~dp0
set OUTTMPNAME=out
set PTOTMPL_SM_C200="%SCRIPTPATH%gear360sm-c200.pto"
set PTOTMPL_SM_R210="%SCRIPTPATH%gear360sm-r210.pto"
set INNAME=
set PTOTMPL=
set OUTDIR=%SCRIPTPATH%html\data
set JPGQUALITY=97
set PTOJPGFILENAME=dummy.jpg
set IGNOREPROCESSED=yes
rem Default temporary directory
set MYTEMPDIR=%TEMP%
rem We define default here
set BLENDPROG=enblend.exe
set MULTIBLENDEXE=multiblend_x64.exe
rem By default use gpu
set EXTRANONAOPTIONS="-g"
set EXTRAENBLENDOPTIONS="--gpu"
rem Should we remove source file?
set REMOVESRCFILE=no
rem Debug enable ("yes")/disable
set DEBUG=""
set EXITCODE=0

rem Process arguments
set PARAMCOUNT=0
rem We need this due to stupid parameter substitution
setlocal enabledelayedexpansion
:PARAMLOOP
rem Small hack as substring doesn't work on %1 (need to use delayed sub.?)
set _TMP=%1
set FIRSTCHAR=%_TMP:~0,1%
rem No arguments?
rem call :PRINT_DEBUG Current arg: %_TMP%
if '%_TMP%' == '' goto PARAMDONE
rem This is to fix weird "bug" when passing quoted files
rem https://stackoverflow.com/questions/31358869/problems-checking-if-string-is-quoted-and-adding-quotes-to-string
if !_TMP:~0^,1!!_TMP:~-1! equ "" set FIRSTCHAR="x"
rem Process arguments
if "%FIRSTCHAR%" == "/" (
  set SWITCH=!_TMP:~1,2!
  rem call :PRINT_DEBUG Current switch: !SWITCH!
  rem Switch processing
  if /i "!SWITCH!" == "q" (
    shift
    rem call :PRINT_DEBUG Setting JPEG quality to: %2
    rem shift has no effect (delayed expansion not working on %1?) we have to use %2
    set JPGQUALITY=%2
  )
  if /i "!SWITCH!" == "h" (
    rem call :PRINT_DEBUG Printing help
    goto NOARGS
  )
  if /i "!SWITCH!" == "o" (
    shift
    rem call :PRINT_DEBUG Setting output directory to: %2
    set OUTDIR=%2
  )
  if /i "!SWITCH!" == "g" (
    rem call :PRINT_DEBUG Will update gallery panorama list file
    set CREATEGALLERY=yes
  )
  if /i "!SWITCH!" == "a" (
    rem call :PRINT_DEBUG Forcing processing of all files
    set IGNOREPROCESSED=no
  )
  if /i "!SWITCH!" == "t" (
    shift
    rem call :PRINT_DEBUG Setting temporary dir: %2
    if not exist "%2" (
      echo Directory "%2" does not exist, using system default
    ) else (
      set MYTEMPDIR=%2
    )
  )
  if /i "!SWITCH!" == "r" (
    rem call :PRINT_DEBUG Will remove source file(s)
    set REMOVESRCFILE=yes
  )
  if /i "!SWITCH!" == "m" (
    rem call :PRINT_DEBUG Using multiblend as blending program
    set BLENDPROG=%MULTIBLENDEXE%
  )
  if /i "!SWITCH!" == "n" (
    rem call :PRINT_DEBUG Disabling GPU usage
    rem Clear any options enabling usage of gpu
    set EXTRANONAOPTIONS=
    set EXTRAENBLENDOPTIONS=
  )
) else (
  if !PARAMCOUNT! EQU 0 (
    rem call :PRINT_DEBUG Input file: %_TMP%
    set PROTOINNAME=%_TMP%
  )
  if !PARAMCOUNT! EQU 1 (
    rem call :PRINT_DEBUG Setting PTO: %_TMP%
    set PTOTMPL=%_TMP%
  )
  set /a PARAMCOUNT+=1
)
shift & goto PARAMLOOP
:PARAMDONE

rem Check arguments and assume defaults
if "%PROTOINNAME%" == "" goto NOARGS

rem Where's Hugin? Prefer 64 bits
rem Haha, weird bug, it doesn't work when using brackets (spaces in path)
if exist "%HUGINPATH%/nona.exe" goto HUGINOK
rem 64 bits not found? Check x86
if not exist "%HUGINPATH32%/nona.exe" goto NOHUGIN
rem Found x86, overwrite original path
set HUGINPATH=%HUGINPATH32%
:HUGINOK
rem Check blending software (now it can be different)
if "%BLENDPROG%" == "%MULTIBLENDEXE%" if not exist "%HUGINPATH%/%BLENDPROG%" goto NOBLEND

rem Warn early about the gallery
if "%CREATEGALLERY%" == "yes" if not "%OUTDIR%" == "html\data" (
  if /i not "%OUTDIR%" == "html\data" (
    echo.
    echo Gallery file list will be updated but output directory is not set to html\data
    echo.
  )
)

rem Loop over input files
for %%f in (%PROTOINNAME%) do (
  set INNAME=%%f
  set OUTNAME=%OUTDIR%\%%~nf_pano.jpg

  rem Why a flag? No continue for "for", use goto, labels
  rem inside for break the loop, use if and "and/or", doesn't
  rem work (can't use poorman's and - double if)
  set PROCESSFILE=yes

  rem Check if this file was already processed
  if "%IGNOREPROCESSED%" == "yes" if exist "!OUTNAME!" (
    rem Can't use brackets for "override with /a" - breaks stuff
    echo File !INNAME! already processed, skipping... override with /a
    set PROCESSFILE=no
  )

  if "!PROCESSFILE!" == "yes" (
    "%HUGINPATH%/exiftool.exe" -s -s -s -Model !INNAME! > modelname.tmp
    set /p MODELNAME=<modelname.tmp
    del modelname.tmp
    rem This is default
    set LOCALPTOTMPL=%PTOTMPL_SM_C200%
    if "!PTOTMPL!" == "" (
      rem call :PRINT_DEBUG Detected model: !MODELNAME!
      if "!MODELNAME!" == "SM-C200" set LOCALPTOTMPL=%PTOTMPL_SM_C200%
      if "!MODELNAME!" == "SM-R210" set LOCALPTOTMPL=%PTOTMPL_SM_R210%
    ) else (
      rem call :PRINT_DEBUG Using command line PTO: !PTOTMPL!
      set LOCALPTOTMPL=!PTOTMPL!
    )

    echo Processing file: !INNAME!
    call :PROCESSPANORAMA !INNAME! !OUTNAME! !LOCALPTOTMPL!

    if "%REMOVESRCFILE%" == "yes" (
      rem call :PRINT_DEBUG Removing source file: !INNAME!
      del !INNAME!
    )
  )
)

if "%CREATEGALLERY%" == "yes" (
  rem This could be a bit more elegant, but this is the easiest
  cd $GALLERYDIR
  echo Updating gallery file list
  rem Yep, repetition...
  rem https://superuser.com/questions/1029558/list-files-in-a-subdirectory-and-get-relative-paths-only-with-windows-command-li
  for %%X IN ('data') DO FOR /F "TOKENS=*" %%F IN (
    'dir /B /A-D ".\%%~X\*.jpg"'
  ) do echo .\%%~X\%%~F > "%GALLERYFILELIST%"
  for %%X IN ('data') DO FOR /F "TOKENS=*" %%F IN (
    'dir /B /A-D ".\%%~X\*.jpeg"'
  ) do echo .\%%~X\%%~F >> "%GALLERYFILELIST%"
  for %%X IN ('data') DO FOR /F "TOKENS=*" %%F IN (
    'dir /B /A-D ".\%%~X\*.mp4"'
  ) do echo .\%%~X\%%~F >> "%GALLERYFILELIST%"
  cd ..
)

rem Time calculation
set end=%time%
set options="tokens=1-4 delims=:.,"
rem Don't try to break lines here, it will most probably not work
for /f %options% %%a in ("%start%") do set start_h=%%a&set /a start_m=100%%b %% 100&set /a start_s=100%%c %% 100&set /a start_ms=100%%d %% 100
for /f %options% %%a in ("%end%") do set end_h=%%a&set /a end_m=100%%b %% 100&set /a end_s=100%%c %% 100&set /a end_ms=100%%d %% 100

set /a hours=%end_h%-%start_h%
set /a mins=%end_m%-%start_m%
set /a secs=%end_s%-%start_s%
set /a ms=%end_ms%-%start_ms%
if %ms% lss 0 set /a secs = %secs% - 1 & set /a ms = 100%ms%
if %secs% lss 0 set /a mins = %mins% - 1 & set /a secs = 60%secs%
if %mins% lss 0 set /a hours = %hours% - 1 & set /a mins = 60%mins%
if %hours% lss 0 set /a hours = 24%hours%
if 1%ms% lss 100 set ms=0%ms%

rem mission accomplished
set /a totalsecs = %hours%*3600 + %mins%*60 + %secs%

echo Processing took: %totalsecs% s
echo Processed files are in %OUTDIR%

goto eof

:NOARGS

echo.
echo Script to stitch raw panorama files.
echo Raw meaning two fisheye images side by side.
echo Script originally writen for Samsung Gear 360.
echo.
echo Usage:
echo %SCRIPTNAME% [options] infile [hugintemplate]
echo.
echo Where infile is a panorama file from camera, it can
echo be a wildcard (ex. *.JPG). hugintemplate is optional.
echo.
echo Panorama will be written to a file with appended _pano,
echo example: 360_010.JPG -> 360_010_pano.JPG
echo.
echo /a process all files, by default already processed images
echo    are ignored (in output directory)
echo /g update gallery file list
echo /m use multiblend (http://horman.net/multiblend/) instead
echo    of enblend for final image stitching
echo /o sets output directory for stitched panoramas
echo    default: html\data
echo /q sets output jpeg quality
echo /t sets temporary directory (default: use systems' default
echo    temporary directory)
echo /h prints this help
echo.
goto eof

:NOHUGIN
echo.
echo Hugin is not installed or installed in non-standard directory
echo Download and install Hugin from: http://hugin.sourceforge.net/
echo Was looking in: %HUGINPATH%
echo and: %HUGINPATH32%
set EXITCODE=1
goto eof

:NOBLEND
echo.
echo Could not find requested blending program:
echo %HUGINPATH%\%BLENDPROG%
echo Please install missing software
set EXITCODE=1
goto eof

:NONAERROR
echo nona failed, panorama not created
set EXITCODE=1
goto eof

:ENBLENDERROR
echo enblend failed, panorama not created
set EXITCODE=1
goto eof

rem Function to stich panorama, parameters:
rem 1: input (two fisheye)
rem 2: output filename
rem 3: pto (Hugin template) file to use
:PROCESSPANORAMA
set LOCALINNAME=%1
set LOCALOUTNAME=%2
set LOCALPTOTMPL=%3

rem Execute commands (as simple as it is)
echo Processing input images (nona)
rem call :PRINT_DEBUG Extra nona options: %EXTRANONAOPTIONS%
rem call :PRINT_DEBUG Output: %MYTEMPDIR%\%OUTTMPNAME%
rem call :PRINT_DEBUG PTO: %LOCALPTOTMPL%
rem call :PRINT_DEBUG Local input: %LOCALINNAME%
"%HUGINPATH%/nona.exe" ^
              %EXTRANONAOPTIONS% ^
              -o %MYTEMPDIR%\%OUTTMPNAME% ^
              -m TIFF_m ^
              -z LZW ^
              %LOCALPTOTMPL% ^
              %LOCALINNAME% ^
              %LOCALINNAME%
if %ERRORLEVEL% equ 1 goto NONAERROR

rem Extra options for multiblend
if "%BLENDPROG%" == "multiblend_x64.exe" (
  set EXTRABLENDOPTS=--quiet
)
rem Add extra options for enblend (ex. gpu)
if "%BLENDPROG%" == "enblend.exe" (
  set EXTRABLENDOPTS=%EXTRAENBLENDOPTIONS%
)

rem call :PRINT_DEBUG Extra blend prog options: %EXTRABLENDOPTS%

echo Stitching input images
"%HUGINPATH%\%BLENDPROG%" ^
              %EXTRABLENDOPTS% ^
              --compression=%JPGQUALITY% ^
              -o %2 ^
              %MYTEMPDIR%\%OUTTMPNAME%0000.tif ^
              %MYTEMPDIR%\%OUTTMPNAME%0001.tif
if %ERRORLEVEL% equ 1 goto ENBLENDERROR

rem Check if we have exiftool...
echo Setting EXIF data (exiftool)
set IMG_WIDTH=7776
set IMG_HEIGHT=3888
"%HUGINPATH%/exiftool.exe" -ProjectionType=equirectangular ^
                            -q ^
                            -m ^
                            -TagsFromFile "%LOCALINNAME%" ^
                            -exif:all ^
                            -ExifByteOrder=II ^
                            -FullPanoWidthPixels=%IMG_WIDTH% ^
                            -FullPanoHeightPixels=%IMG_HEIGHT% ^
                            -CroppedAreaImageWidthPixels=%IMG_WIDTH% ^
                            -CroppedAreaImageHeightPixels=%IMG_HEIGHT% ^
                            -CroppedAreaLeftPixels=0 ^
                            -CroppedAreaTopPixels=0 ^
                            --FocalLength ^
                            --FieldOfView ^
                            --ThumbnailImage ^
                            --PreviewImage ^
                            --EncodingProcess ^
                            --YCbCrSubSampling ^
                            --Compression ^
                            "%LOCALOUTNAME%"
if "%ERRORLEVEL%" EQU 1 echo Setting EXIF failed, ignoring

rem There are problems with -delete_original in exiftool, manually remove the file
del "%LOCALOUTNAME%_original"
exit /b 0

:PRINT_DEBUG
if %DEBUG% == "yes" (
  echo DEBUG: %1 %2 %3 %4 %5 %6 %7 %8 %9
)
exit /b 0

:eof
exit /b %EXITCODE%

Remove debug message

Remove debug message


for i in `ls | grep 2011`; do foo=`echo $i | cut -c 5-8`; mv $i $foo; done

add for future reference how to move a bunch of directories to new naming format


add batch file for pushing

add batch file for pushing


python -m virtualenv .

call Scripts/activate.bat
pip install -r requirements.txt
set PYTHONPATH=%CD%
set PATH=%CD%/bin;%PATH%

python -m virtualenv .

call Scripts/activate.bat
pip install -r requirements.txt
set PYTHONPATH=%CD%
set PATH=%CD%\bin;%PATH%

Fix rc.cmd

Fix rc.cmd


Add Build time

Add Build time


@rem Copyright 2018 Google LLC. All rights reserved.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem     http://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.

@echo "Starting Windows build"

cd /d %~dp0
cd ..

call npm install -g npm@latest || goto :error
call npm install || goto :error
call npm run test || goto :error

goto :EOF

:error
exit /b 1

@rem Copyright 2018 Google LLC. All rights reserved.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem     http://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.

@echo "Starting Windows build"

cd /d %~dp0
cd ..

@rem The image we're currently running has a broken version of Node.js enabled
@rem by nvm (v10.15.3), which has no npm bin. This hack uses the functional
@rem Node v8.9.1 to install npm@latest, it then uses this version of npm to
@rem install npm for v10.15.3.
call nvm use v8.9.1 || goto :error
call node C:\Users\kbuilder\AppData\Roaming\nvm-ps\versions\v8.9.1\node_modules\npm-bootstrap\bin\npm-cli.js i npm -g || goto :error
call nvm use v10.15.3 || goto :error
call node C:\Users\kbuilder\AppData\Roaming\nvm-ps\versions\v8.9.1\node_modules\npm\bin\npm-cli.js i npm -g || goto :error

call npm install || goto :error
call npm run test || goto :error

goto :EOF

:error
exit /b 1

build: patch Windows container, fixing Node 10 (#236)


@rem Copyright 2018 gRPC authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem     http://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.

@echo "Starting Windows build"

cd /d %~dp0
cd ..

call npm install -g npm@5 || goto :error

call npm install || goto :error
call npm run test || goto :error

goto :EOF

:error
exit /b 1

@rem Copyright 2018 Google LLC. All rights reserved.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem     http://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.

@echo "Starting Windows build"

cd /d %~dp0
cd ..

call npm install -g npm@latest || goto :error
call npm install || goto :error
call npm run test || goto :error

goto :EOF

:error
exit /b 1

use latest npm on Windows (#156)

chore: use latest npm on Windows (#156)


Add file run.bat

Add file run.bat


@echo off
goto :main

======================================================================
Performs a clean build and create NuGet packages for this solution
Note that this also modifies the following files, replacing
placeholder version numbers with actual version numbers:
    src\common\GlobalAssemblyInfo.cs
    src\*.nuspec
    src\*\project.json
(see the SetVersionNumber task in xunit.performance.msbuild)

These files will, therefore, show up as modified after the build.
Be careful NOT to check them in that way!

If you publish these packages to Nuget, then please remember to
bump the build number on BuildSemanticVersion below.
======================================================================

:main
setlocal

set BuildAssemblyVersion=1.0.0.0
set BuildSemanticVersion=1.0.0-alpha-build0007

echo Building version %BuildSemanticVersion% NuGet packages.
echo WARNING: Some source files will be modified during this build.
echo WARNING: Please be careful not to check in those modifications.

msbuild.exe /m /nologo /t:CI /v:m /fl xunit.performance.msbuild

goto :eof

@echo off
goto :main

======================================================================
Performs a clean build and create NuGet packages for this solution
Note that this also modifies the following files, replacing
placeholder version numbers with actual version numbers:
    src\common\GlobalAssemblyInfo.cs
    src\*.nuspec
    src\*\project.json
(see the SetVersionNumber task in xunit.performance.msbuild)

These files will, therefore, show up as modified after the build.
Be careful NOT to check them in that way!

If you publish these packages to Nuget, then please remember to
bump the build number on BuildSemanticVersion below.
======================================================================

:main
setlocal

set BuildAssemblyVersion=1.0.0.*
set BuildSemanticVersion=1.0.0-alpha-build0007

echo Building version %BuildSemanticVersion% NuGet packages.
echo WARNING: Some source files will be modified during this build.
echo WARNING: Please be careful not to check in those modifications.

msbuild.exe /m /nologo /t:CI /v:m /fl xunit.performance.msbuild

goto :eof

Use automatic versioning for assembly version build number


call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
hg pull -u --rebase
msbuild "Palaso VS2010.sln" /verbosity:quiet /maxcpucount

IF "%1"=="" (
	set BUILD_CONFIG="Debug"
) ELSE (
	set BUILD_CONFIG=%1
)

IF "%2"=="" (
	call "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
)

hg pull -u --rebase
msbuild "Palaso VS2010.sln" /verbosity:quiet /maxcpucount /p:Configuration=%BUILD_CONFIG%

Update GetAndBuildThis batch file

Update GetAndBuildThis batch file