添加项目源代码

This commit is contained in:
huangzhenpc
2025-02-20 20:20:19 +08:00
parent 7c63d8a390
commit 268a32f78f
76 changed files with 3344 additions and 0 deletions

113
build.bat Normal file
View File

@@ -0,0 +1,113 @@
@echo off
chcp 65001
setlocal EnableDelayedExpansion
echo 开始正式版本打包...
:: 设置工作目录为脚本所在目录
cd /d "%~dp0"
:: 激活虚拟环境
if exist "venv\Scripts\activate.bat" (
echo 激活虚拟环境...
call venv\Scripts\activate.bat
) else (
echo 警告: 未找到虚拟环境,使用系统 Python
)
:: 确保安装了必要的包
echo 检查依赖包...
python -c "import PyInstaller" >nul 2>&1
if errorlevel 1 (
echo 正在安装 PyInstaller...
python -m pip install pyinstaller -i https://pypi.tuna.tsinghua.edu.cn/simple
)
:: 如果存在requirements.txt安装依赖
if exist "requirements.txt" (
echo 安装项目依赖...
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
)
:: 设置基础变量
set VERSION_FILE=version.txt
set SPEC_FILE=tingquan_assistant.spec
:: 读取版本号
set /p VERSION=<%VERSION_FILE%
echo 当前版本: !VERSION!
:: 提取主版本号和次版本号 (4.0.0.1 -> 4.0)
for /f "tokens=1,2 delims=." %%a in ("!VERSION!") do (
set MAJOR_VERSION=%%a.%%b
)
echo 主版本目录: !MAJOR_VERSION!
:: 创建版本目录
set VERSION_DIR=dist\!MAJOR_VERSION!
if not exist "!VERSION_DIR!" (
mkdir "!VERSION_DIR!"
echo 创建目录: !VERSION_DIR!
)
:: 清理 Python 缓存文件
echo 清理Python缓存文件...
for /d /r . %%d in (__pycache__) do @if exist "%%d" rd /s /q "%%d"
del /s /q *.pyc >nul 2>&1
del /s /q *.pyo >nul 2>&1
:: 清理旧的打包文件
echo 清理旧文件...
taskkill /F /IM "听泉助手*.exe" >nul 2>&1
timeout /t 2 /nobreak >nul
if exist "build" rd /s /q "build"
if exist "dist" rd /s /q "dist"
:: 使用优化选项进行打包
echo 开始打包...
python -m PyInstaller !SPEC_FILE! --noconfirm --clean
:: 检查打包结果并移动文件
set BUILD_DIR=dist\听泉助手v!VERSION!
set TARGET_FILE=!VERSION_DIR!\听泉助手v!VERSION!.exe
echo 检查构建目录: !BUILD_DIR!
if exist "!BUILD_DIR!" (
echo 正式版本打包成功!
:: 创建目标目录(如果不存在)
if not exist "!VERSION_DIR!" mkdir "!VERSION_DIR!"
:: 移动整个目录到版本目录
echo 移动文件到: !VERSION_DIR!
xcopy "!BUILD_DIR!\*" "!VERSION_DIR!" /E /I /Y
:: 显示文件大小
for %%I in ("!TARGET_FILE!") do (
echo 文件大小: %%~zI 字节
)
echo.
echo 正式版本构建完成!
echo 版本号: v!VERSION!
echo 文件位置: !TARGET_FILE!
) else (
echo 错误: 打包失败,构建目录不存在
echo 预期构建目录: !BUILD_DIR!
dir /b dist
exit /b 1
)
:: 清理临时文件
echo 清理临时文件...
if exist "build" rd /s /q "build"
if exist "dist" rd /s /q "dist"
:: 退出虚拟环境
if exist "venv\Scripts\activate.bat" (
echo 退出虚拟环境...
deactivate
)
echo.
echo 按任意键退出...
pause >nul