Files
tingquanzhushou/build.bat
huangzhenpc 2d603c33aa xxx
2025-05-17 18:16:24 +08:00

154 lines
4.1 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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
setlocal EnableDelayedExpansion
echo 开始正式版本打包...
:: 设置工作目录为脚本所在目录
cd /d "%~dp0"
:: 激活虚拟环境
if exist ".venv\Scripts\activate.bat" (
echo 激活虚拟环境...
call .venv\Scripts\activate.bat
) else (
echo 警告: 未找到虚拟环境,使用系统 Python
)
:: 确保安装了必要的包
echo Installing dependencies...
pip install -r requirements.txt
:: 读取版本号并处理格式
set /p VERSION=<version.txt
:: 移除版本号中的所有空格
set VERSION=!VERSION: =!
:: 分解版本号并增加 PATCH 版本
for /f "tokens=1-3 delims=." %%a in ("!VERSION!") do (
set MAJOR=%%a
set MINOR=%%b
set PATCH=%%c
:: 检查PATCH是否为9如果是则增加MINOR版本并重置PATCH为0
if "!PATCH!"=="9" (
set /a MINOR=!MINOR!+1
set PATCH=0
:: 检查MINOR是否为10如果是则增加MAJOR版本并重置MINOR为0
if "!MINOR!"=="10" (
set /a MAJOR=!MAJOR!+1
set MINOR=0
)
) else (
set /a PATCH=!PATCH!+1
)
)
:: 组合新版本号
set NEW_VERSION=!MAJOR!.!MINOR!.!PATCH!
echo Current version: !VERSION!
echo New version: !NEW_VERSION!
:: 保存新版本号
echo !NEW_VERSION!>version.txt
:: 清理旧的打包文件
echo Cleaning old files...
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 Starting packaging...
pyinstaller ^
--noconfirm ^
--clean ^
--onefile ^
--noconsole ^
--icon=two.ico ^
--name "听泉助手v!NEW_VERSION!" ^
--hidden-import json ^
--hidden-import sqlite3 ^
--hidden-import winreg ^
--hidden-import ctypes ^
--hidden-import platform ^
--hidden-import uuid ^
--hidden-import hashlib ^
--hidden-import datetime ^
--hidden-import urllib3 ^
--hidden-import requests ^
--hidden-import PyQt5 ^
--hidden-import PyQt5.sip ^
--hidden-import psutil ^
--hidden-import psutil._psutil_windows ^
--hidden-import psutil._pswindows ^
--collect-submodules psutil ^
--add-data "version.txt;." ^
--add-data "requirements.txt;." ^
--add-data "two.ico;." ^
--add-data "config.py;." ^
--add-data "logger.py;." ^
--add-data "common_utils.py;." ^
--add-data "cursor_token_refresher.py;." ^
--add-data "machine_resetter.py;." ^
--add-data "update_disabler.py;." ^
--add-data "exit_cursor.py;." ^
--add-data "gui;gui" ^
--add-data "services;services" ^
--add-data "utils;utils" ^
--exclude-module _tkinter ^
--exclude-module tkinter ^
--exclude-module PIL.ImageTk ^
--exclude-module PIL.ImageWin ^
--exclude-module numpy ^
--exclude-module pandas ^
--exclude-module matplotlib ^
--exclude "__pycache__" ^
--exclude "*.pyc" ^
--exclude "*.pyo" ^
--exclude "*.pyd" ^
--version-file file_version_info.txt ^
--uac-admin ^
tingquan_assistant.py
:: 检查打包结果
set BUILD_FILE=dist\听泉助手v!NEW_VERSION!.exe
if exist "!BUILD_FILE!" (
echo Build completed!
echo Version: v!NEW_VERSION!
echo File location: !BUILD_FILE!
:: 显示文件大小
for %%I in ("!BUILD_FILE!") do (
echo File size: %%~zI bytes
)
:: 更新 main_window.py 中的窗口标题
set MAIN_WINDOW_FILE=gui\windows\main_window.py
if exist "!MAIN_WINDOW_FILE!" (
echo Updating main_window.py...
powershell -Command "(Get-Content '!MAIN_WINDOW_FILE!') -replace '听泉助手 v\d+\.\d+\.\d+\.\d+', '听泉助手 v!NEW_VERSION!' | Set-Content '!MAIN_WINDOW_FILE!'"
) else (
echo Warning: main_window.py not found!
)
) else (
echo Error: Package failed, file does not exist
echo Expected file: !BUILD_FILE!
exit /b 1
)
:: 清理临时文件
echo Cleaning temporary files...
if exist "build" rd /s /q "build"
:: 退出虚拟环境
if exist ".venv\Scripts\activate.bat" (
echo Deactivating virtual environment...
deactivate
)
echo.
echo Press any key to exit...
pause >nul