From cd96935c6be29f3906da4cf2987deb819a844e3a Mon Sep 17 00:00:00 2001 From: haosicheng Date: Thu, 30 Oct 2025 09:25:07 +0800 Subject: [PATCH] =?UTF-8?q?[patch]=20=E5=A4=84=E7=90=86DY=E5=AE=89?= =?UTF-8?q?=E8=A3=85=E5=8C=85=E6=89=93=E5=8C=85=E5=90=8E=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E8=A7=86=E9=A2=91=E6=9A=82=E5=AD=98=E8=B7=AF=E5=BE=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98=20=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=BC=96=E7=A0=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto_updater.py | 61 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/auto_updater.py b/auto_updater.py index 9c2d4f4..81323c4 100644 --- a/auto_updater.py +++ b/auto_updater.py @@ -312,12 +312,33 @@ if NOT ERRORLEVEL 1 ( set /a count+=1 goto wait_main_exit ) else ( - echo WARN: Main program did not exit normally, forcing installation + echo WARN: Main program did not exit normally, forcing termination + taskkill /F /IM {exe_name} 2>nul ) ) echo OK: Main program exited echo. +REM Critical fix: Wait 2 seconds to ensure all file handles are released +echo INFO: Waiting for file handles to release... +timeout /t 2 /nobreak > nul +echo OK: File handles released +echo. + +REM Critical fix: Delete old _internal directory to force clean install +echo INFO: Removing old _internal directory... +if exist "{install_dir}\\_internal" ( + rd /s /q "{install_dir}\\_internal" 2>nul + if exist "{install_dir}\\_internal" ( + echo WARN: Failed to delete _internal directory + ) else ( + echo OK: Old _internal directory removed successfully + ) +) else ( + echo INFO: No old _internal directory found +) +echo. + REM Execute NSIS silent installation echo INFO: Starting installation... echo INFO: Installer: "{installer_path}" @@ -327,9 +348,9 @@ echo. REM Execute installation (with admin rights from NSIS) "{installer_path}" /S /D={install_dir} -REM Wait for installation to complete +REM Wait for installation to complete (extended to 35 seconds for full copy) echo INFO: Waiting for installation to complete... -timeout /t 25 /nobreak > nul +timeout /t 35 /nobreak > nul REM Cleanup installer echo INFO: Cleaning up installer... @@ -384,13 +405,13 @@ def create_restart_launcher(install_dir, exe_name): # 构建批处理脚本 script_content = f"""@echo off chcp 65001 > nul -title 水滴AI客服智能助手 - 更新助手 +title ShuiDi AI Assistant - Update Helper -echo [%time%] 正在更新水滴AI客服智能助手... +echo [%time%] Updating ShuiDi AI Assistant... echo. -REM 等待主程序退出(最多等待10秒) -echo [%time%] 等待主程序退出... +REM Wait for main program to exit (max 10 seconds) +echo [%time%] Waiting for main program to exit... set count=0 :wait_main_exit tasklist /FI "IMAGENAME eq {exe_name}" 2>NUL | find /I "{exe_name}" >NUL @@ -401,40 +422,40 @@ if NOT ERRORLEVEL 1 ( goto wait_main_exit ) ) -echo [%time%] 主程序已退出 +echo [%time%] Main program exited -REM 等待安装完成(15秒) -echo [%time%] 等待安装完成... +REM Wait for installation to complete (15 seconds) +echo [%time%] Waiting for installation to complete... timeout /t 15 /nobreak > nul -REM 清理旧的安装包 -echo [%time%] 清理临时文件... +REM Clean up old installer files +echo [%time%] Cleaning up temporary files... del /f /q "%TEMP%\\ShuiDi_AI_Assistant_Setup_*.exe" 2>nul -REM 启动新版本程序 -echo [%time%] 正在启动新版本... +REM Start new version +echo [%time%] Starting new version... cd /d "{install_dir}" if exist "{exe_name}" ( start "" "{install_dir}\\{exe_name}" - echo [%time%] ✅ 程序已启动 + echo [%time%] Program started successfully ) else ( - echo [%time%] ❌ 错误: 找不到程序文件 {exe_name} + echo [%time%] ERROR: Program file not found: {exe_name} pause ) -REM 延迟后删除自己 +REM Delete this script after delay timeout /t 2 /nobreak > nul del /f /q "%~f0" 2>nul exit """ - # 写入脚本文件(UTF-8 BOM编码,避免中文乱码) + # Write script file with UTF-8 BOM encoding try: with open(script_path, 'w', encoding='utf-8-sig') as f: f.write(script_content) - print(f"[Updater] 重启启动器已创建: {script_path}") + print(f"[Updater] Restart launcher created: {script_path}") except Exception as e: - print(f"[Updater] 创建重启启动器失败: {e}") + print(f"[Updater] Failed to create restart launcher: {e}") return script_path