Fixed installer problem when uninstall didn't work.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1895 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-05-22 08:41:40 +00:00
commit 3c61d87780

View file

@ -218,65 +218,75 @@ Name: "languages\zhTW"; Description: "繁體中文"; Types: Full; Check: hasLang
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
// The following uninstall code was found at: // The following uninstall code was found at:
// http://stackoverflow.com/questions/2000296/innosetup-how-to-automatically-uninstall-previous-installed-version // http://stackoverflow.com/questions/2000296/innosetup-how-to-automatically-uninstall-previous-installed-version
// and than modified to work in a 32/64 bit environment
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
function GetUninstallString(): String; function GetUninstallStrings(): array of String;
var var
sUnInstPath: String; sUnInstPath: String;
sUnInstallString: String; sUnInstallString: String;
asUninstallStrings : array of String;
index : Integer;
begin begin
sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1'); sUnInstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
sUnInstallString := ''; sUnInstallString := '';
// Retrieve uninstall string from HKLM(32/64) or HKCU(32/64) index := 0;
if not RegQueryStringValue(HKLM32, sUnInstPath, 'UninstallString', sUnInstallString) then
if not RegQueryStringValue(HKCU32, sUnInstPath, 'UninstallString', sUnInstallString) then
if IsWin64 then
if not RegQueryStringValue(HKLM64, sUnInstPath, 'UninstallString', sUnInstallString) then
RegQueryStringValue(HKCU64, sUnInstPath, 'UninstallString', sUnInstallString);
Result := sUnInstallString;
end;
// Retrieve uninstall string from HKLM32 or HKCU32
///////////////////////////////////////////////////////////////////// if RegQueryStringValue(HKLM32, sUnInstPath, 'UninstallString', sUnInstallString) then
function IsUpgrade(): Boolean;
begin begin
Result := (GetUninstallString() <> ''); SetArrayLength(asUninstallStrings, index + 1);
asUninstallStrings[index] := sUnInstallString;
index := index +1;
end;
if RegQueryStringValue(HKCU32, sUnInstPath, 'UninstallString', sUnInstallString) then
begin
SetArrayLength(asUninstallStrings, index + 1);
asUninstallStrings[index] := sUnInstallString;
index := index +1;
end;
// Only for Windows with 64 bit support: Retrieve uninstall string from HKLM64 or HKCU64
if IsWin64 then
begin
if RegQueryStringValue(HKLM64, sUnInstPath, 'UninstallString', sUnInstallString) then
begin
SetArrayLength(asUninstallStrings, index + 1);
asUninstallStrings[index] := sUnInstallString;
index := index +1;
end;
if RegQueryStringValue(HKCU64, sUnInstPath, 'UninstallString', sUnInstallString) then
begin
SetArrayLength(asUninstallStrings, index + 1);
asUninstallStrings[index] := sUnInstallString;
index := index +1;
end;
end;
Result := asUninstallStrings;
end; end;
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
function UnInstallOldVersion(): Integer; procedure UnInstallOldVersions();
var var
sUnInstallString: String; sUnInstallString: String;
iTries: Integer; index: Integer;
isUninstallMade: Boolean;
iResultCode : Integer; iResultCode : Integer;
asUninstallStrings : array of String;
begin begin
// Return Values: isUninstallMade := false;
// 1 - uninstall string is empty asUninstallStrings := GetUninstallStrings();
// 2 - error executing the UnInstallString for index := 0 to (GetArrayLength(asUninstallStrings) -1) do
// 3 - successfully executed the UnInstallString
// default return value
Result := 0;
iTries := 5;
// Uninstall while we find a uninstall string
while (Result <> 1) or (iTries = 0) do begin
iTries := iTries - 1;
// get the uninstall string of the old app
sUnInstallString := GetUninstallString();
if sUnInstallString <> '' then
begin begin
sUnInstallString := RemoveQuotes(sUnInstallString); sUnInstallString := RemoveQuotes(asUninstallStrings[index]);
if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
Result := 3 isUninstallMade := true;
else end;
Result := 2;
// Wait a few seconds to prevent installation issues, otherwise files are removed in one process while the other tries to link to them // Wait a few seconds to prevent installation issues, otherwise files are removed in one process while the other tries to link to them
if (isUninstallMade) then
Sleep(2000); Sleep(2000);
end else
begin
Result := 1;
end;
end;
end; end;
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
@ -284,10 +294,7 @@ procedure CurStepChanged(CurStep: TSetupStep);
begin begin
if (CurStep=ssInstall) then if (CurStep=ssInstall) then
begin begin
if (IsUpgrade()) then UnInstallOldVersions();
begin
UnInstallOldVersion();
end;
end; end;
end; end;
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////