mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:18:37 +00:00
When the old Launcher.bat runs --update from the console and git pull replaces it, cmd resumes in the new file's padding and reached 'exit /b 0', so a failed rebuild (code 7) was reported as 0. A plain 'exit /b' keeps the errorlevel. Checked by replaying the update in a throwaway clone: a failing build now exits 7, as the old file did; the clean update still exits 0 with no cmd error text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
140 lines
6.8 KiB
Batchfile
140 lines
6.8 KiB
Batchfile
@echo off
|
|
rem Double-click to open the launcher window: play, settings, mods, tools. It never touches the game package.
|
|
rem cmd reads a batch file line by line from the byte where it stopped: when the launcher's Update replaces this
|
|
rem file while it runs, cmd goes on at that byte of the new file. The :: lines below (labels: cmd skips them, from
|
|
rem any byte) cover where the older Launcher.bat stopped (byte 749), and lead to a clean exit. Keep them.
|
|
goto :start
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
exit /b
|
|
:start
|
|
title Leonida - Launcher
|
|
rem It needs Python 3.12 or newer with Tcl/Tk (the window). Without one it offers to install Python 3.12 for this
|
|
rem user (no admin), as Build.bat does. LEONIDA_PY_INSTALL_DRYRUN=1 prints the install commands and skips them.
|
|
setlocal
|
|
cd /d "%~dp0"
|
|
set "PY_EXE="
|
|
set "PY_ARG="
|
|
set "PY_NOTK="
|
|
call :find_python
|
|
if not defined PY_EXE call :find_user_python
|
|
if not defined PY_EXE call :offer_python
|
|
if not defined PY_EXE (
|
|
echo.
|
|
if defined PY_NOTK (
|
|
echo Python was found, but without Tcl/Tk, which the launcher's window needs.
|
|
echo Install Python 3.12 or newer from https://www.python.org/downloads/ with "tcl/tk and IDLE" ticked
|
|
echo ^(Customize installation^), or run its installer again and choose Modify to add it.
|
|
) else (
|
|
echo Python 3.12 or newer is needed: https://www.python.org/downloads/
|
|
echo Tick "Add python.exe to PATH" during setup.
|
|
)
|
|
if not defined LEONIDA_NO_PAUSE pause
|
|
exit /b 1
|
|
)
|
|
rem One line, read whole before the launcher runs: an update that replaces this file cannot change what follows,
|
|
rem the error path included (its code, git's or the build's with --update, goes back to the caller).
|
|
"%PY_EXE%" %PY_ARG% -I "%~dp0tools\leonida_launcher.py" %* && exit /b 0 || (call set "RC=%%errorlevel%%" & setlocal EnableDelayedExpansion & echo. & echo The launcher stopped with code !RC!. Read the message above. & (if not defined LEONIDA_NO_PAUSE pause) & exit /b !RC!)
|
|
|
|
rem ---- Helpers (only reached by "call"; the script exits above) ----
|
|
|
|
|
|
rem The py launcher's versions, newest first, then python on PATH: the first that is 3.12 or newer and has Tk.
|
|
:find_python
|
|
for %%V in (3.14 3.13 3.12 3) do call :try_py %%V
|
|
if defined PY_EXE exit /b 0
|
|
where python >nul 2>nul || exit /b 0
|
|
call :try_python python
|
|
exit /b 0
|
|
|
|
:try_py
|
|
if defined PY_EXE exit /b 0
|
|
py -%1 -c "import sys; sys.exit(0 if sys.version_info >= (3, 12) else 1)" >nul 2>nul || exit /b 0
|
|
py -%1 -c "import tkinter; tkinter.Tcl()" >nul 2>nul || (set "PY_NOTK=1" & exit /b 0)
|
|
set "PY_EXE=py"
|
|
set "PY_ARG=-%1"
|
|
exit /b 0
|
|
|
|
rem Each per-user install under %LOCALAPPDATA%\Programs\Python (python.org or winget with "Add to PATH" unticked),
|
|
rem highest folder name first; each one is checked, so the name order does not matter.
|
|
:find_user_python
|
|
for /f "delims=" %%D in ('dir /b /ad /o-n "%LOCALAPPDATA%\Programs\Python\Python3*" 2^>nul') do call :try_python "%LOCALAPPDATA%\Programs\Python\%%D\python.exe"
|
|
exit /b 0
|
|
|
|
:try_python
|
|
if defined PY_EXE exit /b 0
|
|
if /i not "%~1"=="python" if not exist "%~1" exit /b 0
|
|
"%~1" -c "import sys; sys.exit(0 if sys.version_info >= (3, 12) else 1)" >nul 2>nul || exit /b 0
|
|
"%~1" -c "import tkinter; tkinter.Tcl()" >nul 2>nul || (set "PY_NOTK=1" & exit /b 0)
|
|
set "PY_EXE=%~1"
|
|
set "PY_ARG="
|
|
exit /b 0
|
|
|
|
rem Ask first, then install Python 3.12 (with Tcl/Tk) for this user only: winget if present, else the pinned
|
|
rem python.org installer checked against its SHA-256 (the same one Build.bat uses). On "No" or any failure PY_EXE
|
|
rem stays unset and the caller prints the manual instructions.
|
|
:offer_python
|
|
echo.
|
|
if defined PY_NOTK (
|
|
echo Python was found without Tcl/Tk, which the launcher's window needs.
|
|
) else (
|
|
echo Python 3.12 or newer was not found, and the launcher needs it.
|
|
)
|
|
choice /c YN /n /t 60 /d N /m "Download and install Python 3.12 with Tcl/Tk for your user account now? (No admin needed) [Y/N] "
|
|
if errorlevel 2 exit /b 0
|
|
if not errorlevel 1 exit /b 0
|
|
where winget >nul 2>nul && goto :py_winget
|
|
:py_download
|
|
set "PYURL=https://www.python.org/ftp/python/3.12.10/python-3.12.10-amd64.exe"
|
|
set "PYSHA=67B5635E80EA51072B87941312D00EC8927C4DB9BA18938F7AD2D27B328B95FB"
|
|
set "PYTMP=%TEMP%"
|
|
if not defined PYTMP set "PYTMP=%LOCALAPPDATA%\Temp"
|
|
if not defined PYTMP set "PYTMP=%~dp0"
|
|
set "PYEXE=%PYTMP%\leonida-python-3.12.10-amd64.exe"
|
|
if defined LEONIDA_PY_INSTALL_DRYRUN goto :py_dry_download
|
|
echo Downloading Python 3.12.10 from python.org ...
|
|
powershell -NoProfile -Command "$ErrorActionPreference='Stop'; $ProgressPreference='SilentlyContinue'; [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -UseBasicParsing -Uri $env:PYURL -OutFile $env:PYEXE; if ((Get-FileHash -Algorithm SHA256 -LiteralPath $env:PYEXE).Hash -ine $env:PYSHA) { Remove-Item -LiteralPath $env:PYEXE -Force; exit 3 }"
|
|
if errorlevel 1 goto :py_download_failed
|
|
echo Installing Python 3.12.10 ...
|
|
start "" /wait "%PYEXE%" /quiet InstallAllUsers=0 PrependPath=1 Include_launcher=1 Include_tcltk=1
|
|
del /q "%PYEXE%" >nul 2>nul
|
|
goto :py_installed
|
|
|
|
:py_download_failed
|
|
echo The download failed or did not match its checksum, so it was not run.
|
|
del /q "%PYEXE%" >nul 2>nul
|
|
exit /b 0
|
|
|
|
:py_dry_download
|
|
echo [dry run] would download %PYURL%
|
|
echo [dry run] would check SHA-256 %PYSHA%
|
|
echo [dry run] would run "%PYEXE%" /quiet InstallAllUsers=0 PrependPath=1 Include_launcher=1 Include_tcltk=1
|
|
exit /b 0
|
|
|
|
:py_winget
|
|
set "PYWG=winget install --id Python.Python.3.12 -e --scope user --silent --accept-package-agreements --accept-source-agreements"
|
|
if defined LEONIDA_PY_INSTALL_DRYRUN goto :py_dry_winget
|
|
echo Installing Python 3.12 with winget ...
|
|
call %PYWG%
|
|
call :find_user_python
|
|
if defined PY_EXE exit /b 0
|
|
echo winget did not install a Python with Tcl/Tk; trying the python.org installer instead.
|
|
goto :py_download
|
|
|
|
:py_dry_winget
|
|
echo [dry run] would run %PYWG%
|
|
goto :py_download
|
|
|
|
:py_installed
|
|
call :find_user_python
|
|
exit /b 0
|