我现在已经了解如何使用此 DswinsHs 来下载文件(因为我们在帮助文档中使用了该文件)。
但是现在我需要迁移一些旧代码,这些旧代码可选地下载并安装了 Dot Net Framework 。
我有以下代码(用于ISTool DLL):
const
// Changed to 4.6.2 download link (see: http://msdn.microsoft.com/en-us/library/ee942965%28v=vs.110%29.aspx#redist)
dotnetRedistURL = 'http://go.microsoft.com/fwlink/?LinkId=780600';
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;
downloadNeeded := 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;
downloadNeeded := false;
end;
end;
end;
if(dotNetNeeded) then begin
if (not IsAdminLoggedOn()) then begin
Result := ExpandConstant('{cm:DotNet_NeedAdminRights}');
end
else begin
dotnetRedistPath := ExpandConstant('{src}\NDP451-KB2858728-x86-x64-AllOS-ENU.exe');
if not FileExists(dotnetRedistPath) then begin
dotnetRedistPath := ExpandConstant('{tmp}\NDP451-KB2858728-x86-x64-AllOS-ENU.exe');
if not FileExists(dotnetRedistPath) then begin
isxdl_AddFile(dotnetRedistURL, dotnetRedistPath);
downloadNeeded := true;
end;
end;
if (downloadNeeded) then begin
if (MsgBox(ExpandConstant('{cm:DotNet_NeedToDownload}'), mbConfirmation, MB_OKCANCEL) = IDCANCEL) then begin
Result := ExpandConstant('{cm:DotNet_InstallAborted}');
end;
end;
end;
end;
// AJT v19.0.0 We always delete the existing local help file if it exists.
// The new version will be downloaded on the next wizard form if
// the user still wants the local help. ("downloadhelp" task selected).
if (bDownloadHelpDocSetup) then DoDeleteFile(ExpandConstant('{app}\CommunityTalks.chm'));
end;
那我有:
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;
这需要改变。
对于适用于DwinsHs的下载,我基本上具有两位,如下所示:
[Files]
部分: ; AJT v19.0.0 Download Help Documentation Setup file.
; This is associated with the "downloadhelp" task.
; It will be downloaded from the internet and deleted after install.
Source: "{tmp}\HelpDocSetup.exe"; \
DestDir: "{app}"; \
Flags: external deleteafterinstall; \
Tasks: downloadhelp; \
Check: DwinsHs_Check( ExpandConstant('{tmp}\HelpDocSetup.exe'), '{#HelpDocSetupURL}', \
'My_Setup', 'Get', {#HelpDocSetupFileSize}, 0 )
[Run]
部分: ; AJT v19.0.0 Installed the downloaded help documentation.
; This is only done if the "downloadhelp" task was selected.
Filename: "{app}\HelpDocSetup.exe"; \
Parameters: "/SP- /VERYSILENT /InstallPath=""{app}"""; \
WorkingDir: "{app}"; \
Flags: waituntilterminated runhidden; \
Description: "{cm:InstallingHelpDescription}"; \
StatusMsg: "{cm:InstallingHelpStatusMessage}"; \
Tasks: downloadhelp
我需要将之前的代码(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是安装程序正常运行的前提。我应该以不同的方式处理这个问题吗?
基于提供的答案和我对文档的理解...
第1步
在PrepareToInstall
中,我们检查是否需要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步
我们添加了一个BeforeDownload
处理程序。在这里,我们有机会将需要下载的文件添加到列表中:
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步
我们添加了一个AfterDownload
处理程序。这是我们执行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;
答案 0 :(得分:1)
只需在DwinsHs_AppendRemoteFile
时调用dotNetNeeded
。
DwinsHs_AppendRemoteFile
与DwinsHs_Check
具有基本相同的参数(DwinsHs_Check
实际上只是Check
周围的DwinsHs_AppendRemoteFile
兼容包装器)。
我相信这就是您所需要的。 [Run]
仅在下载后发生。