From a96b5315e29c8547b49771c20d57b9a119bb33e3 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Wed, 19 Dec 2007 16:15:31 +0100 Subject: [PATCH] WinGit: Fix uninstall check regarding ssh-agent.exe Do not fail uninstall anymore if ssh-agent.exe does not exist, and restore ssh-agent.exe (which is deleted as a test if it is running) in case uninstall is aborted by the user by choosing "no" in the initial "Are you sure?"-style dialog. --- share/WinGit/install.iss | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/share/WinGit/install.iss b/share/WinGit/install.iss index caf2f555..c2ed8a19 100644 --- a/share/WinGit/install.iss +++ b/share/WinGit/install.iss @@ -437,13 +437,27 @@ end; function InitializeUninstall:Boolean; var - Msg:string; + FileName,NewName,Msg:string; begin - Result:=DeleteFile(ExpandConstant('{app}')+'\bin\ssh-agent.exe'); - if not Result then begin - Msg:='Line {#emit __LINE__}: Please stop all ssh-agent processes and run uninstall again.'; - MsgBox(Msg,mbError,MB_OK); - Log(Msg); + FileName:=ExpandConstant('{app}')+'\bin\ssh-agent.exe'; + if FileExists(FileName) then begin + // Create a temporary copy of the file we try to delete. + NewName:=FileName+'.'+IntToStr(1000+Random(9000)); + Result:=FileCopy(FileName,NewName,True) and DeleteFile(FileName); + + if not Result then begin + Msg:='Line {#emit __LINE__}: Please stop all ssh-agent processes and run uninstall again.'; + MsgBox(Msg,mbError,MB_OK); + Log(Msg); + + // Clean-up the temporary copy (ignoring any errors). + DeleteFile(NewName); + end else begin + // Clean-up the temporary copy (ignoring any errors). + RenameFile(NewName,FileName); + end; + end else begin + Result:=True; end; end; -- 2.11.4.GIT