NSIS IfFileExists - more than one line
Asked Answered
H

1

11

I'm using the IfFileExists function but I think it only include the first line after the jump. How can I do something similar to C like {..../.../....}?!

IfFileExists "$PROGRAMFILES\InduSoft Web Studio v7.0\Bin\RunStartUp.exe" StartUpExists PastStartUpExists
      StartUpExists:
        StrCpy $Text "$PROGRAMFILES\InduSoft Web Studio v7.0\Bin\RunStartUp.exe"

      PastStartUpExists:
        nsDialogs::Create 1018
        Pop $Dialog

        nsDialogs::SelectFileDialog open "$PROGRAMFILES\InduSoft Web Studio v7.0\Bin\RunStartUp.exe" "*.exe"

        Pop $Text

        ${NSD_CreateText} 0 13u 100% -13u $Text
        Pop $Text

        ${NSD_CreateText} 0
        ${NSD_GetText} $Text $0

        CreateShortCut "$SMPROGRAMS\Advanlab\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
        CreateShortCut "$SMPROGRAMS\Advanlab\Uninstall.lnk" "$INSTDIR\uninst.exe"
        CreateShortCut "$SMPROGRAMS\Advanlab\Advanlab.lnk" "$0"
        CreateShortCut "$DESKTOP\Advanlab.lnk" "$0"
Heist answered 14/9, 2012 at 10:58 Comment(0)
R
27

The syntax of IfFileExists is

IfFileExists file_to_check offset_or_label_if_exists [offset_or_label_if_not_exists]

If you plan to execute either a block or another block, don't forget to jump over the second block.

Thus a simple case would be:

IfFileExists "$INSTDIR\file.txt" file_found file_not_found
file_found:
StrCpy $0 "the file was found"
goto end_of_test ;<== important for not continuing on the else branch
file_not_found:
StrCpy $0 "the file was NOT found"
end_of_test:

If one of the blocks is just after the IfFileExists you can use a 0 offset instead of a useless label:

IfFileExists "$INSTDIR\file.txt" 0 file_not_found
StrCpy $0 "the file was found"
goto end_of_test ;<== important for not continuing on the else branch
file_not_found:
StrCpy $0 "the file was NOT found"
end_of_test:
Rhetorical answered 14/9, 2012 at 12:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.