0

我想在我的 nsis 安装程序中控制进度条。实际上我正在使用ThreadTimer插件,但我遇到了很大的问题。ThreadTimer 每 10 秒运行一次函数以更新进度条(将进度条值增加 1%)。问题是它使堆栈崩溃(我可以看到 ThreadTimer 使用与 NSIS 相同的堆栈)。Crashes stack意味着当我想从堆栈中获取值时,由于 ThreadTimer 函数操作,该值是错误的。有任何想法吗?也许还有其他方法可以更新进度条?

这些是应该更新进度条的函数/宏。宏StartProgressBarIntervalUpdate开始更新进度条,宏StopProgressBarIntervalUpdate停止掺杂它。

Var /GLOBAL ProgressBarPosition
Var /GLOBAL ProgressBarParentWindow
Var /GLOBAL ProgressBarItem

Function InitProgressBar
    StrCpy $ProgressBarPosition "0"
    FindWindow $ProgressBarParentWindow "#32770" "" $HWNDPARENT
    GetDlgItem $ProgressBarItem $ProgressBarParentWindow 1004
FunctionEnd

Function UpdateProgressBarTimer
    ${If} $ProgressBarPosition >= 30000 ; 100% * 300
        StrCpy $ProgressBarPosition "0"
    ${Endif}
    IntOp $ProgressBarPosition $ProgressBarPosition + 300
    SendMessage $ProgressBarItem ${PBM_SETPOS} $ProgressBarPosition 0
FunctionEnd

!define StartProgressBarIntervalUpdate "!insertmacro StartProgressBarIntervalUpdate"
!macro StartProgressBarIntervalUpdate
    Call InitProgressBar
    GetFunctionAddress $UpdateProgressBarTimerFunctionAddress UpdateProgressBarTimer
    ThreadTimer::Start /NOUNLOAD 20 -1 $UpdateProgressBarTimerFunctionAddress
    Sleep 1000
!macroend

!define StopProgressBarIntervalUpdate "!insertmacro StopProgressBarIntervalUpdate"
!macro StopProgressBarIntervalUpdate
    ThreadTimer::Stop $UpdateProgressBarTimerFunctionAddress
    Sleep 15000
!macroend

以下是使用进度条的部分

Var /GLOBAL UpdateProgressBarTimerFunctionAddress
Section BeforeMoveData SEC01
    ${StartProgressBarIntervalUpdate}

    Call core.UnpackExeData
SectionEnd

Section OnMoveData SEC02    
    Call InstallFiles
    Call InstallRegistry
    Call InstallShortcuts

    ${StopProgressBarIntervalUpdate}

    ...

SectionEnd
4

0 回答 0