Archive: Uncheck Section IfFileExists


Uncheck Section IfFileExists
How do I unckeck a Section with IfFileExists?


Look at macros in Section.nsh file, probably you should use UnSelectSection macro.


Shouldn't this work?


Function CheckInstall
IfFileExists $WINDIR\notepad.exe Skip
!insertmacro ReverseSection SecTest
Skip:
FunctionEnd


Section "Test" SecTest
Call CheckInstall
SectionEnd

anyone?


Not quite.
The Section needs to be above the Function and the ReverseSection line needs to look like this:

!insertmacro ReverseSection ${SecTest}

-Stu


Actually, you should use the UnselectSection macro.

-Stu


I did as you said, but it doesn't work. :(


Your code is logically faulty. You can't unselect a section while it running!
You should call your CheckInstall in the Components page leave function.

-Stu


leave function? I need to run it before the component page load otherwise... it makes no sense. Call function needs to be in a Selection to function I read.


Sorry, I meant Pre function.

!define MUI_PAGE_CUSTOMFUNCTION_PRE ComponentsPagePre
!insertmacro MUI_PAGE_COMPONENTS

Function ComponentsPagePre
...

-Stu


Still no luck. Now it looks like this...


!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

IfFileExists "$WINDIR\NOTEPAD.EXE" Skip

use quotes :) its safer.


Scripting an installer is hopeless, and looking at the number of threads in this forum I can see I'm not the only one haveing a hard time. I'll just have to use the zip2exe wizard.


You just have to have a little patience, really... if all you need to have is an auto-extracting .zip file.. sure, zip2exe or Winzip's functionalities are just dandy if not preferable.

If you want a more complex system, NSIS is the way to go.

If you could indicate whether Comm@nder21's last comment helped at all or not, we could have a closer look - as far as I can see things should work fine though.


Just to confirm, I'm assuming that you want to uncheck the Section if Notepad doesn't exist?

-Stu


If the file already exists, then uncheck.


You should read the docs again on IfFileExists. You're skipping your code if the file exists.

-Stu


Documentation.

4.9.4.10 IfFileExists
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"
You 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.

WTF is 0 +2? :confused:

The jumps are explained earlier in the manual. But a better method is explained even earlier, in the tutorial.

${If} ${FileExists} $WINDIR\notepad.exe
DetailPrint "notepad found"
${Else}
DetailPrint "notepad not found"
${EndIf}

Thanks. I managed to figure it out though. :)


IfFileExists "file" uncheck leave
uncheck:
!insertmacro UnselectSection ${SecTest}
leave:


Though I still don't know what 0 +2 is. And I don't care. The ^tutorial only said yadi yadi yada to me. :confused:

0 means don't jump anywhere, i.e. carry on onto the next instruction. +2 would mean jump over the proceding instruction onto the one after (i.e. 2 instructions from the current statement).
+1 would be the same as 0.

-Stu


Ok so if I understand you correct, this code would do the same thing as the code above?


IfFileExists "file" 0 +2
!insertmacro UnselectSection ${SecTest}


EDIT: Tried but it didn't work. Unselect was always run.

No, because macros are not one instruction. Macros often contain more than one instruction.


Ok. Thank you.



!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


It had another methods?

Look at IfFileExists again.

Stu


oh.yes!!!thanks

i know how to do it.

!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