Skip to content
⌘ NSIS Forum Archive

Stay on InstFilesPage if errors occurs

3 posts

expr#edited

Stay on InstFilesPage if errors occurs

Hi!

I would like to stay on the InstFiles page if errors occurs,
but I am unable to make this working...

Can somebody help me please?

; Sample code (NSIS3)
;--------------------------------
!include "MUI2.nsh"
;--------------------------------
Name "Test"
OutFile "Test.exe"
RequestExecutionLevel user
ShowInstDetails show
Var ErrorCount
    
Function .onInit
    IntOp $ErrorCount 0 + 0
FunctionEnd
;--------------------------------
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
;===============================================================================
;// same result with MUI_PAGE_CUSTOMFUNCTION_SHOW
!define MUI_PAGE_CUSTOMFUNCTION_PRE FinishPagePre
!insertmacro MUI_PAGE_FINISH
Function FinishPagePre
    ${If} $ErrorCount > 0
        DetailPrint ""
        DetailPrint "$ErrorCount error(s)!"
        ShowWindow $mui.FinishPage.Run ${SW_HIDE}
        ShowWindow $mui.InstFilesPage.Run ${SW_SHOW}
        MessageBox MB_OK "Ok?"
        ;// FinishPage displayed...
    ${EndIf}
FunctionEnd
;===============================================================================
;--------------------------------
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
Section "Test"
    DetailPrint "Hello!"
    IntOp $ErrorCount $ErrorCount + 1
    ;// $ErrorCount == 1
SectionEnd
;--------------------------------
; EOF 
expr#
Problem solved 🙂

Working code:

; Sample code (NSIS3)
;--------------------------------
!include "MUI2.nsh"
;--------------------------------
Name "Test"
OutFile "Test.exe"
RequestExecutionLevel user
ShowInstDetails show
Var ErrorCount
Var InstFilesAborted
    
Function .onInit
    IntOp $ErrorCount 0 + 0
    StrCpy $InstFilesAborted "FALSE"
FunctionEnd
;--------------------------------
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE InstFilesLeave
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
;--------------------------------
Function InstFilesLeave
    ${IfNot} $InstFilesAborted == "TRUE"
        ${If} $ErrorCount > 0
            StrCpy $InstFilesAborted "TRUE"
            
            DetailPrint ""
            DetailPrint "$ErrorCount error(s)!"
            
            GetDlgItem $1 $HWNDPARENT 1 ;Next button
            EnableWindow $1 1
            
            Abort
        ${EndIf}
    ${EndIf}
FunctionEnd
;--------------------------------
!insertmacro MUI_LANGUAGE "English"
;--------------------------------
Section "Test"
    DetailPrint "Hello!"
    IntOp $ErrorCount $ErrorCount + 1
    ;// $ErrorCount == 1
SectionEnd
;--------------------------------
; EOF