122 lines
3.3 KiB
Batchfile
122 lines
3.3 KiB
Batchfile
@echo off
|
|
chcp 65001 >nul
|
|
cd /d "%~dp0"
|
|
set "ROOT=%~dp0.."
|
|
set "TOOLS=%ROOT%\tools"
|
|
set "ICON=%~dp0app.ico"
|
|
set NAME=UNI-T-multi-lan-installer
|
|
set SRC=UNI-T-multi-lan-installer.py
|
|
title %NAME% - Build
|
|
|
|
echo ============================================================
|
|
echo %NAME% - Cython Build
|
|
echo ============================================================
|
|
echo.
|
|
|
|
where python >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [ERROR] Python not found
|
|
pause
|
|
exit /b
|
|
)
|
|
for /f "delims=" %%i in ('where python') do set PY=%%i
|
|
echo Python: %PY%
|
|
|
|
echo [1/6] Installing deps...
|
|
%PY% -m pip install pyinstaller cython pyzipper -q
|
|
if errorlevel 1 (
|
|
%PY% -m pip install pyinstaller cython pyzipper -q -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
)
|
|
|
|
echo [2/7] Clean...
|
|
if exist "dist_cy" rmdir /s /q dist_cy 2>nul
|
|
if exist "build" rmdir /s /q build 2>nul
|
|
if exist "dist" rmdir /s /q dist 2>nul
|
|
|
|
echo [3/7] Checking resources...
|
|
if not exist "%ICON%" (
|
|
echo [ERROR] app.ico not found in UNI-T folder: %ICON%
|
|
pause
|
|
exit /b 1
|
|
)
|
|
if not exist "%TOOLS%\adb.exe" (
|
|
echo [ERROR] Missing ADB file: %TOOLS%\adb.exe
|
|
pause
|
|
exit /b 1
|
|
)
|
|
if not exist "%TOOLS%\AdbWinApi.dll" (
|
|
echo [ERROR] Missing ADB file: %TOOLS%\AdbWinApi.dll
|
|
pause
|
|
exit /b 1
|
|
)
|
|
if not exist "%TOOLS%\AdbWinUsbApi.dll" (
|
|
echo [ERROR] Missing ADB file: %TOOLS%\AdbWinUsbApi.dll
|
|
pause
|
|
exit /b 1
|
|
)
|
|
if not exist "%TOOLS%\7za.exe" (
|
|
echo [ERROR] Missing 7za file: %TOOLS%\7za.exe
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo [4/7] Cython compile...
|
|
mkdir dist_cy 2>nul
|
|
copy %SRC% dist_cy\_core.py >nul
|
|
set "PYD="
|
|
|
|
%PY% -c "open('dist_cy/setup_cython.py','w').write('from setuptools import setup\nfrom Cython.Build import cythonize\nsetup(ext_modules=cythonize(\"_core.py\", compiler_directives={\"language_level\":\"3\"}))\n')"
|
|
|
|
cd dist_cy
|
|
%PY% setup_cython.py build_ext --inplace
|
|
if errorlevel 1 (
|
|
cd ..
|
|
echo [ERROR] Cython build failed. Install Microsoft C++ Build Tools and retry.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
for %%f in (_core*.pyd) do set PYD=%%f
|
|
if "%PYD%"=="" (
|
|
cd ..
|
|
echo [ERROR] Cython build did not generate _core*.pyd. Stop.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
echo PYD: %PYD%
|
|
copy "%PYD%" _core.pyd >nul
|
|
|
|
%PY% -c "open('launcher.py','w').write('# -*- coding: utf-8 -*-\nfrom _core import main\nmain()\n')"
|
|
|
|
echo [5/7] Copy resources...
|
|
copy "%TOOLS%\adb.exe" . >nul
|
|
copy "%TOOLS%\AdbWinApi.dll" . >nul
|
|
copy "%TOOLS%\AdbWinUsbApi.dll" . >nul
|
|
copy "%TOOLS%\7za.exe" . >nul
|
|
copy "%ICON%" . >nul
|
|
|
|
echo [6/7] PyInstaller...
|
|
%PY% -m PyInstaller --onefile --windowed --name="%NAME%" --icon="%ICON%" --add-data "%ICON%;." --add-data "%TOOLS%\adb.exe;." --add-data "%TOOLS%\AdbWinApi.dll;." --add-data "%TOOLS%\AdbWinUsbApi.dll;." --add-data "%TOOLS%\7za.exe;." --add-binary "_core.pyd;." --hidden-import=queue --hidden-import=threading --hidden-import=tkinter --hidden-import=tkinter.simpledialog --hidden-import=zipfile --hidden-import=json --hidden-import=urllib --hidden-import=urllib.parse --collect-all tkinter --uac-admin launcher.py
|
|
if errorlevel 1 (
|
|
cd ..
|
|
echo [ERROR] PyInstaller failed
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo [7/7] Cleanup...
|
|
del /q _core.py _core.c _core.pyd %PYD% launcher.py setup_cython.py 2>nul
|
|
rmdir /s /q build 2>nul
|
|
cd ..
|
|
goto :DONE
|
|
|
|
:DONE
|
|
echo.
|
|
echo Done.
|
|
if exist "dist_cy\dist\%NAME%.exe" (
|
|
echo Output: dist_cy\dist\%NAME%.exe
|
|
) else (
|
|
echo Check dist folder
|
|
)
|
|
pause
|