Old 18th September 2006, 18:25   #1
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
Uncheck Section IfFileExists

How do I unckeck a Section with IfFileExists?
em3 is offline   Reply With Quote
Old 19th September 2006, 08:12   #2
Filus
Junior Member
 
Join Date: Feb 2006
Location: Pomerania
Posts: 16
Look at macros in Section.nsh file, probably you should use UnSelectSection macro.
Filus is offline   Reply With Quote
Old 19th September 2006, 16:26   #3
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
Shouldn't this work?

code:

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


Section "Test" SecTest
Call CheckInstall
SectionEnd

em3 is offline   Reply With Quote
Old 20th September 2006, 18:08   #4
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
anyone?
em3 is offline   Reply With Quote
Old 20th September 2006, 18:19   #5
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Not quite.
The Section needs to be above the Function and the ReverseSection line needs to look like this:

!insertmacro ReverseSection ${SecTest}

-Stu
Afrow UK is offline   Reply With Quote
Old 20th September 2006, 18:20   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Actually, you should use the UnselectSection macro.

-Stu
Afrow UK is offline   Reply With Quote
Old 20th September 2006, 18:34   #7
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
I did as you said, but it doesn't work.
em3 is offline   Reply With Quote
Old 20th September 2006, 18:39   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 20th September 2006, 18:42   #9
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
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.
em3 is offline   Reply With Quote
Old 20th September 2006, 18:45   #10
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Sorry, I meant Pre function.

!define MUI_PAGE_CUSTOMFUNCTION_PRE ComponentsPagePre
!insertmacro MUI_PAGE_COMPONENTS

Function ComponentsPagePre
...

-Stu
Afrow UK is offline   Reply With Quote
Old 20th September 2006, 19:26   #11
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
Still no luck. Now it looks like this...
code:

!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

em3 is offline   Reply With Quote
Old 20th September 2006, 21:22   #12
Comm@nder21
Major Dude
 
Join Date: Jul 2003
Location: germany, b-w
Posts: 734
Send a message via ICQ to Comm@nder21
IfFileExists "$WINDIR\NOTEPAD.EXE" Skip

use quotes its safer.
Comm@nder21 is offline   Reply With Quote
Old 20th September 2006, 21:59   #13
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
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.
em3 is offline   Reply With Quote
Old 21st September 2006, 03:18   #14
Animaether
Major Dude
 
Join Date: Jun 2001
Posts: 1,173
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.
Animaether is offline   Reply With Quote
Old 21st September 2006, 11:05   #15
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Just to confirm, I'm assuming that you want to uncheck the Section if Notepad doesn't exist?

-Stu
Afrow UK is offline   Reply With Quote
Old 22nd September 2006, 16:17   #16
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
If the file already exists, then uncheck.
em3 is offline   Reply With Quote
Old 22nd September 2006, 18:15   #17
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
You should read the docs again on IfFileExists. You're skipping your code if the file exists.

-Stu
Afrow UK is offline   Reply With Quote
Old 22nd September 2006, 21:20   #18
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
Documentation.
Quote:
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?
em3 is offline   Reply With Quote
Old 22nd September 2006, 21:27   #19
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
The jumps are explained earlier in the manual. But a better method is explained even earlier, in the tutorial.
code:
${If} ${FileExists} $WINDIR\notepad.exe
DetailPrint "notepad found"
${Else}
DetailPrint "notepad not found"
${EndIf}


NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 22nd September 2006, 21:40   #20
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
Thanks. I managed to figure it out though.

code:

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.
em3 is offline   Reply With Quote
Old 22nd September 2006, 23:34   #21
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 23rd September 2006, 09:17   #22
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
Ok so if I understand you correct, this code would do the same thing as the code above?

code:

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



EDIT: Tried but it didn't work. Unselect was always run.
em3 is offline   Reply With Quote
Old 23rd September 2006, 09:25   #23
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,343
No, because macros are not one instruction. Macros often contain more than one instruction.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Old 23rd September 2006, 09:28   #24
em3
Junior Member
 
Join Date: Sep 2005
Posts: 35
Ok. Thank you.
em3 is offline   Reply With Quote
Old 24th July 2007, 02:36   #25
51819
Member
 
Join Date: May 2007
Posts: 50
code:

!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?
51819 is offline   Reply With Quote
Old 24th July 2007, 10:40   #26
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Look at IfFileExists again.

Stu
Afrow UK is offline   Reply With Quote
Old 24th July 2007, 12:15   #27
51819
Member
 
Join Date: May 2007
Posts: 50
oh.yes!!!thanks

i know how to do it.
code:
!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

51819 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump