-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dist: Make Windows installer uninstall first. Closes #9563
This will remove existing files before installing new ones. Note that I took some code with no license from stackoverflow, as indicated in comments.
- Loading branch information
1 parent
a5dcbc6
commit 8f3c2a6
Showing
4 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// The following code taken from https://stackoverflow.com/questions/2000296/innosetup-how-to-automatically-uninstall-previous-installed-version | ||
// It performs upgrades by running the uninstaller before the install | ||
|
||
///////////////////////////////////////////////////////////////////// | ||
function GetUninstallString(): String; | ||
var | ||
sUnInstPath: String; | ||
sUnInstallString: String; | ||
begin | ||
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\Rust_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 UpgradeCurStepChanged(CurStep: TSetupStep); | ||
begin | ||
if (CurStep=ssInstall) then | ||
begin | ||
if (IsUpgrade()) then | ||
begin | ||
UnInstallOldVersion(); | ||
end; | ||
end; | ||
end; |