From aa48a411ba76c5eae220196b75c243cb3339e40c Mon Sep 17 00:00:00 2001 From: CorpNewt <12772521+corpnewt@users.noreply.github.com> Date: Sun, 16 Nov 2025 17:04:09 -0600 Subject: [PATCH] Bring to feature parity --- MakeInstall.bat | 127 +++++++++++++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 49 deletions(-) diff --git a/MakeInstall.bat b/MakeInstall.bat index 691aa9f..154789d 100644 --- a/MakeInstall.bat +++ b/MakeInstall.bat @@ -1,6 +1,7 @@ @echo off -REM Get our local path before delayed expansion - allows ! in path +REM Get our local path and args before delayed expansion - allows % and ! set "thisDir=%~dp0" +set "args=%*" setlocal enableDelayedExpansion REM Setup initial vars @@ -23,7 +24,10 @@ set "use_py3=TRUE" REM We'll parse if the first argument passed is REM --install-python and if so, we'll just install +REM Can optionally take a version number as the +REM second arg - i.e. --install-python 3.13.1 set "just_installing=FALSE" +set "user_provided=" REM Get the system32 (or equivalent) path call :getsyspath "syspath" @@ -41,9 +45,9 @@ if "!syspath!" == "" ( ) if "!syspath!" == "" ( cls - echo ### ### - echo # Warning # - echo ### ### + echo ### ### + echo # Missing Required Files # + echo ### ### echo. echo Could not locate cmd.exe, reg.exe, or where.exe echo. @@ -60,6 +64,7 @@ if "!syspath!" == "" ( if "%~1" == "--install-python" ( set "just_installing=TRUE" + set "user_provided=%~2" goto installpy ) @@ -76,6 +81,11 @@ if "!script_name!" == "" ( ) ) if not exist "!thisDir!\!script_name!" ( + cls + echo ### ### + echo # Target Not Found # + echo ### ### + echo. echo Could not find !looking_for!. echo Please make sure to run this script from the same directory echo as !looking_for!. @@ -113,13 +123,14 @@ if !tried! lss 1 ( ) ) else ( cls - echo ### ### - echo # Warning # - echo ### ### + echo ### ### + echo # Python Not Found # + echo ### ### echo. REM Couldn't install for whatever reason - give the error message echo Python is not installed or not found in your PATH var. - echo Please install it from https://www.python.org/downloads/windows/ + echo Please go to https://www.python.org/downloads/windows/ to + echo download and install the latest version, then try again. echo. echo Make sure you check the box labeled: echo. @@ -197,9 +208,9 @@ exit /b 0 :askinstall cls -echo ### ### -echo # Python Not Found # -echo ### ### +echo ### ### +echo # Python Not Found # +echo ### ### echo. echo Python !targetpy! was not found on the system or in the PATH var. echo. @@ -217,41 +228,54 @@ goto askinstall :installpy REM This will attempt to download and install python -REM First we get the html for the python downloads page for Windows set /a tried=!tried!+1 cls -echo ### ### -echo # Installing Python # -echo ### ### +echo ### ### +echo # Downloading Python # +echo ### ### echo. -echo Gathering info from https://www.python.org/downloads/windows/... -powershell -command "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;(new-object System.Net.WebClient).DownloadFile('https://www.python.org/downloads/windows/','%TEMP%\pyurl.txt')" -REM Extract it if it's gzip compressed -powershell -command "$infile='%TEMP%\pyurl.txt';$outfile='%TEMP%\pyurl.temp';try{$input=New-Object System.IO.FileStream $infile,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read);$output=New-Object System.IO.FileStream $outfile,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None);$gzipStream=New-Object System.IO.Compression.GzipStream $input,([IO.Compression.CompressionMode]::Decompress);$buffer=New-Object byte[](1024);while($true){$read=$gzipstream.Read($buffer,0,1024);if($read -le 0){break};$output.Write($buffer,0,$read)};$gzipStream.Close();$output.Close();$input.Close();Move-Item -Path $outfile -Destination $infile -Force}catch{}" -if not exist "%TEMP%\pyurl.txt" ( - if /i "!just_installing!" == "TRUE" ( - echo Failed to get info - exit /b 1 - ) else ( - goto checkpy - ) -) -echo Parsing for latest... -pushd "%TEMP%" -:: Version detection code slimmed by LussacZheng (https://github.com/corpnewt/gibMacOS/issues/20) -for /f "tokens=9 delims=< " %%x in ('findstr /i /c:"Latest Python !targetpy! Release" pyurl.txt') do ( set "release=%%x" ) -popd +set "release=!user_provided!" if "!release!" == "" ( - if /i "!just_installing!" == "TRUE" ( - echo Failed to get python version - exit /b 1 - ) else ( - goto checkpy + REM No explicit release set - get the latest from python.org + echo Gathering latest version... + powershell -command "[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;(new-object System.Net.WebClient).DownloadFile('https://www.python.org/downloads/windows/','%TEMP%\pyurl.txt')" + REM Extract it if it's gzip compressed + powershell -command "$infile='%TEMP%\pyurl.txt';$outfile='%TEMP%\pyurl.temp';try{$input=New-Object System.IO.FileStream $infile,([IO.FileMode]::Open),([IO.FileAccess]::Read),([IO.FileShare]::Read);$output=New-Object System.IO.FileStream $outfile,([IO.FileMode]::Create),([IO.FileAccess]::Write),([IO.FileShare]::None);$gzipStream=New-Object System.IO.Compression.GzipStream $input,([IO.Compression.CompressionMode]::Decompress);$buffer=New-Object byte[](1024);while($true){$read=$gzipstream.Read($buffer,0,1024);if($read -le 0){break};$output.Write($buffer,0,$read)};$gzipStream.Close();$output.Close();$input.Close();Move-Item -Path $outfile -Destination $infile -Force}catch{}" + if not exist "%TEMP%\pyurl.txt" ( + if /i "!just_installing!" == "TRUE" ( + echo - Failed to get info + exit /b 1 + ) else ( + goto checkpy + ) + ) + pushd "%TEMP%" + :: Version detection code slimmed by LussacZheng (https://github.com/corpnewt/gibMacOS/issues/20) + for /f "tokens=9 delims=< " %%x in ('findstr /i /c:"Latest Python !targetpy! Release" pyurl.txt') do ( set "release=%%x" ) + popd + REM Let's delete our txt file now - we no longer need it + del "%TEMP%\pyurl.txt" + if "!release!" == "" ( + if /i "!just_installing!" == "TRUE" ( + echo - Failed to get python version + exit /b 1 + ) else ( + goto checkpy + ) + ) + echo Located Version: !release! +) else ( + echo User-Provided Version: !release! + REM Update our targetpy to reflect the first number of + REM our release + for /f "tokens=1 delims=." %%a in ("!release!") do ( + call :isnumber "%%a" + if "!errorlevel!" == "0" ( + set "targetpy=%%a" + ) ) ) -echo Found Python !release! - Downloading... -REM Let's delete our txt file now - we no longer need it -del "%TEMP%\pyurl.txt" +echo Building download url... REM At this point - we should have the version number. REM We can build the url like so: "https://www.python.org/ftp/python/[version]/python-[version]-amd64.exe" set "url=https://www.python.org/ftp/python/!release!/python-!release!-amd64.exe" @@ -260,30 +284,34 @@ if "!targetpy!" == "2" ( set "url=https://www.python.org/ftp/python/!release!/python-!release!.amd64.msi" set "pytype=msi" ) +echo - !url! +echo Downloading... REM Now we download it with our slick powershell command powershell -command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; (new-object System.Net.WebClient).DownloadFile('!url!','%TEMP%\pyinstall.!pytype!')" REM If it doesn't exist - we bail if not exist "%TEMP%\pyinstall.!pytype!" ( if /i "!just_installing!" == "TRUE" ( - echo Failed to download installer + echo - Failed to download python installer exit /b 1 ) else ( goto checkpy ) ) REM It should exist at this point - let's run it to install silently -echo Installing... +echo Running python !pytype! installer... pushd "%TEMP%" if /i "!pytype!" == "exe" ( - echo pyinstall.exe /quiet PrependPath=1 Include_test=0 Shortcuts=0 Include_launcher=0 + echo - pyinstall.exe /quiet PrependPath=1 Include_test=0 Shortcuts=0 Include_launcher=0 pyinstall.exe /quiet PrependPath=1 Include_test=0 Shortcuts=0 Include_launcher=0 ) else ( set "foldername=!release:.=!" - echo msiexec /i pyinstall.msi /qb ADDLOCAL=ALL TARGETDIR="%LocalAppData%\Programs\Python\Python!foldername:~0,2!" + echo - msiexec /i pyinstall.msi /qb ADDLOCAL=ALL TARGETDIR="%LocalAppData%\Programs\Python\Python!foldername:~0,2!" msiexec /i pyinstall.msi /qb ADDLOCAL=ALL TARGETDIR="%LocalAppData%\Programs\Python\Python!foldername:~0,2!" ) popd -echo Installer finished with %ERRORLEVEL% status. +set "py_error=!errorlevel!" +echo Installer finished with status: !py_error! +echo Cleaning up... REM Now we should be able to delete the installer and check for py again del "%TEMP%\pyinstall.!pytype!" REM If it worked, then we should have python in our PATH @@ -301,12 +329,13 @@ exit /b :runscript REM Python found cls -set "args=%*" -set "args=!args:"=!" -if "!args!"=="" ( +REM Checks the args gathered at the beginning of the script. +REM Make sure we're not just forwarding empty quotes. +set "arg_test=!args:"=!" +if "!arg_test!"=="" ( "!pypath!" "!thisDir!!script_name!" ) else ( - "!pypath!" "!thisDir!!script_name!" %* + "!pypath!" "!thisDir!!script_name!" !args! ) if /i "!pause_on_error!" == "yes" ( if not "%ERRORLEVEL%" == "0" (