Here's what I'm trying to do and am not sure if it's actually possible:
;compileTime
IfFileExists onLocalMachine
Do
;Runtime
Unregister dll
Copy dll from local to dest
Register dll
Done
Endif
In other words, I want to ignore a section of code if a certain file doesn't exist at compile time.
Thanks,
Eric
ifFileExists - compile time
9 posts
I think I know the answer to this. Tell me if I'm wrong:
IfFileExists is compile time
FindFirst is run time
If that's the case, I'm square. I'm going to code based on this assumption.
Thanks,
Eric
IfFileExists is compile time
FindFirst is run time
If that's the case, I'm square. I'm going to code based on this assumption.
Thanks,
Eric
Looks to me like I'm wrong based on the documentation for DLL/TLB Library Setup. IfFileExists is looking on the destination machine.
I tried, but I guess you are better at searching this forum. So, I tried to do basically what they're doing and failed. Any help on what I'm doing wrong?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Backgound Colors
BGGradient 800080 000000 FFFFFF
BrandingText " "
Name "Test"
;Output File Name
OutFile "test.exe"
;The Default Installation Directory
InstallDir "D:\NoWhereLand"
Section "Install"
!system 'IF EXIST "D:\myFile.txt" ECHO !define MyVar'
!ifdef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"file exists $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"finished $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
SectionEnd
Section "Shortcuts"
;Add Shortcuts
SectionEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Thanks,
Eric
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Backgound Colors
BGGradient 800080 000000 FFFFFF
BrandingText " "
Name "Test"
;Output File Name
OutFile "test.exe"
;The Default Installation Directory
InstallDir "D:\NoWhereLand"
Section "Install"
!system 'IF EXIST "D:\myFile.txt" ECHO !define MyVar'
!ifdef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"file exists $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"finished $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
SectionEnd
Section "Shortcuts"
;Add Shortcuts
SectionEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Thanks,
Eric
Nevermind, I see what I missed:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Backgound Colors
BGGradient 800080 000000 FFFFFF
BrandingText " "
Name "Test"
;Output File Name
OutFile "test.exe"
;The Default Installation Directory
InstallDir "D:\NoWhereLand"
Section "Install"
!system 'IF EXIST "D:\myFile.txt" ECHO !define MyVar>"%TEMP%\Temp$$$.nsh"'
!include "$%TEMP%\Temp$$$.nsh"
!system 'DEL "%TEMP%\Temp$$$.nsh"'
!ifdef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"file exists $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"finished $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
SectionEnd
Section "Shortcuts"
;Add Shortcuts
SectionEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Backgound Colors
BGGradient 800080 000000 FFFFFF
BrandingText " "
Name "Test"
;Output File Name
OutFile "test.exe"
;The Default Installation Directory
InstallDir "D:\NoWhereLand"
Section "Install"
!system 'IF EXIST "D:\myFile.txt" ECHO !define MyVar>"%TEMP%\Temp$$$.nsh"'
!include "$%TEMP%\Temp$$$.nsh"
!system 'DEL "%TEMP%\Temp$$$.nsh"'
!ifdef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"file exists $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"finished $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
SectionEnd
Section "Shortcuts"
;Add Shortcuts
SectionEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
You're missing about 80% of the code.
You're missing those 3 main parts.
Edit: You just updated your post when I posted 🙂
-Stu
It's writing a define to a temp file and then !including that temp file (and then deleting it).
!system 'IF EXIST "C:\NsisBuilds\MaybeFileMaybeNot\file.txt" ECHO !insertmacro MUI_INSTALLOPTIONS_WRITE "Menu.ini" "Field 3" "Flags" "DISABLED">"%TEMP%\Temp$$$.nsh"'
!include "$%TEMP%\Temp$$$.nsh"
!system 'DEL "%TEMP%\Temp$$$.nsh"'
You're missing those 3 main parts.
Edit: You just updated your post when I posted 🙂
-Stu
Is there a way to modularize this? I tried, but it doesn't seem to work. Anyone see what I'm doing wrong?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Backgound Colors
BGGradient 800080 000000 FFFFFF
BrandingText " "
Name "Test"
;Output File Name
OutFile "test2.exe"
;The Default Installation Directory
InstallDir "D:\NoWhereLand"
Section "Install"
StrCpy $8 'D:\myFile.txt'
call checkFileExists
!ifdef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"D:\myFile.txt file exists $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
!ifndef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"myFile.txt file doesn't exist $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
StrCpy $8 'D:\noFile.txt'
call checkFileExists
!ifdef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"D:\noFile.txt file exists $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
!ifndef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"noFile.txt file doesn't exist $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
SectionEnd
Section "Shortcuts"
;Add Shortcuts
SectionEnd
Function checkFileExists
!ifdef MyVar
!undef MyVar
!endif
!system 'ECHO ;$8 FileCheck>"%TEMP%\Temp$$$.nsh"'
!system 'IF EXIST "$8" ECHO !define MyVar>"%TEMP%\Temp$$$.nsh"'
!include "$%TEMP%\Temp$$$.nsh"
!system 'DEL "%TEMP%\Temp$$$.nsh"'
FunctionEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Backgound Colors
BGGradient 800080 000000 FFFFFF
BrandingText " "
Name "Test"
;Output File Name
OutFile "test2.exe"
;The Default Installation Directory
InstallDir "D:\NoWhereLand"
Section "Install"
StrCpy $8 'D:\myFile.txt'
call checkFileExists
!ifdef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"D:\myFile.txt file exists $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
!ifndef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"myFile.txt file doesn't exist $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
StrCpy $8 'D:\noFile.txt'
call checkFileExists
!ifdef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"D:\noFile.txt file exists $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
!ifndef MyVar
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"noFile.txt file doesn't exist $\n$\nClick `OK` to continue \
or `Cancel` to abort." \
IDOK +1
!endif
SectionEnd
Section "Shortcuts"
;Add Shortcuts
SectionEnd
Function checkFileExists
!ifdef MyVar
!undef MyVar
!endif
!system 'ECHO ;$8 FileCheck>"%TEMP%\Temp$$$.nsh"'
!system 'IF EXIST "$8" ECHO !define MyVar>"%TEMP%\Temp$$$.nsh"'
!include "$%TEMP%\Temp$$$.nsh"
!system 'DEL "%TEMP%\Temp$$$.nsh"'
FunctionEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
All NSIS variables $0-$9 ... are run-time.
Name "Test"
OutFile "Test.exe"
Section "Install"
!ifdef MyVar
!undef MyVar
!endif
!system 'IF EXIST "D:\myFile.txt" IF EXIST "D:\noFile.txt" ECHO !define MyVar>>"%TEMP%\Temp$$$.nsh"'
!include "$%TEMP%\Temp$$$.nsh"
!system 'DEL "%TEMP%\Temp$$$.nsh"'
!ifdef MyVar
MessageBox MB_OK '"D:\myFile.txt" and "D:\noFile.txt" were exist at compile-time'
!endif
!ifndef MyVar
MessageBox MB_OK '"D:\myFile.txt" and "D:\noFile.txt" were not exist at compile-time'
!endif
SectionEnd