From 079b80dbe041c94499b388eb1750e82ec88a7aac Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Wed, 19 May 2021 15:39:36 -0400 Subject: [PATCH] Handle CTRL+C --- innosetup.iss | 63 +++++++++++++++++++++++++++++++++++++++++++++++- opendm/system.py | 5 +++- 2 files changed, 66 insertions(+), 2 deletions(-) diff --git a/innosetup.iss b/innosetup.iss index 6b2ca6e5..945e1fee 100644 --- a/innosetup.iss +++ b/innosetup.iss @@ -87,4 +87,65 @@ begin begin ExtractTemporaryFile('vc_redist.x64.exe'); end; -end; \ No newline at end of file +end; + +function GetUninstallString(): String; +var + sUnInstPath: String; + sUnInstallString: String; +begin + sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1'); + sUnInstallString := ''; + if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then + RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString); + Result := sUnInstallString; +end; + +function IsUpgrade(): Boolean; +begin + Result := (GetUninstallString() <> ''); +end; + +function UnInstallOldVersion(): Integer; +var + sUnInstallString: String; + iResultCode: Integer; +begin +{ Return Values: } +{ 1 - uninstall string is empty } +{ 2 - error executing the UnInstallString } +{ 3 - successfully executed the UnInstallString } + + { default return value } + Result := 0; + + { get the uninstall string of the old app } + sUnInstallString := GetUninstallString(); + if sUnInstallString <> '' then begin + sUnInstallString := RemoveQuotes(sUnInstallString); + if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then + Result := 3 + else + Result := 2; + end else + Result := 1; +end; + +procedure CurStepChanged(CurStep: TSetupStep); +begin + if (CurStep=ssInstall) then + begin + if (IsUpgrade()) then + begin + UnInstallOldVersion(); + end; + end; +end; + +[UninstallDelete] +Type: filesandordirs; Name: "{app}\SuperBuild" +Type: filesandordirs; Name: "{app}\contrib" +Type: filesandordirs; Name: "{app}\licenses" +Type: filesandordirs; Name: "{app}\opendm" +Type: filesandordirs; Name: "{app}\stages" +Type: filesandordirs; Name: "{app}\venv" diff --git a/opendm/system.py b/opendm/system.py index af5e6c1b..657f5724 100644 --- a/opendm/system.py +++ b/opendm/system.py @@ -47,7 +47,10 @@ def exit_gracefully(): for sp in running_subprocesses: log.ODM_WARNING("Sending TERM signal to PID %s..." % sp.pid) - os.killpg(os.getpgid(sp.pid), signal.SIGTERM) + if sys.platform == 'win32': + os.kill(sp.pid, signal.CTRL_C_EVENT) + else: + os.killpg(os.getpgid(sp.pid), signal.SIGTERM) os._exit(1)