mirror of
https://github.com/greenshot/greenshot
synced 2025-08-20 13:33:27 -07:00
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:
parent
8c319fe0e4
commit
3c61d87780
1 changed files with 58 additions and 51 deletions
|
@ -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
|
||||||
|
begin
|
||||||
|
SetArrayLength(asUninstallStrings, index + 1);
|
||||||
|
asUninstallStrings[index] := sUnInstallString;
|
||||||
|
index := index +1;
|
||||||
|
end;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
if RegQueryStringValue(HKCU32, sUnInstPath, 'UninstallString', sUnInstallString) then
|
||||||
function IsUpgrade(): Boolean;
|
begin
|
||||||
begin
|
SetArrayLength(asUninstallStrings, index + 1);
|
||||||
Result := (GetUninstallString() <> '');
|
asUninstallStrings[index] := sUnInstallString;
|
||||||
end;
|
index := index +1;
|
||||||
|
end;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
// Only for Windows with 64 bit support: Retrieve uninstall string from HKLM64 or HKCU64
|
||||||
function UnInstallOldVersion(): Integer;
|
if IsWin64 then
|
||||||
var
|
begin
|
||||||
sUnInstallString: String;
|
if RegQueryStringValue(HKLM64, sUnInstPath, 'UninstallString', sUnInstallString) then
|
||||||
iTries: Integer;
|
|
||||||
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;
|
|
||||||
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);
|
SetArrayLength(asUninstallStrings, index + 1);
|
||||||
if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
|
asUninstallStrings[index] := sUnInstallString;
|
||||||
Result := 3
|
index := index +1;
|
||||||
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
|
if RegQueryStringValue(HKCU64, sUnInstPath, 'UninstallString', sUnInstallString) then
|
||||||
Sleep(2000);
|
|
||||||
end else
|
|
||||||
begin
|
begin
|
||||||
Result := 1;
|
SetArrayLength(asUninstallStrings, index + 1);
|
||||||
|
asUninstallStrings[index] := sUnInstallString;
|
||||||
|
index := index +1;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
Result := asUninstallStrings;
|
||||||
|
end;
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
procedure UnInstallOldVersions();
|
||||||
|
var
|
||||||
|
sUnInstallString: String;
|
||||||
|
index: Integer;
|
||||||
|
isUninstallMade: Boolean;
|
||||||
|
iResultCode : Integer;
|
||||||
|
asUninstallStrings : array of String;
|
||||||
|
begin
|
||||||
|
isUninstallMade := false;
|
||||||
|
asUninstallStrings := GetUninstallStrings();
|
||||||
|
for index := 0 to (GetArrayLength(asUninstallStrings) -1) do
|
||||||
|
begin
|
||||||
|
sUnInstallString := RemoveQuotes(asUninstallStrings[index]);
|
||||||
|
if Exec(sUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
|
||||||
|
isUninstallMade := true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// 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);
|
||||||
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;
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue