cursor-free-vip/build.bat
2025-01-14 14:47:41 +08:00

62 lines
1.5 KiB
Batchfile
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
chcp 65001 > nul
cls
:: 檢查是否以管理員權限運行
net session >nul 2>&1
if %errorLevel% == 0 (
:: 如果是管理員權限,只創建虛擬環境後就降權運行
if not exist venv (
echo 正在創建虛擬環境...
python -m venv venv
)
:: 降權運行剩餘的步驟
echo 以普通用戶權限繼續...
powershell -Command "Start-Process -FilePath '%comspec%' -ArgumentList '/c cd /d %cd% && %~f0 run' -Verb RunAs:NO"
exit /b
) else (
:: 檢查是否是第二階段運行
if "%1"=="run" (
goto RUN_BUILD
) else (
:: 如果是普通權限且需要創建虛擬環境,請求管理員權限
if not exist venv (
echo ⚠️ 需要管理員權限來創建虛擬環境
echo 正在請求管理員權限...
powershell -Command "Start-Process -Verb RunAs -FilePath '%comspec%' -ArgumentList '/c cd /d %cd% && %~f0'"
exit /b
) else (
goto RUN_BUILD
)
)
)
:RUN_BUILD
echo 啟動虛擬環境...
call venv\Scripts\activate.bat
if errorlevel 1 (
echo ❌ 啟動虛擬環境失敗
pause
exit /b 1
)
:: 檢查並安裝缺失的依賴
echo 檢查依賴...
for /f "tokens=1" %%i in (requirements.txt) do (
pip show %%i >nul 2>&1 || (
echo 安裝 %%i...
pip install %%i
)
)
echo 開始構建...
python build.py
if errorlevel 1 (
echo ❌ 構建失敗
pause
exit /b 1
)
echo ✅ 完成!
pause