setup-npp64.bat 2.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
@echo off

WHERE unzip
IF %ERRORLEVEL% NEQ 0 (
	echo Cywin with unzip required
)

rem we check de powershell version if lower that 3 exit
for /f %%i in ('powershell -Command "$PSVersionTable.PSVersion.Major"') do set powershellVersion=%%i
echo powershellVersion=%powershellVersion%

if %powershellVersion% LSS 3 (
  echo Only works with powershell greater or equal to 3 
  goto end
)

IF "%NPP_VERSION%" NEQ "" goto versionSet

rem https://xenappblog.com/2018/download-and-install-latest-notepad/ based on that at command line
rem powershell -Command "$url = 'https://notepad-plus-plus.org/';$content = wget -Uri $url;($content.allelements | ? id -eq 'download').innerText -match '\d+\.\d+\.\d+' | out-null;Write-Output $Matches.Values"

Set POWERSHELL_COMMAND="$url = 'https://notepad-plus-plus.org/';$content = wget -Uri $url;($content.allelements | ? id -eq 'download').innerText -match '\d+\.\d+' | out-null;Write-Output $Matches.Values"
rem Set POWERSHELL_COMMAND="$url = 'https://notepad-plus-plus.org/';$content = wget -Uri $url;($content.allelements | ? id -eq 'download').innerText -match '\d+\.\d+\.\d+' | out-null;Write-Output $Matches.Values"

rem echo POWERSHELL_COMMAND=%POWERSHELL_COMMAND%
rem powershell -Command %POWERSHELL_COMMAND%

for /f %%i in (' powershell -Command %POWERSHELL_COMMAND% ') do set NPP_VERSION=%%i
echo Defaults NPP_VERSION=%NPP_VERSION%

:versionSet

echo downloading %NPP_VERSION%

rem https://www.dostips.com/DtTipsStringManipulation.php
set downloadUrl=https://notepad-plus-plus.org/repository/7.x/%NPP_VERSION%/npp.%NPP_VERSION%.bin.x64.zip

mkdir downloads 2> nul

for /f %%i in ('powershell -Command "$(split-path -path "%downloadUrl%" -leaf)"') do set appFileName=%%i
echo appFileName=%appFileName%

if Not exist "downloads\%appFileName%" (
    rem file exists
	echo downloading %downloadUrl% to downloads
	rem we escape because we are inside if
	powershell -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest %downloadUrl% -OutFile downloads\%appFileName%"
)

set APP_HOME_REL_PATH=npp64
mkdir %APP_HOME_REL_PATH% 2> nul

unzip downloads\%appFileName% -d %APP_HOME_REL_PATH%

echo #!/bin/sh  > %APP_HOME_REL_PATH%\npp.sh
echo|set /p="notepad++.exe -multiInst -notabbar -nosession -noPlugin $(cygpath -w "$@")" >> %APP_HOME_REL_PATH%\npp.sh

copy /Y "%APP_HOME_REL_PATH%\notepad++.exe" "%APP_HOME_REL_PATH%\npp.exe"

rem ----------------------------------  Path   --------------------------------

echo %PATH% | %WINDIR%\System32\find.exe "%CURRENT_DIR%\%APP_HOME_REL_PATH%" /C >NUL
IF NOT ERRORLEVEL 1 GOTO pathDuplicate
SET PATH=%CURRENT_DIR%\%APP_HOME_REL_PATH%;%PATH%
echo PATH has been updated PATH = %PATH%
:pathDuplicate

:end