Uncheck Section IfFileExists
How do I unckeck a Section with IfFileExists?
27 posts
Function CheckInstall
IfFileExists $WINDIR\notepad.exe Skip
!insertmacro ReverseSection SecTest
Skip:
FunctionEnd
Section "Test" SecTest
Call CheckInstall
SectionEnd
!define MUI_PAGE_CUSTOMFUNCTION_PRE ComponentsPagePre
!insertmacro MUI_PAGE_COMPONENTS
Function ComponentsPagePre
Call CheckInstall
FunctionEnd
Section "Test" SecTest
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
;Files Here
SectionEnd
Function CheckInstall
IfFileExists $WINDIR\NOTEPAD.EXE Skip
!insertmacro UnselectSection ${SecTest}
Skip:
FunctionEnd
4.9.4.10 IfFileExistsYou shouldn't assume a normal person understand what is written in the manual. I don't understand it. It doesn't say how to do something if a file exist. Only option is jump.
file_to_check_for jump_if_present [jump_otherwise]
Checks for existence of file(s) file_to_check_for (which can be a wildcard, or a directory), and Gotos jump_if_present if the file exists, otherwise Gotos jump_otherwise. If you want to check to see if a file is a directory, use IfFileExists DIRECTORY\*.*
IfFileExists $WINDIR\notepad.exe 0 +2
MessageBox MB_OK "notepad is installed"
${If} ${FileExists} $WINDIR\notepad.exe
DetailPrint "notepad found"
${Else}
DetailPrint "notepad not found"
${EndIf}Though I still don't know what 0 +2 is. And I don't care. The ^tutorial only said yadi yadi yada to me. 😕
IfFileExists "file" uncheck leave
uncheck:
!insertmacro UnselectSection ${SecTest}
leave:
EDIT: Tried but it didn't work. Unselect was always run.
IfFileExists "file" 0 +2
!insertmacro UnselectSection ${SecTest}
It had another methods?
!include "MUI.nsh"
OutFile "S32.exe"
!define MUI_PAGE_CUSTOMFUNCTION_PRE ComponentsPage1Pre
!insertmacro MUI_PAGE_COMPONENTS
Function ComponentsPage1Pre
Call Check1
Call Check2
Call Check3
Call Check4
Call Check5
FunctionEnd
Function Check1
IfFileExists $PROGRAMFILES\NSIS\NSIS.exe skip
!insertmacro UnselectSection ${Sec60}
skip:
FunctionEnd
Function Check2
IfFileExists $PROGRAMFILESA\A.exe skip
!insertmacro UnselectSection ${Sec20}
skip:
FunctionEnd
Function Check3
IfFileExists $PROGRAMFILES\DAEMON Tools\DAEMON.exe skip
!insertmacro UnselectSection ${Sec30}
skip:
FunctionEnd
Function Check4
IfFileExists $PROGRAMFILES\QQGAME\Game.exe skip
!insertmacro UnselectSection ${Sec40}
skip:
FunctionEnd
Function Check5
IfFileExists $windir\notepad skip
!insertmacro UnselectSection ${Sec50}
skip:
FunctionEnd
!include Sections.nsh
Name TestSelectSection
OutFile "TestSelectSection.exe"
Page components
Page instfiles
ShowInstDetails show
; This file will exist on most computers
Section /o "autoexec.bat detected" autoexec_detected
MessageBox MB_OK autoexec
SectionEnd
Section /o "Boot.ini detected" boot_detected
MessageBox MB_OK boot
SectionEnd
Section /o "non-existing file detected" missing_detected
MessageBox MB_OK missing
SectionEnd
Function .onInit
IfFileExists C:\autoexec.bat AutoexecExists PastAutoexecCheck
AutoexecExists:
; This is what is done by sections.nsh SelectSection macro
SectionGetFlags "${autoexec_detected}" $0
IntOp $0 $0 | ${SF_SELECTED}
SectionSetFlags "${autoexec_detected}" $0
PastAutoexecCheck:
IfFileExists C:\boot.ini BootExists PastBootCheck
BootExists:
; Use the macro from sections.nsh
!insertmacro SelectSection ${boot_detected}
PastBootCheck:
IfFileExists C:\xyz_missing.xyz MissingExists PastMissingCheck
MissingExists:
!insertmacro SelectSection ${missing_detected}
PastMissingCheck:
FunctionEnd