Old 14th March 2017, 19:20   #1
amkaaron96
Junior Member
 
Join Date: Mar 2017
Posts: 3
If File Exist Finding Files That Shouldn't Exist

Hi, I'm extremely new to NSIS but I've been picking it up pretty quickly. I'm trying to write a function that checks if a file exists, and if it does, define it, and then later install it. And if the file doesn't exist then just don't define it. However, every time I run the program, it supposedly finds the file even if it doesn't exist. I've deleted the files multiple times but it still creates them, and even installs them. Does any one know where NSIS could be finding these files? Any help is appreciated!

Code:
!include LogicLib.nsh

!define SOURCEPATH1 "C:\Program Files\PODS\Config Files"

IfFileExists "${SOURCEPATH1}\B1EZ1013_MAP085e_T.xml" 'secondDoesExist' 'secondNotExist' ;checks if file exists
secondDoesExist:
!define XMLFILENAME2 "B1EZ1013_MAP085e_T.xml" ;name the file
!define XMLNAME2 "B1EZ1013_MAP085" ;name the file

IfFileExists "${SOURCEPATH1}\B1EZ1009_MAP069Be_T.xml" 'thirdDoesExist' 'thirdNotExist' ;checks if file exists
thirdDoesExist:
!define XMLFILENAME3 "B1EZ1009_MAP069Be_T.xml" ;name the file
!define XMLNAME3 "B1EZ1009_MAP069B" ;name the file

secondNotExist:
!ifdef XMLFILENAME2
DetailPrint "Test. 2nd File is found and defined."
!endif

thirdNotExist:
!ifdef XMLFILENAME3
DetailPrint "Test. 3rd File is found and defined."
!endif
amkaaron96 is offline   Reply With Quote
Old 14th March 2017, 21:19   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,488
You are mixing compile-time and run-time concepts!

All instructions starting with ! are compile-time based and happen on the computer you are compiling on. You can use !if /fileexists with !define.

IfFileExists must be paired with $variables and they are usable on the end-users system.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 15th March 2017, 00:07   #3
amkaaron96
Junior Member
 
Join Date: Mar 2017
Posts: 3
Ok, so just so I'm understanding (hopefully), the files are always being found because I'm using a runtime syntax to check if they exist, but defining them at compile time. So when I compile, the files will automatically be defined, because it doesn't check if they exist until runtime. This would actually make sense because my code later on just checks that those files are defined as those names, and then installs them if they are. And if this is the case, the solution would be something like:

!if /fileexists "${SOURCEPATH1}\B1EZ1013_MAP085e_T.xml" 'secondDoesExist'
(not sure on that syntax, I see that !if can compare two values or use a non zero, not sure if I can still use gotos.)
'secondNotExist' ;checks if file exists
secondDoesExist:
!define XMLFILENAME2 "B1EZ1013_MAP085e_T.xml" ;name the file
!define XMLNAME2 "B1EZ1013_MAP085" ;name the file

If this is sounding wrong I apologize, I'm only a few days in and trying to learn as best as I can. This is my first language like this and it's pretty intimidating. Again, thanks in advance for your time and help.
amkaaron96 is offline   Reply With Quote
Old 15th March 2017, 00:49   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 4,488
No you cannot use goto with !if.

Quote:
!if x
!y
!else
!z
!endif
Maybe you should try reading the help file again, it should contain some small code snippets etc.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 15th March 2017, 14:30   #5
amkaaron96
Junior Member
 
Join Date: Mar 2017
Posts: 3
I was able to find some examples online after knowing what I was looking for. Thanks for the help!
amkaaron96 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