diff --git a/deploy/installer/Lea.iss b/deploy/installer/Lea.iss index a2ab2d63d..e6625df4b 100644 --- a/deploy/installer/Lea.iss +++ b/deploy/installer/Lea.iss @@ -587,12 +587,16 @@ end; // -------------------------------------------------------------------- function PrepareToInstall(var NeedsRestart: Boolean): String; var - LockPath: string; + AppDir, LockPath, BackupDir, SessionsDir: string; Lines: TArrayOfString; ResultCode: Integer; begin Result := ''; - LockPath := ExpandConstant('{app}\lea_agent.lock'); + AppDir := ExpandConstant('{app}'); + + // 1) Tuer une Lea en cours (via le PID du lock) pour liberer les DLL + // python-embed. Ne tue QUE ce PID, jamais tous les pythonw du poste. + LockPath := AppDir + '\lea_agent.lock'; if FileExists(LockPath) then begin if LoadStringsFromFile(LockPath, Lines) and (GetArrayLength(Lines) > 0) then @@ -600,6 +604,27 @@ begin DeleteFile(LockPath); Sleep(1500); end; + + // UPGRADE uniquement (install existante detectee via config.txt). + if FileExists(AppDir + '\config.txt') then + begin + // 2) BACKUP (rollback) : copie code+config vers _backup, HORS + // python-embed / sessions / logs (leger, rapide). Filet si la nouvelle + // version deconne : Julien restaure ce dossier. + BackupDir := AppDir + '_backup'; + Exec(ExpandConstant('{cmd}'), + '/c rmdir /s /q "' + BackupDir + '" 2>nul & robocopy "' + AppDir + '" "' + BackupDir + + '" /E /XD python-embed sessions logs __pycache__ /XF *.pyc /R:1 /W:1 /NFL /NDL /NJH /NJS /NP >nul 2>&1', + '', SW_HIDE, ewWaitUntilTerminated, ResultCode); + + // 3) PURGE des captures accumulees (donnees d'apprentissage internes, non + // exploitables cote clinique) : libere le disque. Le fix capture JPEG + // evite que la saturation reprenne. Les logs (compliance 180j) restent. + SessionsDir := AppDir + '\agent_v1\sessions'; + if DirExists(SessionsDir) then + Exec(ExpandConstant('{cmd}'), + '/c rmdir /s /q "' + SessionsDir + '"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode); + end; end; // --------------------------------------------------------------------