在自定义 NSIS 页面中下载文件
Downloading files in Custom NSIS Page
我想使用 inetc 插件创建一个下载文件而不冻结 UI 的安装程序。我的问题是可能 without 使用带有 /ASYNC 标志的 ExecDos::Exec 然后 ExecDos::Wait.
此外,我不想在我的安装程序中出现安装页面。
这是我的代码:
!macro DOWNLOAD_PAGE
Function myTimer
${If} [=10=] == "OK"
${NSD_KillTimer} myTimer
SendMessage $hPBar ${PBM_SETRANGE32} 0 100
SendMessage $hPBar ${PBM_SETPOS} 100 0
Return
${EndIf}
SendMessage $hPBar ${PBM_SETRANGE32} 0 100
SendMessage $hPBar ${PBM_SETPOS} 50 0
FunctionEnd
function Page1
nsDialogs::Create 1018
Pop $Dialog
${NSD_CreateLabel} 0 0 100% 50% "Starting download..."
Pop $hInfo
${NSD_CreateProgressBar} 0 55% 100% 10u ""
Pop $hPBar
${NSD_CreateTimer} myTimer 1000
inetc::get /silent "$URL\skype.exe" "$EXEDIR\skype.exe" /end
Pop [=10=]
nsDialogs::Show
functionEnd
function Page2
functionEnd
Page Custom Page1 Page2
!macroend
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!insertmacro DOWNLOAD_PAGE
!insertmacro MUI_PAGE_FINISH
或者我唯一的选择是将 ExecDos::Exec 与 /ASYNC 标志一起使用?
也许,一个解决方案是创建另一个 nsis 安装程序来进行下载?
在 nsDialogs::Create
和 nsDialogs::Show
之间执行长时间操作将挂起 UI。
简单的解决方案是在 Section
中下载,因为它们是在不同的线程中执行的。您应该在 Section
.
内完成大部分任务
如果您坚持要在自定义页面上下载一些东西,那么您可以使用 InetBgDL plug-in:
!include nsDialogs.nsh
!include LogicLib.nsh
Page Custom Page1
Var hInfo
Function Page1
nsDialogs::Create 1018
Pop [=10=]
${NSD_CreateLabel} 0 0 100% 50% "Starting download..."
Pop $hInfo
InitPluginsDir
INetBgDl::Get "https://example.com/file.exe" "$PluginsDir\file.exe" /end
${NSD_CreateTimer} myTimer 1000
nsDialogs::Show
${NSD_KillTimer} myTimer
FunctionEnd
Function myTimer
InetBgDL::GetStats
${NSD_SetText} $hInfo "Status=[=10=]$\nCompleted files=$\nDownloaded of bytes"
${If} [=10=] = 0 ; HTTP status code or 0 if completed without errors
${NSD_KillTimer} myTimer
MessageBox mb_ok Done
${EndIf}
FunctionEnd
我想使用 inetc 插件创建一个下载文件而不冻结 UI 的安装程序。我的问题是可能 without 使用带有 /ASYNC 标志的 ExecDos::Exec 然后 ExecDos::Wait.
此外,我不想在我的安装程序中出现安装页面。 这是我的代码:
!macro DOWNLOAD_PAGE
Function myTimer
${If} [=10=] == "OK"
${NSD_KillTimer} myTimer
SendMessage $hPBar ${PBM_SETRANGE32} 0 100
SendMessage $hPBar ${PBM_SETPOS} 100 0
Return
${EndIf}
SendMessage $hPBar ${PBM_SETRANGE32} 0 100
SendMessage $hPBar ${PBM_SETPOS} 50 0
FunctionEnd
function Page1
nsDialogs::Create 1018
Pop $Dialog
${NSD_CreateLabel} 0 0 100% 50% "Starting download..."
Pop $hInfo
${NSD_CreateProgressBar} 0 55% 100% 10u ""
Pop $hPBar
${NSD_CreateTimer} myTimer 1000
inetc::get /silent "$URL\skype.exe" "$EXEDIR\skype.exe" /end
Pop [=10=]
nsDialogs::Show
functionEnd
function Page2
functionEnd
Page Custom Page1 Page2
!macroend
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
!insertmacro DOWNLOAD_PAGE
!insertmacro MUI_PAGE_FINISH
或者我唯一的选择是将 ExecDos::Exec 与 /ASYNC 标志一起使用? 也许,一个解决方案是创建另一个 nsis 安装程序来进行下载?
在 nsDialogs::Create
和 nsDialogs::Show
之间执行长时间操作将挂起 UI。
简单的解决方案是在 Section
中下载,因为它们是在不同的线程中执行的。您应该在 Section
.
如果您坚持要在自定义页面上下载一些东西,那么您可以使用 InetBgDL plug-in:
!include nsDialogs.nsh
!include LogicLib.nsh
Page Custom Page1
Var hInfo
Function Page1
nsDialogs::Create 1018
Pop [=10=]
${NSD_CreateLabel} 0 0 100% 50% "Starting download..."
Pop $hInfo
InitPluginsDir
INetBgDl::Get "https://example.com/file.exe" "$PluginsDir\file.exe" /end
${NSD_CreateTimer} myTimer 1000
nsDialogs::Show
${NSD_KillTimer} myTimer
FunctionEnd
Function myTimer
InetBgDL::GetStats
${NSD_SetText} $hInfo "Status=[=10=]$\nCompleted files=$\nDownloaded of bytes"
${If} [=10=] = 0 ; HTTP status code or 0 if completed without errors
${NSD_KillTimer} myTimer
MessageBox mb_ok Done
${EndIf}
FunctionEnd