Home > Others > Get size on disk of package in nsis

Get size on disk of package in nsis

In case you want to deploy package to remote host. That means the installer can install on remote machine. You should pack the installation component into package may be tar.gz. So, in the component page the Space required control will show the wrong required space for hard disk. In this case, you should calculate the size of the package yourself and display in the control. Since, we get two things to do here: Get the actual size on disk of package, and display it on the Space required control which is instructed in the next post.

Get the space
One of the solution is to use another application named 7za.exe.
+ From nsis we will execute the application and write out the output contains the size on disk of the package.
+ Read the content of text file and get the size on disk you need.

Function GetPackageSize
	Pop $0
	StrCpy $1 -6
	StrCpy $2 "Size = "
	StrCpy $3 -5
	StrCpy $4 "Packed Size = "
	ExecDos::exec '"${DEPLOY_DIR}\7za.exe" l -slt $0' "" "${DEPLOY_DIR}\package_size.txt"
	${LineRead} "${DEPLOY_DIR}\package_size.txt" "$1" $R0
	StrCpy $R0 $R0 -2
	${StrStr} $1 $R0 "$2"
	StrCmp $1 "" +5 0
	StrLen $1 "$2"
	StrCpy $R0 $R0 "" $1
	Push $R0
	Goto +2
	Push 0
	${LineRead} "${DEPLOY_DIR}\package_size.txt" "$3" $R1
	StrCpy $R1 $R1 -2
	${StrStr} $3 $R1 "$4"
	StrCmp $3 "" +5 0
	StrLen $3 "$4"
	StrCpy $R1 $R1 "" $3
	Push $R1
	Goto +2
	Push 0

Here we can see that i use the function ExecDos::exec and LineRead. ExecDos is a plugin you can easily download and copy to plugin/ansi. Otherwise, user of nsis 2 can no use LineRead, so you should upgrade your nsis version to 3 or easily search for this function.
We can make it more easy to use via a macro definition like.

!macro AddSectionSize Package
	Push ${Package}
	Call GetPackageSize
	Pop $0 ;	packed size
	Pop $1 ;	size on disk
Categories: Others Tags: , , ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: