fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #71868 - Mark-Simulacrum:stable-1.43.1, r=pietroalbini8d69840ab92

1.43.1
1.8 KiB61 linesraw
1// The following code taken from https://stackoverflow.com/questions/2000296/innosetup-how-to-automatically-uninstall-previous-installed-version
2// It performs upgrades by running the uninstaller before the install
3
4/////////////////////////////////////////////////////////////////////
5function GetUninstallString(): String;
6var
7  sUnInstPath: String;
8  sUnInstallString: String;
9begin
10  sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\Rust_is1');
11  sUnInstallString := '';
12  if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstallString) then
13    RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstallString);
14  Result := sUnInstallString;
15end;
16
17
18/////////////////////////////////////////////////////////////////////
19function IsUpgrade(): Boolean;
20begin
21  Result := (GetUninstallString() <> '');
22end;
23
24
25/////////////////////////////////////////////////////////////////////
26function UnInstallOldVersion(): Integer;
27var
28  sUnInstallString: String;
29  iResultCode: Integer;
30begin
31// Return Values:
32// 1 - uninstall string is empty
33// 2 - error executing the UnInstallString
34// 3 - successfully executed the UnInstallString
35
36  // default return value
37  Result := 0;
38
39  // get the uninstall string of the old app
40  sUnInstallString := GetUninstallString();
41  if sUnInstallString <> '' then begin
42    sUnInstallString := RemoveQuotes(sUnInstallString);
43    if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
44      Result := 3
45    else
46      Result := 2;
47  end else
48    Result := 1;
49end;
50
51/////////////////////////////////////////////////////////////////////
52procedure UpgradeCurStepChanged(CurStep: TSetupStep);
53begin
54  if (CurStep=ssInstall) then
55  begin
56    if (IsUpgrade()) then
57    begin
58      UnInstallOldVersion();
59    end;
60  end;
61end;