Search code examples
nsis

How to control progress bar from two different tasks


I have a custom page, and and added a progress bar. Now I have two functions to control that progress bar. One function is to stop few services and other is to back up some files from install location.

Function myCustomPage
    Var /GLOBAL progressBar
    Var /GLOBAL label 
    !insertmacro MUI_HEADER_TEXT "Setup is preaparing to install updates" "Please wait"
    nsDialogs::Create 1018 
    ${NSD_CreateLabel} 10 15 80% 10% ""
    Pop $label
    ${NSD_CreateProgressBar} 10 30 80% 8% ""
    Pop $progressBar

    ${NSD_CreateTimer} BackUp_Files.Callback 10
    ${NSD_CreateTimer} Stop_Services.Callback 10 
    nsDialogs::Show
FunctionEnd

Stop_Services call back function

Function Stop_Services.Callback
    ${NSD_SetText} $label "Stopping services"
    ${NSD_KillTimer} Stop_Services.Callback
    SendMessage $progressBar ${PBM_SETRANGE32} 0 100 
    SendMessage $progressBar ${PBM_SETPOS} 25 0
    Sleep 100
    SendMessage $progressBar ${PBM_SETPOS} 25 0 
    Sleep 100
    SendMessage $progressBar ${PBM_SETPOS} 50 0 
    Sleep 100
    SendMessage $progressBar ${PBM_SETPOS} 75 0 
    Sleep 100
    SendMessage $progressBar ${PBM_SETPOS} 100 0
FuncionEnd

Same kind of structure for Backup_files.callback has. Result: When I look at the label its kind of switching between "stopping services" and "backing up files". Can any one tell me how to handle this. I want to stop the services first then I want to copy the backup files. Progress bar needs to be set to 0 after stopping the services and start again for backing up files. I need to do it on single custom page.


Solution

  • Just use one timer and at the end of the first task call the second task function directly...