优化更新: 1. 修复版本显示和检查逻辑 2. 优化打包目录结构为两位版本号(3.4.4 -> 3.4)

This commit is contained in:
huangzhenpc
2025-02-13 20:38:49 +08:00
parent dd0a307ff4
commit 10523de040
5 changed files with 137 additions and 24 deletions

View File

@@ -9,15 +9,57 @@ python update_version.py
set /p VERSION=<version.txt
echo 当前版本: %VERSION%
:: 提取主版本号和次版本号 (3.4.4 -> 3.4)
for /f "tokens=1,2 delims=." %%a in ("%VERSION%") do (
set MAJOR_VERSION=%%a.%%b
)
echo 主版本目录: %MAJOR_VERSION%
:: 创建版本目录
set VERSION_DIR=dist\%VERSION%
if not exist "%VERSION_DIR%" mkdir "%VERSION_DIR%"
set VERSION_DIR=dist\%MAJOR_VERSION%
if not exist "%VERSION_DIR%" (
mkdir "%VERSION_DIR%"
echo 创建目录: %VERSION_DIR%
)
:: 使用新的spec文件进行打包
pyinstaller --noconfirm build_nezha.spec
:: 移动文件到版本目录
move "dist\听泉cursor助手%VERSION%.exe" "%VERSION_DIR%\听泉cursor助手v%VERSION%.exe"
:: 检查源文件是否存在
echo 检查文件: dist\听泉cursor助手%VERSION%.exe
if not exist "dist\听泉cursor助手%VERSION%.exe" (
echo 错误: 打包后的文件不存在
echo 预期文件路径: dist\听泉cursor助手%VERSION%.exe
dir /b dist
pause
exit /b 1
)
echo 打包完成!文件保存在: %VERSION_DIR%
:: 检查目标目录是否存在
echo 检查目标目录: %VERSION_DIR%
if not exist "%VERSION_DIR%" (
echo 错误: 目标目录不存在
pause
exit /b 1
)
:: 移动文件到版本目录
echo 移动文件:
echo 源文件: dist\听泉cursor助手%VERSION%.exe
echo 目标文件: %VERSION_DIR%\听泉cursor助手v%VERSION%.exe
move "dist\听泉cursor助手%VERSION%.exe" "%VERSION_DIR%\听泉cursor助手v%VERSION%.exe"
if errorlevel 1 (
echo 移动文件失败,请检查:
echo 1. 源文件是否存在: dist\听泉cursor助手%VERSION%.exe
echo 2. 目标目录是否可写: %VERSION_DIR%
echo 3. 目标文件是否已存在: %VERSION_DIR%\听泉cursor助手v%VERSION%.exe
dir /b dist
dir /b "%VERSION_DIR%"
pause
exit /b 1
)
echo.
echo 打包完成!
echo 文件保存在: %VERSION_DIR%\听泉cursor助手v%VERSION%.exe
pause

View File

@@ -1639,7 +1639,7 @@ class MainWindow(QMainWindow):
self.show_custom_message(
"检查更新",
"已是最新版本",
"您当前使用的已经是最新版本。",
f"您当前使用的 v{self.version_manager.current_version} 已经是最新版本。",
QStyle.SP_DialogApplyButton,
"#198754"
)
@@ -1693,7 +1693,8 @@ class MainWindow(QMainWindow):
version_layout.addWidget(current_version_label)
# 最新版本
new_version_label = QLabel(f"最新版本v{version_info.get('version_no', '未知')} ({version_info.get('version_name', '未知')})")
new_version = version_info.get('version_no', '未知').lstrip('v')
new_version_label = QLabel(f"最新版本v{new_version} ({version_info.get('version_name', '未知')})")
new_version_label.setStyleSheet("font-weight: bold; color: #0d6efd;")
version_layout.addWidget(new_version_label)

View File

@@ -12,6 +12,12 @@ REM 读取当前版本号
set /p VERSION=<version.txt
echo 当前正式版本: %VERSION%
REM 提取主版本号和次版本号 (3.4.4 -> 3.4)
for /f "tokens=1,2 delims=." %%a in ("%VERSION%") do (
set MAJOR_VERSION=%%a.%%b
)
echo 主版本目录: %MAJOR_VERSION%
REM 读取测试版本号(如果存在)
if exist testversion.txt (
set /p TEST_VERSION=<testversion.txt
@@ -29,8 +35,11 @@ set FULL_VERSION=%VERSION%.!TEST_VERSION!
echo 完整版本号: !FULL_VERSION!
REM 创建测试版本输出目录
set TEST_DIR=dist\test\%VERSION%
if not exist "!TEST_DIR!" mkdir "!TEST_DIR!"
set TEST_DIR=dist\test\%MAJOR_VERSION%
if not exist "!TEST_DIR!" (
mkdir "!TEST_DIR!"
echo 创建目录: !TEST_DIR!
)
REM 清理旧文件
if exist "dist\听泉cursor助手%VERSION%.exe" del "dist\听泉cursor助手%VERSION%.exe"
@@ -39,8 +48,31 @@ if exist "build" rmdir /s /q "build"
REM 执行打包
venv\Scripts\python.exe -m PyInstaller build_nezha.spec --clean
REM 检查源文件是否存在
echo 检查文件: dist\听泉cursor助手%VERSION%.exe
if not exist "dist\听泉cursor助手%VERSION%.exe" (
echo 错误: 打包后的文件不存在
echo 预期文件路径: dist\听泉cursor助手%VERSION%.exe
dir /b dist
pause
exit /b 1
)
REM 移动并重命名文件
echo 移动文件:
echo 源文件: dist\听泉cursor助手%VERSION%.exe
echo 目标文件: !TEST_DIR!\听泉cursor助手v!FULL_VERSION!.exe
move "dist\听泉cursor助手%VERSION%.exe" "!TEST_DIR!\听泉cursor助手v!FULL_VERSION!.exe"
if errorlevel 1 (
echo 移动文件失败,请检查:
echo 1. 源文件是否存在: dist\听泉cursor助手%VERSION%.exe
echo 2. 目标目录是否可写: !TEST_DIR!
echo 3. 目标文件是否已存在: !TEST_DIR!\听泉cursor助手v!FULL_VERSION!.exe
dir /b dist
dir /b "!TEST_DIR!"
pause
exit /b 1
)
echo.
echo 测试版本构建完成!

View File

@@ -6,6 +6,7 @@ from typing import Optional, Dict, Any
import json
import logging
from urllib.parse import quote, unquote
from pathlib import Path
class VersionManager:
"""版本管理器
@@ -20,15 +21,25 @@ class VersionManager:
def __init__(self):
self.base_url = "https://cursorapi.nosqli.com"
# 获取项目根目录路径
self.root_path = Path(__file__).parent.parent
self.current_version = self._get_current_version()
self.platform = "windows" if sys.platform.startswith("win") else "mac" if sys.platform.startswith("darwin") else "linux"
def _get_current_version(self) -> str:
"""获取当前版本号"""
try:
with open("version.txt", "r") as f:
return f.read().strip()
except FileNotFoundError:
version_file = self.root_path / "version.txt"
if not version_file.exists():
logging.error(f"版本文件不存在: {version_file}")
return "0.0.0"
with open(version_file, "r", encoding="utf-8") as f:
version = f.read().strip()
logging.info(f"当前版本: {version}")
return version
except Exception as e:
logging.error(f"读取版本号失败: {str(e)}")
return "0.0.0"
def _handle_response(self, response: requests.Response) -> Dict[str, Any]:
@@ -82,8 +93,10 @@ class VersionManager:
"""检查是否有更新"""
try:
url = f"{self.base_url}/admin/api.version/check"
current_version = self.current_version.lstrip('v') # 移除可能存在的v前缀
params = {
"version": self.current_version,
"version": current_version,
"platform": self.platform
}
logging.info(f"正在请求: {url}")
@@ -99,7 +112,19 @@ class VersionManager:
logging.info(f"响应头: {dict(response.headers)}")
logging.info(f"响应内容: {response.text}")
return self._handle_response(response)
result = self._handle_response(response)
# 确保返回的数据包含版本信息
if result["code"] == 0 and result.get("data"):
data = result["data"]
if "version_info" in data:
version_info = data["version_info"]
# 确保版本号格式一致
if "version_no" in version_info:
version_info["version_no"] = version_info["version_no"].lstrip('v')
return result
except requests.exceptions.Timeout:
logging.error("检查更新超时")
return {"code": -1, "msg": "请求超时,请检查网络连接", "data": None}
@@ -145,15 +170,28 @@ class VersionManager:
Returns:
tuple: (是否有更新, 是否强制更新, 版本信息)
"""
result = self.check_update()
if result["code"] == 0 and result["data"]:
data = result["data"]
return (
data["has_update"],
bool(data.get("is_force")),
data.get("version_info")
)
return False, False, None
try:
result = self.check_update()
if result["code"] == 0 and result["data"]:
data = result["data"]
version_info = data.get("version_info", {})
# 比较版本号(移除v前缀)
current = self.current_version.lstrip('v')
latest = version_info.get("version_no", "0.0.0").lstrip('v')
# 使用packaging.version进行版本比较
has_update = version.parse(latest) > version.parse(current)
return (
has_update,
bool(data.get("is_force")),
version_info
)
return False, False, None
except Exception as e:
logging.error(f"检查更新失败: {str(e)}")
return False, False, None
def download_update(self, download_url: str, save_path: str) -> tuple[bool, str]:
"""下载更新文件

View File

@@ -1 +1 @@
3.4.4
3.4.5