Skip to content

Commit 6717a47

Browse files
committed
1) Run the uninstaller first only if the v8 version is already installed.
2) Delete the MyAppVersion key from the Windows registry during the installation or upgrade. 3) Remove the logic that checks if a 32-bit or 64-bit version of the installer is already installed.
1 parent 2f49500 commit 6717a47

File tree

1 file changed

+65
-57
lines changed

1 file changed

+65
-57
lines changed

pkg/win32/installer.iss.in

Lines changed: 65 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
#define MyAppArchitecturesMode "x64"
99
#define MyAppVCDist MYAPP_VCDIST
1010
#define MyAppInvalidPath "Please provide a valid path."
11-
#define MyAppErrorMsgIsWin32 "You already have a 32 bit installation of pgAdmin 4. Please uninstall this before installing the 64 bit version."
12-
#define MyAppErrorMsgIsWin64 "You already have a 64 bit installation of pgAdmin 4. Please uninstall this before installing the 32 bit version."
1311
#define MinimumWindowsVer "6.2.9200"
12+
#define CheckOldInstallerVersion "v8"
1413

1514
[Setup]
1615
AppId={#MyAppName}{#MyAppVersion}
@@ -51,7 +50,7 @@ english.NewerVersionExists=A newer version of {#MyAppName}
5150
english.InvalidPath={#MyAppInvalidPath}
5251

5352
[Icons]
54-
Name: {group}\{#MyAppName} {#MyAppVersion}; Filename: {app}\runtime\{#MyAppExeName}; IconFilename: {app}\pgAdmin4.ico; WorkingDir: {app}\runtime;
53+
Name: {group}\{#MyAppName}; Filename: {app}\runtime\{#MyAppExeName}; IconFilename: {app}\pgAdmin4.ico; WorkingDir: {app}\runtime;
5554

5655
[Files]
5756
Source: "..\..\win-build\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs;
@@ -60,10 +59,10 @@ Source: "..\..\win-build\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdi
6059
Filename: "{app}\installer\{#MyAppVCDist}"; StatusMsg: "VC runtime redistributable package"; Parameters: "/passive /verysilent /norestart"; Check: InstallVC;
6160

6261
[Registry]
63-
Root: HKA; Subkey: "Software\{#MyAppName}\{#MyAppVersion}"; Flags: uninsdeletekeyifempty
64-
Root: HKA; Subkey: "Software\{#MyAppName}\{#MyAppVersion}"; Flags: uninsdeletekey
65-
Root: HKA; Subkey: "Software\{#MyAppName}\{#MyAppVersion}"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
66-
Root: HKA; Subkey: "Software\{#MyAppName}\{#MyAppVersion}"; ValueType: string; ValueName: "Version"; ValueData: "{#MyAppFullVersion}"
62+
Root: HKA; Subkey: "Software\{#MyAppName}"; Flags: uninsdeletekeyifempty
63+
Root: HKA; Subkey: "Software\{#MyAppName}"; Flags: uninsdeletekey
64+
Root: HKA; Subkey: "Software\{#MyAppName}"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
65+
Root: HKA; Subkey: "Software\{#MyAppName}"; ValueType: string; ValueName: "Version"; ValueData: "{#MyAppFullVersion}"
6766

6867
[Code]
6968
var
@@ -145,68 +144,77 @@ begin
145144
Result := 0;
146145
end;
147146

147+
// This function is invoked only when the V8 version is already installed.
148+
// It retrieves the path of the uninstaller to remove the installed V8 version.
149+
function GetUninstallerPath(): String;
150+
var
151+
sUnInstRegKey: String;
152+
sUnInstPath: String;
153+
begin
154+
sUnInstRegKey := 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#MyAppName}{#CheckOldInstallerVersion}_is1';
155+
sUnInstPath := '';
156+
if not RegQueryStringValue(HKLM, sUnInstRegKey, 'UninstallString', sUnInstPath) then
157+
RegQueryStringValue(HKCU, sUnInstRegKey, 'UninstallString', sUnInstPath);
158+
Result := sUnInstPath;
159+
end;
160+
161+
// This function is invoked only when the V8 version is already installed.
162+
// It is used to uninstall the installed V8 version.
163+
// Return Values:
164+
// 1 - Uninstaller path is empty.
165+
// 2 - Error executing the Uninstaller.
166+
// 3 - Successfully executed the Uninstaller
167+
function UnInstallOldVersion(): Integer;
168+
var
169+
sUnInstallerPath: String;
170+
iResultCode: Integer;
171+
begin
172+
// default return value
173+
Result := 0;
174+
175+
// get the uninstall path of the old app
176+
sUnInstallerPath := GetUninstallerPath();
177+
if sUnInstallerPath <> '' then begin
178+
sUnInstallerPath := RemoveQuotes(sUnInstallerPath);
179+
if Exec(sUnInstallerPath, '/SILENT /NORESTART /SUPPRESSMSGBOXES','', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
180+
Result := 3
181+
else
182+
Result := 2;
183+
end else
184+
Result := 1;
185+
end;
186+
148187
function CheckPgAdminAlreadyInstalled: Boolean;
149188
var
150189
Version: String;
151-
InstallationFound: Boolean;
152190
begin
153-
InstallationFound := False;
154-
// Check the installation mode 64 or 32 bit of installer
155-
if Is64BitInstallMode then
191+
if RegKeyExists(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}\{#CheckOldInstallerVersion}') then
156192
begin
157-
158-
// Check if pgAdmin 32 bit is already installed
159-
RegQueryStringValue(HKLM32,'Software\{#MyAppName}\{#MyAppVersion}', 'Version', Version);
160-
161-
// If version is found then shouldn't install 64bit - abort
162-
if Length(Version) > 0 then
193+
if UnInstallOldVersion() < 3 then
163194
begin
164-
MsgBox(ExpandConstant('{#MyAppErrorMsgIsWin32}'), mbCriticalError, MB_OK);
165-
Result := False;
166-
InstallationFound := True;
195+
Result := False;
167196
end;
168-
end
169-
else
170-
begin
171-
// Suppose system is running a 32-bit version of Windows then no need to check HKLM64 in RegQueryStringValue
172-
// So IsWin64 - will make sure its should only execute on 64-bit version of windows.
173-
if IsWin64 then
174-
begin
175-
// Check if pgAdmin 64 bit is already installed
176-
RegQueryStringValue(HKLM64,'Software\{#MyAppName}\{#MyAppVersion}', 'Version', Version);
177-
178-
// If version is found the shouldn't install 32bit - abort
179-
if Length(Version) > 0 then
180-
begin
181-
MsgBox(ExpandConstant('{#MyAppErrorMsgIsWin64}'), mbCriticalError, MB_OK);
182-
Result := False;
183-
InstallationFound := True;
184-
end;
185-
end;
186-
end;
197+
end;
187198

188-
if not (InstallationFound) then
199+
if RegValueExists(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}', 'Version') then
189200
begin
190-
if RegValueExists(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}\{#MyAppVersion}', 'Version') then
191-
begin
192-
UpgradeMode := True;
193-
RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}\{#MyAppVersion}', 'Version', Version);
194-
if CompareVersions(Version, '{#MyAppFullVersion}') = 1 then
195-
begin
196-
MsgBox(ExpandConstant('{cm:NewerVersionExists}' + '(v' + Version + ') is already installed' ), mbInformation, MB_OK);
197-
Result := False;
198-
end
199-
else
200-
begin
201-
Result := True;
202-
end;
203-
end;
201+
UpgradeMode := True;
202+
RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\{#MyAppName}', 'Version', Version);
203+
if CompareVersions(Version, '{#MyAppFullVersion}') = 1 then
204+
begin
205+
MsgBox(ExpandConstant('{cm:NewerVersionExists}' + '(v' + Version + ') is already installed' ), mbInformation, MB_OK);
206+
Result := False;
207+
end
208+
else
209+
begin
210+
Result := True;
211+
end;
204212
end;
205213

206-
if ( not (InstallationFound) and not (UpgradeMode) ) then
214+
if ( not (UpgradeMode) ) then
207215
begin
208-
// This is required as it will be passed on to the InitializeSetup function
209-
Result := True;
216+
// This is required as it will be passed on to the InitializeSetup function
217+
Result := True;
210218
end;
211219
end;
212220

0 commit comments

Comments
 (0)