installation - 创新设置: Overwrite existing installation or show dir prompt

标签 installation inno-setup

如果我的设置中有这个就好了:

  • 如果以前没有安装过,则应显示目标目录的编辑字段。
  • 如果有以前的安装,则应询问用户是否要覆盖现有安装(无目录) 提示应该是可见的)或者如果他想在 不同的目录作为单独的安装(卸载列表中的两个条目)。如果选择此选项,则编辑字段 应显示目标目录。

是否可以使用现有的 Inno Setup 选项来实现此目的?或者我是否必须构建自定义对话框页面?

最佳答案

在开头 ( InitializeSetup event function ),检查应用程序是否已安装(请参阅下面代码中的 GetUninstallString)。如果是,询问用户该怎么办(请参阅代码中的 MsgBox 使用和第一个屏幕截图)。如果用户选择更新现有安装,请正常继续。默认情况下,Inno Setup 不允许更改现有安装的安装路径(请参阅 DisableDirPage )。

如果用户选择安装另一个副本,请设置 AppId到一个新的唯一值(代码中的 GetAppId 函数)。这将使 Inno Setup 将安装视为新安装,因此会提示输入安装路径。还更新UninstallDisplayName ,以便用户在选择要卸载的副本时可以区分安装(请参阅 GetAppIdentification 和第三个屏幕截图)。同时更新DefaultDirName到新的唯一路径(请参阅 GetAppIdentification 和第三个屏幕截图)。

#define AppName "My Program"
#define AppVersion "1.5"

[Setup]
AppId={code:GetAppId}
AppName={#AppName}
AppVersion={#AppVersion}
UninstallDisplayName={#AppName} {#AppVersion}{code:GetAppIdentification}
UsePreviousLanguage=no # Needed when AppId is dynamic
DefaultDirName={autopf}\My Program{code:GetAppIdentification}
[Code]

var
  Instance: string;

function GetAppId(Param: string): string;
begin
  Result := '{#AppName}' + Instance;
end;

function GetAppIdentification(Param: string): string;
begin
  if Instance <> '' then Result := ' (' + Instance + ')';
end;

function GetUninstallString(): string;
var
  UninstallKey: string;
begin
  UninstallKey :=
    'Software\Microsoft\Windows\CurrentVersion\Uninstall\' + GetAppId('') + '_is1';
  RegQueryStringValue(HKA, UninstallKey, 'UninstallString', Result);
  Log(Result)
end;

function InitializeSetup(): Boolean;
var
  Message: string;
  Answer: Integer;
begin
  Result := True;
  if GetUninstallString() = '' then
  begin
    Log('Application is not installed yed, installing the first copy');
  end
    else
  begin
    Log('Application is installed already, asking what to do');
    Message :=
      'This program is installed already, ' +
      'do you want to update the existing installation? ' +
      'Press No to install another copy of the program';
    Answer := MsgBox(Message, mbConfirmation, MB_YESNOCANCEL);
    if Answer = IDYES then
    begin
      Log('User chose to update the installation');
    end
      else
    if Answer = IDNO then
    begin
      Log('User chose to install another copy');
      Instance := '2';
    end
      else
    begin
      Log('User chose to abort the installation');
      Result := False;
    end;
  end;
end;

enter image description here

enter image description here

enter image description here


现在的问题是如果已经有两个安装该怎么办。要创建第三个(或更多),很简单,只需循环,增加 Instance 中的值,直到 GetUninstallString 返回空字符串。但如果您希望用户能够选择要更新的副本,那就会更困难。对于一个问题来说这太多了。


你想做的事情相当复杂。如果你想保持灵活性,我认为最简单的解决方案是将每个新版本视为一个单独的软件。此外,在开始安装时,出于对那些只想保留最新版本的人的礼貌,请自动卸载以前(最新)的安装。如果用户已经进行了多次安装,则无需执行任何具体操作(或仅通知用户)。

关于installation - 创新设置: Overwrite existing installation or show dir prompt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61971214/

相关文章:

python - 为 python 2.7 安装 mysql

windows - Windows 7 上的 Docker 桌面安装无法正常工作

tfs - 生成 MSI 作为 TFS 构建的一部分

c# - 安装时自动启动 Windows 服务

registry - 卸载时恢复文件关联注册表值

java - "ItemizedOverlay"无法解析为类型

inno-setup - Inno Setup Compiler "Cannot find the path specified"错误,路径长

installation - Inno setup 中等效的升级代码

unicode - 在 Inno Setup 中对所有语言使用 .islu 翻译文件是否安全?

inno-setup - 在 Inno Setup 中通过部分名称搜索查找窗口