Excludes part of Code section in ssPostInstall step if installation is update in Inno Setup

末鹿安然 提交于 2019-12-23 01:54:31

问题


I try to use same installer for both (fresh installation and update).

  • so if user try to install my application for first time it will run the full installation included MySQL installer as prerequisites, and the part of MySQL installation within [Code] will execute normally.
  • but, if user already installed my application, and the installer is newer version (update), the part of MySQL installation within [Code] shouldn't be execute.

So, how to implement exception function for this part of code (MySQL installation) if the installation is just updating?

[Code]

procedure CurStepChanged(CurStep: TSetupStep);
{ ... }
begin
  if CurStep = ssPostInstall then
  begin
    { fresh installation code }
  end;
end;

回答1:


You can use IsUpgrade function from my answer to
Can Inno Setup respond differently to a new install and an update?:

Though as it relies on a presence of "Uninstall" registry key, which already exists at the time of ssPostInstall, you have to cache its value.

var
  IsUpgradeCached: Boolean;

function InitializeSetup(): Boolean;
begin
  IsUpgradeCached := IsUpgrade;
  Result := True;
end;

procedure CurStepChanged(CurStep: TSetupStep);
{ ... }
begin
  if (CurStep = ssPostInstall) and (not IsUpgradeCached) then
  begin
    { fresh installation code }
  end;
end;


来源:https://stackoverflow.com/questions/54808659/excludes-part-of-code-section-in-sspostinstall-step-if-installation-is-update-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!