From 5f7d570b6533ae5f247f326a0c63a239652c43b2 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Sat, 5 Feb 2011 18:52:03 +0200 Subject: [PATCH] Add some code to the installer to uninstall the previous install of OpenLP. --- resources/windows/OpenLP-2.0.iss | 53 ++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/resources/windows/OpenLP-2.0.iss b/resources/windows/OpenLP-2.0.iss index 94ee4fc22..fbb36009a 100644 --- a/resources/windows/OpenLP-2.0.iss +++ b/resources/windows/OpenLP-2.0.iss @@ -86,3 +86,56 @@ Root: HKCU; SubKey: Software\OpenLP\OpenLP\presentations; ValueType: dword; Valu Root: HKCU; SubKey: Software\OpenLP\OpenLP\remotes; ValueType: dword; ValueName: status; ValueData: $00000001 Root: HKCU; SubKey: Software\OpenLP\OpenLP\songs; ValueType: dword; ValueName: status; ValueData: $00000001 Root: HKCU; SubKey: Software\OpenLP\OpenLP\songusage; ValueType: dword; ValueName: status; ValueData: $00000001 + + +[Code] +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; + +// Return Values: +// 1 - uninstall string is empty +// 2 - error executing the UnInstallString +// 3 - successfully executed the UnInstallString +function UnInstallOldVersion(): Integer; +var + sUnInstallString: String; + iResultCode: Integer; +begin + Result := 0; + 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;