-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathClick To Launch MOTO.bat
More file actions
116 lines (107 loc) · 4.13 KB
/
Copy pathClick To Launch MOTO.bat
File metadata and controls
116 lines (107 loc) · 4.13 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
@echo off
setlocal EnableExtensions
set "SCRIPT_DIR=%~dp0"
set "LAUNCHER_SCRIPT=%SCRIPT_DIR%moto_launcher.py"
set "PYTHON_CMD="
call :find_python
if not defined PYTHON_CMD (
if defined MOTO_PYTHON_BOOTSTRAP_ATTEMPTED goto python_missing
echo.
echo Python 3.10+ was not found. MOTO will try to install Python 3.12 with winget.
echo.
call :install_python
if errorlevel 1 goto python_missing
set "MOTO_PYTHON_BOOTSTRAP_ATTEMPTED=1"
echo.
echo Python installation completed. Refreshing launcher environment...
call :refresh_environment
timeout /t 2 /nobreak >nul
call :find_python
if not defined PYTHON_CMD (
echo.
echo Python installed successfully, but this launcher window still cannot see it.
echo Restarting MOTO launcher in a fresh window...
start "" "%ComSpec%" /d /c call "%~f0" %*
exit /b 0
)
)
if not defined PYTHON_CMD goto python_missing
%PYTHON_CMD% "%LAUNCHER_SCRIPT%" %*
set "EXIT_CODE=%ERRORLEVEL%"
if %EXIT_CODE% NEQ 0 (
echo.
echo Press Enter to close...
pause >nul
)
exit /b %EXIT_CODE%
:find_python
call :check_python py -3.12
if defined PYTHON_CMD exit /b 0
call :check_python py -3.11
if defined PYTHON_CMD exit /b 0
call :check_python py -3.10
if defined PYTHON_CMD exit /b 0
call :check_python "%LocalAppData%\Programs\Python\Python312\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python "%LocalAppData%\Programs\Python\Python311\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python "%LocalAppData%\Programs\Python\Python310\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python "%ProgramFiles%\Python312\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python "%ProgramFiles%\Python311\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python "%ProgramFiles%\Python310\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python "%ProgramFiles(x86)%\Python312\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python "%ProgramFiles(x86)%\Python311\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python "%ProgramFiles(x86)%\Python310\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python python
if defined PYTHON_CMD exit /b 0
call :check_python py -3
if defined PYTHON_CMD exit /b 0
call :check_python "%LocalAppData%\Programs\Python\Python313\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python "%ProgramFiles%\Python313\python.exe"
if defined PYTHON_CMD exit /b 0
call :check_python "%ProgramFiles(x86)%\Python313\python.exe"
if defined PYTHON_CMD exit /b 0
exit /b 1
:check_python
%* -c "import sys; raise SystemExit(0 if sys.version_info >= (3, 10) else 1)" >nul 2>nul
if not errorlevel 1 set "PYTHON_CMD=%*"
exit /b 0
:install_python
where winget >nul 2>nul
if errorlevel 1 exit /b 1
winget install --id Python.Python.3.12 -e --source winget --scope user --accept-package-agreements --accept-source-agreements
if not errorlevel 1 exit /b 0
echo.
echo User-scope Python install did not complete. Trying the default winget install scope...
winget install --id Python.Python.3.12 -e --source winget --accept-package-agreements --accept-source-agreements
exit /b %ERRORLEVEL%
:refresh_environment
set "MOTO_USER_PATH="
set "MOTO_MACHINE_PATH="
for /f "tokens=1,2,*" %%A in ('reg query "HKCU\Environment" /v Path 2^>nul') do if /i "%%A"=="Path" set "MOTO_USER_PATH=%%C"
for /f "tokens=1,2,*" %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path 2^>nul') do if /i "%%A"=="Path" set "MOTO_MACHINE_PATH=%%C"
if defined MOTO_MACHINE_PATH call set "PATH=%%MOTO_MACHINE_PATH%%;%PATH%"
if defined MOTO_USER_PATH call set "PATH=%%MOTO_USER_PATH%%;%PATH%"
exit /b 0
:python_missing
echo.
echo ============================================================
echo ERROR: Python 3.10+ is required to launch MOTO.
echo ============================================================
echo.
echo Automatic Python installation was unavailable or did not complete.
echo Install Python 3.12 from https://www.python.org/downloads/
echo IMPORTANT: Check "Add Python to PATH" during installation.
echo.
start "" "https://www.python.org/downloads/"
echo Press Enter to close...
pause >nul
exit /b 1