diff --git a/build.bat b/build.bat index fc3f522..40ed820 100644 --- a/build.bat +++ b/build.bat @@ -9,15 +9,57 @@ python update_version.py set /p VERSION= 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 \ No newline at end of file diff --git a/gui/main_window.py b/gui/main_window.py index f0fbeb8..9f1b3c1 100644 --- a/gui/main_window.py +++ b/gui/main_window.py @@ -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) diff --git a/testbuild.bat b/testbuild.bat index 5df2f27..ce3595a 100644 --- a/testbuild.bat +++ b/testbuild.bat @@ -12,6 +12,12 @@ REM 读取当前版本号 set /p VERSION= 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= 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]: """下载更新文件 diff --git a/version.txt b/version.txt index 5141b61..3ec370e 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -3.4.4 \ No newline at end of file +3.4.5 \ No newline at end of file