Inno setup 如何使用Inno Setup Install/DswinDs系统处理DotNet先决条件?

Inno setup 如何使用Inno Setup Install/DswinDs系统处理DotNet先决条件?,inno-setup,pascal,prerequisites,Inno Setup,Pascal,Prerequisites,我现在已经了解了如何使用这个DswinsHs下载文件(正如我们在帮助文档中使用的那样) 但是现在我需要迁移一些可以选择下载并安装的旧代码 旧代码 我有以下代码(使用ISTool DLL): 那么我有: procedure CurStepChanged(CurStep: TSetupStep); var hWnd: Integer; ResultCode: Integer; begin if (CurStep = ssInstall) then begin hWnd :=

我现在已经了解了如何使用这个DswinsHs下载文件(正如我们在帮助文档中使用的那样)

但是现在我需要迁移一些可以选择下载并安装的旧代码

旧代码 我有以下代码(使用ISTool DLL):

那么我有:

procedure CurStepChanged(CurStep: TSetupStep);
var
  hWnd: Integer;
  ResultCode: Integer;
begin
  if (CurStep = ssInstall) then
  begin
    hWnd := StrToInt(ExpandConstant('{wizardhwnd}'));

    // Don't try to init isxdl if it's not needed because it will error on < ie 3
    if (downloadNeeded) then begin
      isxdl_SetOption('label', ExpandConstant('{cm:Downloading}'));
      isxdl_SetOption('description', ExpandConstant('{cm:DownloadingInfo}'));
      if (isxdl_DownloadFiles(hWnd) = 1) then begin
        if (dotNetNeeded = true) then begin
          if Exec(ExpandConstant(dotnetRedistPath), '/quiet', '',
                 SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
            // handle success if necessary; ResultCode contains the exit code
            if not (ResultCode = 0) then begin
              // Microsoft present an array of options for this. But since
              // The interface was visible I think it is safe to just say
              // that the installation was not completed.
              MsgBox(ExpandConstant('{cm:DotNet_InstallFailed}'), mbInformation, MB_OK);
              Abort();
            end;
          end
          else begin
            // The execution failed for some reason
            MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
            Abort();
          end;
        end;
      end
      else begin
        // The user most likely cancelled the download of the file
        MsgBox(ExpandConstant('{cm:DotNet_DownloadFailed}'), mbInformation, MB_OK);
        Abort();
      end;
    end;
    end;
end;
  • [Run]
    部分:

问题 我需要将我以前的代码(DotNet先决条件)转换为合适的文件/运行脚本行(这次我必须将文件大小传递0,因为我不知道大小)

简而言之,我的安装需要管理员权限,从技术上讲,我们需要它来下载和安装dotnet(如果没有),然后才能继续安装。原因是我们有这些运行条目:

Filename: "{dotnet40}\regasm.exe"; \
    Parameters: "PTSTools_x86.dll /codebase"; \
    WorkingDir: "{app}"; \
    Flags: runhidden

Filename: "{dotnet4064}\regasm.exe"; \
    Parameters: "PTSTools_x64.dll /codebase"; \
    WorkingDir: "{app}"; \
    Flags: runhidden; \
    Check: IsWin64

Filename: "{dotnet40}\regasm.exe"; \
    Parameters: "/u PTSTools_x86.dll"; \
    WorkingDir: "{app}"; \
    Flags: runhidden; \
    Check: FileExists(ExpandConstant('{app}\PTSTools.dll')); \
    AfterInstall: DoDeleteFile(ExpandConstant('{app}\PTSTools.dll'))

Filename: "{dotnet4064}\regasm.exe"; \
    Parameters: "/u PTSTools.dll"; \
    WorkingDir: "{app}"; \
    Flags: runhidden; \
    Check: IsWin64 and FileExists(ExpandConstant('{app}\PTSTools.dll')); \
    AfterInstall: DoDeleteFile(ExpandConstant('{app}\PTSTools.dll'))
因此,拥有DotNet是安装程序工作的先决条件。我应该以不同的方式处理这个问题吗


我这样做对吗? 根据提供的答案和我对文件的理解

第一步

preparetoall
中,我们检查是否需要DotNet并缓存结果:

function PrepareToInstall(var NeedsRestart: Boolean): String;
var
 IsInstalled: Cardinal;
begin
  Result := '';
  dotNetNeeded := true;

  // Check for required netfx installation
  // http://msdn.microsoft.com/en-us/library/hh925568%28v=vs.110%29.aspx#net_b
  if(Is64BitInstallMode()) then begin
    if (RegValueExists(HKLM, 'SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release')) then begin
      RegQueryDWordValue(HKLM, 'SOFTWARE\Wow6432Node\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', IsInstalled);
      if(IsInstalled >= 378675) then begin
        dotNetNeeded := false;
      end;
    end;
  end
  else begin
    if (RegValueExists(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release')) then begin
      RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', IsInstalled);
      if(IsInstalled >= 378675) then begin
        dotNetNeeded := false;
      end;
    end;
  end;

  if(dotNetNeeded) then begin
    if (MsgBox(ExpandConstant('{cm:DotNet_NeedToDownload}'), mbConfirmation, MB_OKCANCEL) = IDCANCEL) then begin
      Result := ExpandConstant('{cm:DotNet_InstallAborted}');
    end;
  end;

 end;
步骤2

我们在下载之前添加一个
处理程序。在这里,我们有机会将需要下载的文件添加到列表中:

function BeforeDownload(): Boolean;
 begin
  if(dotNetNeeded) then
  begin
    dotNetRedistPath := ExpandConstant('{tmp}\NDP451-KB2858728-x86-x64-AllOS-ENU.exe');
    DwinsHs_AppendRemoteFile( dotNetRedistPath, \
                  dotnetRedistURL, 'My_Setup', rmGet, FILESIZE_QUERY_SERVER );
  end;

  Result := True;
end;
步骤3

我们在下载后添加一个
处理程序。这就是我们安装DotNet的地方

procedure AfterDownload(State: Integer);
var
  hWnd: Integer;
  ResultCode: Integer;
begin
  if (State = READ_OK) then
  begin
    if(dotNetNeeded) then
    begin
      if Exec(ExpandConstant(dotnetRedistPath), '/quiet', '',
          SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
        // handle success if necessary; ResultCode contains the exit code
        if not (ResultCode = 0) then begin
          // Microsoft present an array of options for this. But since
          // The interface was visible I think it is safe to just say
          // that the installation was not completed.
          MsgBox(ExpandConstant('{cm:DotNet_InstallFailed}'), mbInformation, MB_OK);
          Abort();
        end;
      end
      else begin
        // The execution failed for some reason
        MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
        Abort();
      end;
    end;
  end;
end;
我不确定现在“安静”是不是正确的方式

步骤4

我们调整CurPageChanged处理程序:

procedure CurPageChanged(CurPage: Integer);
begin
  DwinsHs_CurPageChanged(CurPage, @BeforeDownload, @AfterDownload);
end;

dotNetNeeded
时,只需调用
DwinsHs\u AppendRemoteFile

DwinsHs\u AppendRemoteFile
的参数基本上与
DwinsHs\u Check
相同(
DwinsHs\u Check
实际上只是
Check
的兼容包装


我相信这就是你所需要的。
[Run]
只有在下载之后才会出现。

问题是?@MartinPrikryl我的帮助文档不是“先决条件”。因此,如果“用户”希望将其包括在内,则可以将其作为安装的一部分进行下载。但正如你所知,网络是一个“先决条件”。这意味着我应该测试是否需要它,如果需要,请先安装它,然后继续安装。我不知道如何将我已有的代码塞进与DswinDs兼容的等式中。为什么不能在安装过程中安装.NET?安装本身需要它吗?@MartinPrikryl是的,请看底部的“问题”,我们使用dotnet regasm对我的一些文件进行注册。@MartinPrikryl我看到了类似的问题,但逻辑对我来说是不同的。由于我们使用的是
{dotnet4064}\regasm.exe
,我们必须在其余脚本运行之前安装它(如果需要)。我明白了。这意味着我们将把它作为第一个“运行”条目。。。因此,首先安装它…我将接受这一点,因为我关于框架实际安装的问题是另一个问题。谢谢
function BeforeDownload(): Boolean;
 begin
  if(dotNetNeeded) then
  begin
    dotNetRedistPath := ExpandConstant('{tmp}\NDP451-KB2858728-x86-x64-AllOS-ENU.exe');
    DwinsHs_AppendRemoteFile( dotNetRedistPath, \
                  dotnetRedistURL, 'My_Setup', rmGet, FILESIZE_QUERY_SERVER );
  end;

  Result := True;
end;
procedure AfterDownload(State: Integer);
var
  hWnd: Integer;
  ResultCode: Integer;
begin
  if (State = READ_OK) then
  begin
    if(dotNetNeeded) then
    begin
      if Exec(ExpandConstant(dotnetRedistPath), '/quiet', '',
          SW_SHOW, ewWaitUntilTerminated, ResultCode) then begin
        // handle success if necessary; ResultCode contains the exit code
        if not (ResultCode = 0) then begin
          // Microsoft present an array of options for this. But since
          // The interface was visible I think it is safe to just say
          // that the installation was not completed.
          MsgBox(ExpandConstant('{cm:DotNet_InstallFailed}'), mbInformation, MB_OK);
          Abort();
        end;
      end
      else begin
        // The execution failed for some reason
        MsgBox(SysErrorMessage(ResultCode), mbInformation, MB_OK);
        Abort();
      end;
    end;
  end;
end;
procedure CurPageChanged(CurPage: Integer);
begin
  DwinsHs_CurPageChanged(CurPage, @BeforeDownload, @AfterDownload);
end;