.:: CODE SNIPPET ::.

"Your time is limited, so don't waste it living someone else's life"

Tag Archives: NSIS

How to indicate the remote host’s os


This post introduce how to find the remote machine(s) is Window or Linux in the system UI – Data Server – Equipment Service. In this case, if remote DS is Windows, you have to install Cygwin which simulate Linux environment on Windows, so you can execute the same command for both platform. After that, you will use plink application to get the output of command uname into a file, we check the file out and there is some key word for every operation system like: Linux (Linux) or Cygwin (Windows)
Read more of this post

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.
Read more of this post

Detect default browser and launch in NSIS


Window supports us with a function to get any default executable application of a file. So we will get the default browser by create a empty *.htm file then get it’s default executable program, and that is also the default browser

Section
    InitPluginsDir
    FileOpen $0 "$PLUGINSDIR\dummy.htm" "w"
    FileClose $0
    System::Call "Shell32::FindExecutable(t '$PLUGINSDIR\dummy.htm', i 0, t .r1)"
    Exec '"$1" http://google.com'
SectionEnd

Check for available disk space and required disk space in NSIS


Get available disk space:
We use the macro DriveSpace

Section
    ${DriveSpace} "C:\" "/D=F /S=M" $R0
    ; $R0="2530"
SectionEnd

Get the required disk space of your program
To do this, you will in turn get the required disk space of every section in your script, then we will plus all of the results. We use the SectionGetSize instruction to get the required disk space

Section "plink" secPlink
    File "plink.exe"
SectionEnd
SectionGetSize ${secPlink} $R1

How to read an text file line by line in NSIS


This is just a small snippet to guide how to read text file by every line in NSIS
NSIS support instruction FileRead to read the line of a file, we just use it in a loop

FileOpen $0 $INSTDIR\file.dat r
LOOP:
ClearErrors
IfErrors exit_loop
FileRead $0 $1
DetailPrint $1
Goto LOOP
exit_loop:
FileClose $0

How to customize the default page in NSIS


As you know, NSIS supports user with default pages with fixed controls on its UI. So, the problem is how we can customize those page with our own control. This is impossible on NSIS2, upgrade to NSIS 3, we got the MUI2 instead of MUI. Hence, we can customize the default pages.

MUI2 supports the macros to customize pages as flowing point:

MUI_CUSTOMFUNCTION_GUIINIT function
MUI_CUSTOMFUNCTION_UNGUIINIT function
MUI_CUSTOMFUNCTION_ABORT function
MUI_CUSTOMFUNCTION_UNABORT function
MUI_CUSTOMFUNCTION_ONMOUSEOVERSECTION function
MUI_CUSTOMFUNCTION_UNONMOUSEOVERSECTION function

MUI_PAGE_CUSTOMFUNCTION_PRE function
MUI_PAGE_CUSTOMFUNCTION_SHOW function
MUI_PAGE_CUSTOMFUNCTION_LEAVE function

where can we put those macros?
The answer is before the default macros.
Example:

!insertmacro MUI_PAGE_CUSTOMFUNCTION_PRE func_ComponentPage_Pre
!insertmacro MUI_PAGE_COMPONENTS
Function func_ComponentPage_Pre
; do the stuff to pre-create the component page
FunctionEnd

NSIS script flow chart


After many hour research and test, i found that the running flow of a NSIS script like below;

Flow chart

%d bloggers like this: