diff --git a/install.bat b/install.bat index 56fa224..1c522d5 100644 --- a/install.bat +++ b/install.bat @@ -64,14 +64,15 @@ echo. :: (no elevation) then fails silently and conda never installs. --scope user :: installs to %USERPROFILE%\miniforge3 with no admin needed — which is also one :: of the locations :rescan_conda searches. +:: winget returns non-zero when the package is already installed, so don't +:: trust the exit code -- rescan for conda and only fall through to the direct +:: download if it's genuinely still missing. Keep this comment outside the block: +:: a "::" line inside a ( ) block is a parse error. winget --version >nul 2>&1 if %errorlevel% equ 0 ( echo Installing via winget... winget install --id CondaForge.Miniforge3 --exact --silent --scope user ^ --accept-package-agreements --accept-source-agreements - :: winget returns non-zero when the package is already installed, so don't - :: trust the exit code — rescan for conda and only fall through to the - :: direct download if it's genuinely still missing. for %%C in ( "%LOCALAPPDATA%\miniforge3\Scripts\conda.exe" "%USERPROFILE%\miniforge3\Scripts\conda.exe" @@ -326,12 +327,16 @@ if %errorlevel% neq 0 ( echo WARNING: Could not install pytesseract Python wrapper. ) +:: Try winget machine scope, then user scope -- the latter needs no admin. +:: winget's exit code is unreliable, being non-zero when the package is already +:: installed, so after each attempt we re-resolve tesseract.exe instead of +:: trusting errorlevel. +:: NOTE: comments must stay OUTSIDE the parenthesised blocks below. A "::" line +:: inside a ( ) block is a parse error, and any parenthesis in the comment text +:: closes the block early. call :find_tesseract if not defined TESS_EXE ( echo Installing Tesseract OCR... - :: Try winget machine scope, then user scope (no admin needed). winget's - :: exit code is unreliable (non-zero when already installed), so after each - :: attempt we re-resolve tesseract.exe rather than trusting errorlevel. winget --version >nul 2>&1 if !errorlevel! equ 0 ( winget install --id tesseract-ocr.tesseract --exact --silent ^ @@ -347,6 +352,9 @@ if not defined TESS_EXE ( :: Last resort: direct download of the official NSIS installer and a per-user :: install. Covers clean Win10 machines with no winget and no admin rights. +:: The size check guards against a truncated download or an HTML error page; +:: the installer is ~50 MB. NSIS /D= must come last and unquoted, and breaks on +:: paths containing spaces, so it is only used when the target path has none. if not defined TESS_EXE ( echo winget unavailable or failed -- downloading Tesseract directly... set "TS_INSTALLER=%TEMP%\tesseract-setup.exe" @@ -358,12 +366,9 @@ if not defined TESS_EXE ( powershell -NoProfile -ExecutionPolicy Bypass -Command ^ "$ProgressPreference='SilentlyContinue'; try { Invoke-WebRequest -Uri '!TS_URL!' -OutFile '!TS_INSTALLER!' -UseBasicParsing; exit 0 } catch { exit 1 }" ) - :: Sanity-check the size (installer is ~50 MB) before executing it. set "TS_SIZE=0" if exist "!TS_INSTALLER!" for %%A in ("!TS_INSTALLER!") do set "TS_SIZE=%%~zA" if !TS_SIZE! GEQ 20971520 ( - :: NSIS /D= must be last and unquoted, and breaks on paths containing - :: spaces -- so only use it when the target path has none. echo !TS_DEST! | find " " >nul if !errorlevel! equ 0 ( start /wait "" "!TS_INSTALLER!" /S