Upgrades

From ISXKB

(Difference between revisions)
Jump to: navigation, search
(Added a link to the original HOWTO article)
Line 39: Line 39:
Nothing else is needed to do an upgrade installation as Inno handles the rest for you automatically (provided you have specified appropriate Flags on your install entries).
Nothing else is needed to do an upgrade installation as Inno handles the rest for you automatically (provided you have specified appropriate Flags on your install entries).
-
In Inno 5.3.3 and above, you can check the value of WizardForm.PrevAppDir to determine the previous install folder and determine if an upgrade is being performed:
+
In Inno 5.3.3 and above, you can check the value of WizardForm.PrevAppDir to determine the previous install folder and determine if an upgrade is being performed (however note that this is not available in InitializeSetup; InitializeWizard is the earliest that it can be called):
<pre>
<pre>

Revision as of 06:00, 17 March 2014

When upgrading an application, it is a good idea to hide the directory selection and program group selection pages to stop users changing the details once it has already been installed and potentially orphaning files. If you're using Inno Setup 5.3.3, this is easily accomplished by setting both the DisableDirPage and DisableProgramGroupPage directives to auto, and Inno handles everything else for you.

If you are using an older version, then there is no built in method to detect if you are installing fresh, or upgrading an existing install with the same AppID, so you will need to make use of a small function that looks up the previous installation directory and returns TRUE if it's an upgrade or FALSE if it's not:

function IsUpgrade(): Boolean;
var
   sPrevPath: String;
begin
  sPrevPath := '';
  if not RegQueryStringValue(HKLM, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppID")}_is1', 'UninstallString', sPrevpath) then
    RegQueryStringValue(HKCU, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppID")}_is1', 'UninstallString', sPrevpath);
  Result := (sPrevPath <> '');
end;

This first checks the uninstall key in HKEY_LOCAL_MACHINE, and if that fails, checks HKEY_CURRENT_USER.

Bear in mind that this snippet uses ISPP, but if you do not have this available, replace {#emit SetupSetting("AppID")} with the AppID used by your setup.

Warning: If your AppID consists of a GUID (so you have a leading {{) or if you use other constants within it, then you will also need to call ExpandConstant:

 ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppID")}_is1')

You can then use the return value of this function to hide the install directory and program group selection pages. This stops the user from installing the same app into multiple locations and generally making a mess... :o)

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Result := False;
  if IsUpgrade() then
  begin
    if PageID = wpSelectDir then Result := True;
    if PageID = wpSelectProgramGroup then Result := True;
  end;
end;

Nothing else is needed to do an upgrade installation as Inno handles the rest for you automatically (provided you have specified appropriate Flags on your install entries).

In Inno 5.3.3 and above, you can check the value of WizardForm.PrevAppDir to determine the previous install folder and determine if an upgrade is being performed (however note that this is not available in InitializeSetup; InitializeWizard is the earliest that it can be called):

function IsUpgrade(): Boolean;
var
   sPrevPath: String;
begin
  sPrevPath := WizardForm.PrevAppDir;
  Result := (sPrevPath <> '');
end;

See also

Personal tools
Ads: