如果已安装旧版本,则创建将执行更新的安装程序

时间:2013-03-26 13:46:28

标签: inno-setup updates

我正在尝试为我的软件配置Inno设置(这是一个c#软件)。 我计划发布我的软件的许多版本,如果我的应用程序的旧版本已经安装在计算机上,我想更改inno安装程序安装程序界面。 在这种情况下,用户不应该能够更改安装目录。

有四种情况:

第一种情况:这是我产品的第一次安装,inno设置应该正常进行。

第二种情况:产品已全部安装且安装程序包含较新版本。用户无法选择目标文件夹。他可以运行更新。

第三种情况:如果安装程序包含的版本低于安装的版本,则将禁用更新并显示消息。

第四种情况:安装程序版本与安装版本相同。如果需要,用户可以修复他的执行版本。

InnoSetup是否可以做到这一点?

2 个答案:

答案 0 :(得分:9)

如果您想为用户提供一些反馈,可以尝试这样的方法。 首先,您的更新应与您的主应用程序具有相同的AppId名称。 然后,您可以设置一些检查,显示消息以通知用户状态。

#define MyAppVersion "1.2.2.7570"
#define MyAppName "MyApp Update"

[Setup]
AppId=MyApp
AppName={#MyAppName}
AppVersion={#MyAppVersion}
DefaultDirName={reg:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1,InstallLocation}
DisableDirPage=True

[CustomMessages]
MyAppOld=The Setup detected application version 
MyAppRequired=The installation of {#MyAppName} requires MyApp to be installed.%nInstall MyApp before installing this update.%n%n
MyAppTerminated=The setup of update will be terminated.

[Code]
var
InstallLocation: String;

function GetInstallString(): String;
var
InstPath: String;
InstallString: String;
begin
InstPath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1');
InstallString := '';
if not RegQueryStringValue(HKLM, InstPath, 'InstallLocation', InstallString) then
RegQueryStringValue(HKCU, InstPath, 'InstallLocation', InstallString);
Result := InstallString;
InstallLocation := InstallString;
end;

function InitializeSetup: Boolean;
var
V: Integer;
sUnInstallString: String;
Version: String;
begin
    if RegValueExists(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'UninstallString') then begin
      RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_is1', 'DisplayVersion', Version);
      if Version =< ExpandConstant('{#MyAppVersion}') then begin 
          Result := True;
          GetInstallString();
       end
       else begin
MsgBox(ExpandConstant('{cm:MyAppOld}'+Version+'.'+#13#10#13#10+'{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK);
         Result := False;
  end;
end
else begin
  MsgBox(ExpandConstant('{cm:MyAppRequired}'+'{cm:MyAppTerminated}'), mbInformation, MB_OK);
  Result := False;
end;
end;

答案 1 :(得分:7)

如果AppID在应用程序的生命周期内保持不变,Inno Setup已自动处理案例1,2和4。 您还可以使用以下[Setup]指令隐藏目录和组页面:

DisableDirPage=auto
DisableGroupPage=auto

有关详细信息,请参阅此ISXKB article

对于案例3,假设您的文件版本正确,Inno不会降级任何内容,但它实际上不会警告用户。为此,您需要添加代码来检查这一点,最有可能在InitializeSetup()事件函数中。

相关问题