Have been working with NSIS (v3.05) for a few weeks. Does what it needs to do. I have been chasing the following problem for a few days and have not been able to comprehend it completely.
Problem statement:
Compare two (2) versions with each other. Many ways to implement. I chose the following:
1st 'version' (string) is retrieved from the currently installed versions .txt file via (function) LineRead (!include TextFunc.nsh) like this:
IfFileExists "C:\$PROGRAMFILES64\...\VERSION.txt" 0 +31 # Open the file and perform N FileRead
DetailPrint "VERSION.txt found!"
${LineRead} "C:\$PROGRAMFILES64\...\VERSION.txt" "7" $4 # $4 = '1.x.y.z' (for example)
2nd 'version' is retrieved with following code:
!getdllversion "C:\...\application_name.exe" expversion_
StrCpy $7 ${expversion_} # pass the define string 'expversion' to $7
As last part I use following code for comparison of $4 and $7:
${VersionCompare} $4 $7 $R0
This can only work as I know for sure that '$4' (version string #1) and '$7' (version string #2) are correct inputs for VersionCompare (output: $R0)
Question: Is there a way to display (for test/check) the content of $4 (# compile time) in order to know for sure var $4 contains the correct string to be passed to function 'VersionCompare'? (tried 'DetailPrint $4'; does not resolve into the expected string (retrieved by function 'LineRead'). (I know that 'DetailPrint' only displays during executing the installation '.exe. file So is makes sense not seeing that # compile time.)
Output from MakeNSIS:
IfFileExists: "C:\$PROGRAMFILES64\...\VERSION.txt" ? 0 : +31
DetailPrint: "VERSION.txt found!"
!insertmacro: LineReadCall
!insertmacro: end of LineReadCall
DetailPrint: "The version number of the currently installed app: $4"
How-To get $4 resolve into the version string (for testing purposes) during compile time)?
Question number 2:
I use the preprocessor command '!GetDLLVersion' in a function to retrieve version number of the to be installed version of the 'app' (via The NSIS Installer...). MakeNSIS displays resolving the version correctly:
Function: "VersionRetrievalBinary"
!getdllversion: C:\1_SW_dev\...\app.exe (1.8.47.5)->(expversion_<1..4>)
Question: What exactly is 'expverion_'?; a var or a define? If a define (which I read here => Reference/!getdllversion), do I need to define it in my script as follow?:
!define expverion_1 " " # Major; single digit
!define expverion_2 " " # Minor; 2-digit
!define expverion_3 " " # Build; 3-digit
!define expverion_4 " "# Revision; 3-digit
Being unsure what 'expversion_' exactly is and operates/works MakeNSIS throws following warning that -I think- indicates clearly something is incorrect:
warning 6000: unknown variable/constant "{expversion_}" detected, ignoring (C:\1_SW_dev\...\app_client.nsi:295)
The worrying part is the word 'ignoring' in the MakeNSIS compiling message. Can I conclude from above mentioned warning message that assigning the string derived from the (define?) with name "expversion_" is not passed to var $7 by means of command:
StrCpy $7 ${expversion_}
Following MakeNSIS message (# compile time) appears to confirm this:
StrCpy $7 "${expversion_}" () ()
It appears to resolve empty (unsure if I read this MakeNSIS message correctly).
Although having learned a lot wrt NSIS (and liking it) and gone through most of the relevant documentation I do not get my head around this one.
Thnx in advance for solving this specific piece of the puzzle.
Have solved the puzzle myself.
The solution to a version comparison is rather 'simple'. The essential parts herewith: (add to .onInit)
Create a function (e.g. name 'VersionComparison')
Read local version from registry
'Read' installation version from binary (e.g. .DLL or .exe)
Use VersionCompare (!include WordFunc.nsh) to perform the actual comparison.
I'll tackle the !getdllversion issue first. It extracts the 4 16-bit numbers from the start of the version info block and stores them in 4 defines. It simply uses the name you pass in plus a number when naming the defines.
!getdllversion "$%windir%\explorer.exe" foo
!warning ${foo2} ; This prints the minor version
There is no specific number of digits as expected by your comments. Each of the 4 numbers go from 0 to 65535.
You can do basic verification of these numbers at compile time:
!if ${foo1} < 1
!error "Major version must at least be 1, we don't ship beta software :) "
!endif
The 2nd problem is harder to solve. Variables can only be expanded when the installer is running. The only option is to actually generate and run a "installer" from inside your main .nsi:
!makensis vertest.nsi = 0
!execute '"$%temp%\vertest.exe" /S' = 0
!defile "$%temp%\vertest.exe"
where vertest.nsi would look something like
OutFile "$%temp%\vertest.exe"
RequestExecutionLevel user
SilentInstall silent
Section
Do version test here and Goto..
fail:
Abort
success:
SectionEnd
Related
I have the following code block inside the .onInit function of my NSIS script.
; Split the supplied artifacts array.
nsArray::Split ARTIFACT_ARRAY "${ARTIFACTS}" ";"
${ForEachIn} ARTIFACT_ARRAY $R0 $R1
File ${IVY_ROOT}\"$R1"
${Next}
The ${ARTIFACTS} is a passed in property from ANT at NSIS compile time and is basically a comma seperated list of files. When I attempt to compile the script I get the error below.
[exec] File: "C:\My_Workspaces\WEnDL\\deployments\ivy\"$R1"" -> no files found.
[exec] Usage: File [/nonfatal] [/a] ([/r] [/x filespec [...]] filespec [...] |
[exec] /oname=outfile one_file_only)
[exec] Error in script "C:\My_Workspaces\WEnDL\/deployments/selections.nsis" on line 394 -- aborting creation process
Any pointers appreciated.
You cannot use variables in File instructions because variables are only evaluated on the end-users system. The same is true for plug-ins. You need to stick with ${defines} and the instructions starting with ! when parsing at compile-time.
The best option is letting your build system generate a .nsh with the File instructions if possible:
Section
SetOutPath $InstDir
!include "generatedfilelist.nsh"
SectionEnd
Another option is to call external tools or batch-files with !system and let them parse the list and generate the .nsh.
Finally, in NSIS v3 it might be possible to pull this off with macro recursion and !searchparse+!searchreplace but the available recursion depth is limited so it might not work depending on the number of files in your list.
I have a problem with recursive search, but first some key data:
I have several directories filled with sql files which I want to copy to $TEMP
the directories i want to read from look like this v2.1.0.0
at the moment, the directories v2.5.0.0 to v2.7.0.3 have to be read
folders dont have to be "the next" so v2.5.0.3 can follow v2.5.0.0
I'm using the LogicLib
I'm new to this language (before java) and this is my first task
I'm currently trying to solve the problem with a ${ForEach}
!macro GetSQLVersionFiles first second third fourth
SetOutPath $TEMP
${ForEach} ${first} 0 9 + 1
${ForEach} ${second} 0 9 + 1
${ForEach} ${third} 0 9 + 1
${ForEach} ${fourth} 0 9 + 1
IfFileExists "scripte\v${first}.${second}.${third}.${fourth}" 0 +2
File "scripte\v${first}.${second}.${third}.${fourth}\*.sql"
${next}
${next}
${next}
${next}
!macroend
so my idea was, to make it viable for later, to have a macro with 4 parameters in which one can put the start directory, say the desired "2 5 0 0" and it iterates through every folder and puts the found .sql files into the $TEMP directory
things i've already tried
refering to all parameters without the {}
writing "${first} ${first} 9 + 1 (thought this would only iterate FROM first to 9)
the error i get is following
!insertmacro: _ForEach
Usage: StrCpy $(user_var: output) str [maxlen] [startoffset]
Error in macro _ForEach on macroline 3
Error in macro GetSQLVersionFiles on macroline 2
Error in script "\\NAMEOFMYSCRIPT -- aborting creation process
the third line in _ForEach of the LogicLib is
StrCpy "${_v}" "${_f}" ; Assign the initial value
Thanks in advance for your help :)
You are mixing defines and variables.
Defines are created with !define and accessed with ${name}.
Variables are created with Var and accessed with $name. There are also some built in variables you can use: $0..$9.
Variables can be changed at run-time, defines cannot.
The other issue is that you cannot use the File instruction to copy files on the end-users machine, you need to use the CopyFiles instruction if you want to copy files at run-time. If on the other hand you want to extract files from the installer (I cannot tell which you want based on your question) then you do need to use the File instruction but then you cannot use ${For} because it is a run-time concept. You can use !system to execute a batch file that builds a list of files in a .nsh that you then !include.
I am using Windows version of NMAKE. I would like to check for file existence in a make file. If it exists I need to delete it. Here is my code:
!IF EXIST ("C:\ABC.XML")
#del ABC.XML
!ELSE
#echo "FILE DOESN'T EXIST
!ENDIF
The above code is not working. I could not figure it out the problem. Please help.
Your code doesn't work because !IF, !ELSE and !ENDIF are a preprocessing directives and the result of preprocessing must produce a valid makefile. Commands are only allowed as part of what Microsoft calls a description block which are required to start with a dependency line with one or more targets and zero or more dependents.
You can get around this by executing your commands during the preprocessing stage by including them in a preprocessing directive surrounded by brackets ([]). Something like this:
!IF EXIST(C:\ABC.XML)
! IF [del C:\ABC.XML]
! ENDIF
!ELSEIF [echo FILE DOESN'T EXIST]
!ENDIF
The second !IF and the !ELSEIF directives are used to provide a context for the commands so they're executed during the preprocessing phase.
However I think you'd probably be better moving the del command to a description block where it's actually needed. For example if file ABC.XML needs to be deleted before it can be rebuilt, use something like this:
ABC.XML: ABC.CSV
-rem The csv2xml translator requires that the XML file not already exist
-#del ABC.XML 2> NUL
csv2xml ABC.CSV ABC.XML
I am new to NSIS i am trying to execute an executable while installation similar to pre request. I tried the below code which copies the exe to the installation path but it is not executing it.
Section "example" example
SetOutPath "$INSTDIR"
File "setup.exe"
Exec "$INSTDIR\setup.exe"
BringToFront
SectionEnd
The answer from Seki is mostly correct, I'd just like to add that the correct syntax for Exec/ExecWait is always Exec '"c:\path\app.exe" param1 "par am2" param3'
Parameters are of course optional but the path to the app should always be quoted, not just because in your case where $INSTDIR could contain spaces but at least on Win9x it will fail no matter what if you don't quote (According to the NSIS manual)
If the spaces/lack of quotes is not the issue then there are a couple of other things you might want to look into:
$OUTDIR is the working directory for the new process (SetOutPath sets this)
Missing dll's etc (Check with Process Monitor)
Do the $INSTDIR variable maps to a directory whose name contains spaces? If so, you should add simple quotes to include the double quotes into the Execargument :
Exec '"$INSTDIR\setup.exe"'
I have bash script that I use regularly in my job to automate a large job. I was making some changes today, but everything seemed fine. The script itself is about 1700 lines long. The first part of the script is all good and runs through all the user input and logic just fine. It then proceeds into the core of the script and stops working at exactly line 875 (tested the script with bash -x to find the break point). However, it breaks with the following error:
script.sh: line 1341: syntax error near unexpected token `;;'
script.sh: line 1341: ` ;;'
Line 1341 is in the middle of a case statement. The following code is the beginning of that block of code where it is breaking:
if [[ $VAR1 = "TRUE" && $VAR2 = "VAL2" ]]; then
VERSION=`XXXXXXXXXXXXXXXX`
## Set variables based on location $VAR3
case $VAR3 in
STR1 )
case $VERSION in
STR2 )
VAR4 = "STR5"
VAR5 = "STR6"
VAR6 = "STR7"
VAR7 = "STR8"
Line 1341 ---> ;;
STR3 )
VAR4="STR9"
VAR5="STR10"
VAR6="STR11"
VAR7="STR12"
;;
STR4 )
VAR4="STR13"
VAR5="STR14"
VAR6="STR15"
VAR7="STR16"
;;
esac
VAR8="STR17"
VAR9="STR18"
VAR10=1
VAR11="STR19"
;;
Because of the sensitive nature of what I do, I obviously had to remove quite a bit of information. I know this may make things more difficult to help me with. However, all VAR##="STR##" are standard variable declarations with string values, nothing special (no variable substitution, etc). All the variables are used later in the script. The code for VERSION returns a string value, which is used in the nested case.
The script was working fine up until my changes today, but I really didn't touch this section, with the exception of tweaking some of the STR values. I tried setting $VAR3 and $VERSION variables in quotes "", as well as the STR values used as the cases. I tried taking out this block entirely, only to have it fail on the next block (STR1 has a different value thus change the variable declarations). I have it output to the console what it is doing as well as checks for errors after most functions. There is nothing out of the ordinary on the console and nothing in the error log.
Any help would be appreciated, and I know I'm asking a lot.
By the way here is the code around line 875 where the script stops running (no errors generated based on the code here). Again, with bash -x I could see the VAR2 variable get set, but the script breaks before the next for loop starts.
## Create file ##
echo 'Creating files . . . '
j=0
p=1111
if [ $VAR1 = "TRUE" ]
then
VAR2=1
else
VAR2=2
fi
for i in `seq 1 $HOWMANY`; do <----Line 875
echo -n "Creating file . . . "
echo "XXXXXXXXXXX
Thanks again.
The problem is likely somewhere between line 875 (or a bit earlier) and line 1341. It maybe a misplaced quote or something less subtle. It will be essentially impossible for us to debug without all the original material between those lines.
Suggestion 1: run with 'bash -n -v' and see whether that gives you any insight into the problem.
Suggestion 2: split the script into smaller pieces that are more easily managed - and that can be separately debugged. The biggest scripts I have (out of 400 in my bin directory) are from the autoconf suite - they weigh in at just under 1100 lines; the next biggest is mine, and the 750 line script is too d..n big. The next biggest scripts are between 600 and 700 lines of Perl (including Perl documentation).
Having said 'missing quote', I see that your fragment close to line 875 has:
echo -n "Creating file . . . "
echo "XXXXXXXXXXX
with a missing close double quote from the second echo.
You also mentioned making changes, albeit not close to the point where the script breaks. Since you have the code under version control (you wouldn't dream of playing with a 1700 line script without backups, would you?), you should look at the actual changes again.
Or even back up to the previous working version, and make the changes again, one at a time, carefully, until you see why you broke something.
You have spaces around your equal signs in this section:
case $VERSION in
STR2 )
VAR4 = "STR5"
VAR5 = "STR6"
VAR6 = "STR7"
VAR7 = "STR8"
Take those out and you may be OK (unless that's a posting error).