diff --git a/core/updater.py b/core/updater.py index 3b075b6..ef9d0f7 100644 --- a/core/updater.py +++ b/core/updater.py @@ -268,19 +268,23 @@ class UpdateChecker: bat_path = os.path.join(tmp_dir, "sm_update.bat") log_path = os.path.join(tmp_dir, "sm_update.log") pid = os.getpid() + new_size = os.path.getsize(new_exe) bat_content = f"""@echo off +setlocal enabledelayedexpansion chcp 65001 >nul 2>&1 set "LOGFILE={log_path}" set "SRC={new_exe}" set "DST={current_exe}" set "PID={pid}" set "TMPDIR={tmp_dir}" +set "EXPECTED_SIZE={new_size}" echo [%date% %time%] Update script started >> "%LOGFILE%" echo [%date% %time%] PID to wait for: %PID% >> "%LOGFILE%" echo [%date% %time%] SRC: %SRC% >> "%LOGFILE%" echo [%date% %time%] DST: %DST% >> "%LOGFILE%" +echo [%date% %time%] Expected size: %EXPECTED_SIZE% >> "%LOGFILE%" :wait_loop tasklist /FI "PID eq %PID%" 2>nul | find "%PID%" >nul @@ -300,17 +304,39 @@ for /d %%D in ("%TMPDIR%\\_MEI*") do ( ) timeout /t 1 /nobreak >nul -rem Copy with retry +rem Log source file size +for %%F in ("%SRC%") do ( + echo [%date% %time%] SRC file size: %%~zF >> "%LOGFILE%" +) + +rem Delete old DST first so copy is clean +echo [%date% %time%] Deleting old DST... >> "%LOGFILE%" +del /f /q "%DST%" >nul 2>&1 +if exist "%DST%" ( + echo [%date% %time%] WARNING: could not delete old DST >> "%LOGFILE%" +) +timeout /t 1 /nobreak >nul + +rem Copy with retry and size verification echo [%date% %time%] Starting copy... >> "%LOGFILE%" set COPIED=0 for /L %%i in (1,1,5) do ( if !COPIED!==0 ( - copy /Y "%SRC%" "%DST%" >nul 2>&1 + echo [%date% %time%] Copy attempt %%i... >> "%LOGFILE%" + copy /Y /B "%SRC%" "%DST%" >> "%LOGFILE%" 2>&1 if exist "%DST%" ( - echo [%date% %time%] Copy attempt %%i done >> "%LOGFILE%" - set COPIED=1 + for %%F in ("%DST%") do set DST_SIZE=%%~zF + echo [%date% %time%] DST size after copy: !DST_SIZE! >> "%LOGFILE%" + if "!DST_SIZE!"=="%EXPECTED_SIZE%" ( + echo [%date% %time%] Size verified OK >> "%LOGFILE%" + set COPIED=1 + ) else ( + echo [%date% %time%] Size mismatch! Expected %EXPECTED_SIZE%, got !DST_SIZE! >> "%LOGFILE%" + del /f /q "%DST%" >nul 2>&1 + timeout /t 2 /nobreak >nul + ) ) else ( - echo [%date% %time%] Copy attempt %%i failed >> "%LOGFILE%" + echo [%date% %time%] Copy failed - DST does not exist >> "%LOGFILE%" timeout /t 2 /nobreak >nul ) ) @@ -340,16 +366,12 @@ echo [%date% %time%] Cleanup done >> "%LOGFILE%" rem Self-delete del /f /q "%~f0" >nul 2>&1 """ - # Enable delayed expansion for variables inside for loops - bat_content = bat_content.replace("@echo off", - "@echo off\nsetlocal enabledelayedexpansion") - with open(bat_path, "w", encoding="utf-8") as f: f.write(bat_content) log.info(f"Update BAT: {bat_path}, log: {log_path}") - # Launch BAT minimized (not hidden — need cmd.exe to run) + # Launch BAT minimized subprocess.Popen( ["cmd.exe", "/c", "start", "/min", "", bat_path], creationflags=_SUBPROCESS_FLAGS, diff --git a/releases/ServerManager-v1.8.99-win-x64.exe b/releases/ServerManager-v1.8.99-win-x64.exe new file mode 100644 index 0000000..10993c9 Binary files /dev/null and b/releases/ServerManager-v1.8.99-win-x64.exe differ diff --git a/version.py b/version.py index 7be74a6..186af30 100755 --- a/version.py +++ b/version.py @@ -1,6 +1,6 @@ """Version info for ServerManager.""" -__version__ = "1.8.98" +__version__ = "1.8.99" __app_name__ = "ServerManager" __author__ = "aibot777" __description__ = "Desktop GUI for managing remote servers"