Archive: AddSize/SectionSetSize


AddSize/SectionSetSize
I am having some trouble with getting AddSize/SectionSetSize to work. I have seen several posts with people having trouble with these, but none that solved my problem.

Because of the 2 Gb limit of file size in compression, I am trying to first compress the file I want to install with the 7-Zip package, and then uncompress at runtime with 7za.exe as described in several posts. Now I want to set the size of the section correct, because the FILE command to include the zipped file will only show the compressed size. With AddSize I can do this at compile time as I want, but only with a fixed number. Instead I can do this at runtime with SectionSetSize but it will only use the users environment, which doesn't have the file I'm installing. With ${GetSize} I can get the size of the file, but it seems only at runtime, not compile-time.

What I want is not to have to code the size with AddSize with a fixed number, because each time I compile, the file name will be the same, but the size might have changed. So I want the expected size to be calculated from the uncompressed file at compile time, and then the installer to reflect the correct size at runtime. Is that possible with NSIS?


Calculate it at "runtime" by executing another installer in compile time.

http://nsis.sourceforge.net/Invoking...n_compile-time


Include big files (> 2 Gb) with 7z compression
Thanks for pushing me in the right direction, kichik! This shows once again what a versatile package NSIS is. Too bad that it can't compress bigger files than 2 Gb though. Those who get the #12345 error mmapping, you know who you are! This happens with files smaller than 2 Gb though. Mine was 1.6 Gb. Also note that this way of doing things also has the advantage of making a quicker main compilation, especially when making changes to it, because it doesn't need to make a full compression from scratch of the big file.

For the record if anybody wants the solution I came up with, here is the outline:

First you download both the 7-zip package and then the 7-zip Command line version (they are separate downloads) from

http://www.7-zip.org/download.html

Then you compress the file(s) you want to include, e.g. IWIS3-GMS.mdb to IWIS3-GMS.7z with the Windows interface of 7-zip (well, there are also Linux version I guess). And then you create a script to get the file size at compile time (this program creates an EXE, needs to be compiled only once, and the EXE will be run from the main script). 7za.exe is the command line unzipper.

This is GetDBsize.nsi:

!define FileGMS "C:\ICIS5\Database\IWIS3\Central\IWIS3-DMS.mdb"
!include "FileFunc.nsh"
!insertmacro GetSize

OutFile "GetDBsize.exe"
SilentInstall silent

Section
## Write it to a !define for use in main script
FileOpen $R0 "$EXEDIR\GetDBsize.txt" w
; Get Database Size DMS
${GetSize} "C:\ICIS5\Database\IWIS3\Central" "/M=IWIS3-DMS.mdb /S=0K /G=0" $0 $1 $2
FileWrite $R0 '!define SizeDMS "$0"$\r$\n'
FileClose $R0
SectionEnd

Compile it to produce GetDBsize.exe

Then the main script:

SetCompressor lzma

!system "GetDBsize.exe"
!include "GetDBsize.txt"
...
Function .onInit
; Change the section size here
SectionSetSize InstDMS ${SizeDMS}
...
FunctionEnd

Section "Install IWIS3 DMS database" InstDMS
SETOUTPATH $INSTDIR
File "C:\Program Files\7-Zip\7za.exe"
SETOUTPATH $INSTDIR\Database\IWIS3\Central
File C:\ICIS5\Database\IWIS3\Central\IWIS3-DMS.7z
nsExec::ExecToLog /OEM '"$INSTDIR\7za.exe" x "$INSTDIR\Database\IWIS3\Central\IWIS3-DMS.7z" -o"$INSTDIR\Database\IWIS3\Central"'
Delete $INSTDIR\Database\IWIS3\Central\IWIS3-DMS.7z
Delete $INSTDIR\7za.exe
SectionEnd
...


I found a few bugs in the script above. The correct code for changing section size should be

SectionSetSize ${InstDMS} "${SizeDMS}"
not
SectionSetSize InstDMS ${SizeDMS}

and also it seems to be important that .onInit section is placed *after* the section(s) it tries to change the size of in the script, in this example section .onInit should be after section InstDMS. Otherwise all the section sizes will be zero.