Warning: Undefined variable $mode in /var/www/virtual/qbnz.com/htdocs/highlighter/examples/nsis/full-example.php on line 6
GeSHi - Generic Syntax Highlighter :: Examples
 
Navigation
Home News Examples Demo Downloads FAQ Documentation Mailing Lists License
Support GeSHi!
If you're using GeSHi, why not help GeSHi out? You can link to GeSHi with this image:
Powered by GeSHi
Get the HTML

Project Status
The latest stable version of GeSHi is 1.0.8.11, released on the 19th of Aug, 2012.

Supported Languages:
*ABAP
*Actionscript
*ADA
*Apache Log
*AppleScript
*APT sources.list
*ASM (m68k)
*ASM (pic16)
*ASM (x86)
*ASM (z80)
*ASP
*AutoIT
*Backus-Naur form
*Bash
*Basic4GL
*BlitzBasic
*Brainfuck
*C
*C for Macs
*C#
*C++
*C++ (with QT)
*CAD DCL
*CadLisp
*CFDG
*CIL / MSIL
*COBOL
*ColdFusion
*CSS
*D
*Delphi
*Diff File Format
*DIV
*DOS
*DOT language
*Eiffel
*Fortran
*FourJ's Genero
*FreeBasic
*GetText
*glSlang
*GML
*gnuplot
*Groovy
*Haskell
*HQ9+
*HTML
*INI (Config Files)
*Inno
*INTERCAL
*IO
*Java
*Java 5
*Javascript
*KiXtart
*KLone C & C++
*LaTeX
*Lisp
*LOLcode
*LotusScript
*LScript
*Lua
*Make
*mIRC
*MXML
*MySQL
*NSIS
*Objective C
*OCaml
*OpenOffice BASIC
*Oracle 8 & 11 SQL
*Pascal
*Perl
*PHP
*Pixel Bender
*PL/SQL
*POV-Ray
*PowerShell
*Progress (OpenEdge ABL)
*Prolog
*ProvideX
*Python
*Q(uick)BASIC
*robots.txt
*Ruby
*Ruby on Rails
*SAS
*Scala
*Scheme
*Scilab
*SDLBasic
*Smalltalk
*Smarty
*SQL
*T-SQL
*TCL
*thinBasic
*TypoScript
*Uno IDL
*VB.NET
*Verilog
*VHDL
*VIM Script
*Visual BASIC
*Visual Fox Pro
*Visual Prolog
*Whitespace
*Winbatch
*Windows Registry Files
*X++
*XML
*Xorg.conf

GeSHi 1.0.8.11 is the current stable release, with eighteen new languages and bug fixes over the last release.

GeSHi 1.1.2alpha5 is the current latest version from the development branch, with full C support (see the GeSHi development website).
Subscribe
RSS 2
Mailing Lists
HomeNewsExamplesDemoDownloadsFAQDocumentationMailing ListsLicense 
5:05 am GMT

Examples

Examples » NSIS
  1. ;======================================================
  2. ; Include
  3.  
  4.   !include "MUI.nsh"
  5.  
  6. ;======================================================
  7. ; Installer Information
  8.  
  9.   Name "Installer version 1.0.3"
  10.   OutFile "Installer_1.0.3.exe"
  11.   InstallDir C:\App
  12.  
  13. ;======================================================
  14. ; Modern Interface Configuration
  15.  
  16.   !define MUI_HEADERIMAGE
  17.   !define MUI_ABORTWARNING
  18.   !define MUI_COMPONENTSPAGE_SMALLDESC
  19.   !define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
  20.   !define MUI_FINISHPAGE
  21.   !define MUI_FINISHPAGE_TEXT "Thank you for installing the appname.\r\n\n\nYou can check the install by going to the Test Page at:http://appname/testpage.jsp"
  22.   !define MUI_WELCOMEFINISHPAGE_BITMAP "..\somepic.bmp"
  23.   !define MUI_ICON "..\someicon.ico"
  24.  
  25. ;======================================================
  26. ; Defines for the Mutually Exclusive functions
  27.   !define SF_SELECTED   1
  28.   !define SF_SUBSEC     2
  29.   !define SF_SUBSECEND  4
  30.   !define SF_BOLD       8
  31.   !define SF_RO         16
  32.   !define SF_EXPAND     32
  33.   !define SECTION_OFF   0xFFFFFFFE
  34.  
  35. ;======================================================
  36. ; Pages
  37.  
  38.   !insertmacro MUI_PAGE_WELCOME
  39.   !insertmacro MUI_PAGE_COMPONENTS
  40.   Page custom customerConfig
  41.   Page custom priorApp
  42.   !insertmacro MUI_PAGE_DIRECTORY
  43.   !insertmacro MUI_PAGE_INSTFILES
  44.   !insertmacro MUI_PAGE_FINISH
  45.  
  46. ;======================================================
  47. ; Languages
  48.  
  49.   !insertmacro MUI_LANGUAGE "English"
  50.  
  51. ;======================================================
  52. ; Reserve Files
  53.  
  54.   ReserveFile "..\customerConfig.ini"
  55.   ReserveFile "..\priorApp.ini"
  56.   !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
  57.  
  58.  
  59. ;======================================================
  60. ; Variables
  61.   var varCustomerName
  62.   var varCustomerLicense
  63.   var varPriorApp
  64.   var varPreviousVersion
  65.  
  66. ;======================================================
  67. ; Sections
  68.  
  69. Section "Install a full application" fullInstallSection
  70.   ; Version checking logic
  71.   ; This will send out a warning if the same version is already installed
  72.   ; Open the file and assign it the handle $R8
  73.   FileOpen $R8 "C:\app\docs\version.txt" r
  74.   ; Go to position 11 on the first line of the file
  75.   FileSeek $R8 11
  76.   ; Read from there until the end of the line and copy to the variable
  77.   FileRead $R8 $varPreviousVersion
  78.   ; If the variable is empty (which will mean the file is not there in this
  79. case
  80.   ; go to lbl_noprev. Otherwise go to lbl_prev
  81.   StrCmp $varPreviousVersion "" lbl_noprev lbl_prev
  82.  
  83.   lbl_noprev:
  84.   ; Close the file (otherwise you'll have some problems during the copying of
  85.   ; files that override the version.txt file
  86.   FileClose $R8
  87.   GoTo lbl_prevdone
  88.  
  89.   lbl_prev:
  90.   ;MessageBox MB_OK "Previous version: $varPreviousVersion"
  91.   ; Close the file (otherwise you'll have some problems during the copying of
  92.   ; files that override the version.txt file
  93.   FileClose $R8
  94.   ; If the variable is equal to 1.0.3, which is the version of this installer,
  95.   ; go to lbl_warn, otherwise for to lbl_del
  96.   StrCmp $varPreviousVersion "1.0.3" lbl_warn lbl_del
  97.  
  98.       lbl_warn:
  99.       ; Ask confirmation to user that they want to install 1.0.3 even though they
  100.       ; already have it installed. If they click OK, go to lbl_prevdone, if they click
  101.       ; Cancel, go to lbl_ABORT
  102.       MessageBox MB_OKCANCEL|MB_ICONQUESTION "Existing install is the same version as this installer. The existing install will be removed. Do you want to continue?" IDOK lbl_prevdone IDCANCEL lbl_ABORT
  103.  
  104.              lbl_ABORT:
  105.              ; Abort the install
  106.              ABORT
  107.              GoTo lbl_del
  108.  
  109.                     lbl_del:
  110.                     ; Delete the previous install by deleting a file and a directory
  111.                     Delete "$varPriorapp\bin\app.bat"
  112.                     ; The /r ensures the directory will be deleted even though it's not empty
  113.                     RMDir /r "$varPriorapp\webapps"
  114.                     GoTo lbl_prevdone
  115.  
  116.   lbl_prevdone:
  117.  
  118.   SetOutPath $INSTDIR
  119.  
  120.   File /r "app\*.*"
  121.  
  122.   ; Replace Customer Name in config.properties
  123.   Push @CustomerName@                        #text to be replaced
  124.   Push $varCustomerName                      #replace with
  125.   Push all                                   #replace all occurrences
  126.   Push all                                   #replace all occurrences
  127.   Push $INSTDIR\config\config.properties     #file to replace in
  128.   Call AdvReplaceInFile                      #call find and replace function
  129.  
  130.   ; Replace Customer License in config.properties
  131.   Push @CustomerLicense@                     #text to be replaced
  132.   Push $varCustomerLicense                   #replace with
  133.   Push all                                   #replace all occurrences
  134.   Push all                                   #replace all occurrences
  135.   Push $INSTDIR\config\config.properties     #file to replace in
  136.   Call AdvReplaceInFile                      #call find and replace function
  137. SectionEnd
  138.  
  139. Section "Install a Patch to an existing app" installPatchSection
  140.   ; Version checking logic
  141.   ; This will send out a warning if the same version is already installed
  142.   ; and abort if there is no previous version
  143.   ; Open the file and assign it the handle $R8
  144.   FileOpen $R8 "C:\app\docs\version.txt" r
  145.   ; Go to position 11 on the first line of the file
  146.   FileSeek $R8 11
  147.   ; Read from there until the end of the line and copy to the variable
  148.   FileRead $R8 $varPreviousVersion
  149.   ; If the variable is empty (which will mean the file is not there in this case
  150.   ; go to lbl_noprev. Otherwise go to lbl_prev
  151.   StrCmp $varPreviousVersion "" lbl_noprev lbl_prev
  152.  
  153.   lbl_noprev:
  154.   ; The variable is empty, meaning either the previous install was corrupt or the file wasn't
  155.   ; there, which means they need to do a full install, not just a patch install
  156.   MessageBox MB_OK "No previous version detected. You need to perform a full install"
  157.   ; Close the file (otherwise you'll have some problems during the copying of
  158.   ; files that override the version.txt file
  159.   FileClose $R8
  160.   ; Abort the install
  161.   ABORT
  162.   GoTo lbl_prevdone
  163.  
  164.   lbl_prev:
  165.   ;MessageBox MB_OK "Previous version of app: $varPreviousVersion"
  166.   ; Close the file (otherwise you'll have some problems during the copying of
  167.   ; files that override the version.txt file
  168.   FileClose $R8
  169.   ; If the variable is equal to 1.0.3, which is the version of this installer,
  170.   ; go to next command (the message box), otherwise for to two commands down (or the CreateDirectory)
  171.   StrCmp $varPreviousVersion "1.0.3" "+1" "+2"
  172.   ; Ask confirmation to user that they want to install 1.0.3 even though they
  173.   ; already have it installed. If they click OK, go to lbl_prevdone, if they click
  174.   ; Cancel, go to lbl_ABORT
  175.   MessageBox MB_OKCANCEL|MB_ICONQUESTION "Existing install is the same version as this installer. Do you want to continue?" IDOK lbl_prevdone IDCANCEL
  176. lbl_ABORT
  177.  
  178.           lbl_ABORT:
  179.           ; Abort the install
  180.           ABORT
  181.           GoTo lbl_prevdone
  182.  
  183.   lbl_prevdone:
  184.  
  185.   ; Save the config files into a temp directory
  186.   CreateDirectory "C:\Temp3141592"
  187.   CopyFiles "C:\app\config\config.properties" "C:\Temp3141592\config.properties"
  188.  
  189.   ; Perform the actual install
  190.   SetOutPath $INSTDIR
  191.   File /r "app\*.*"
  192.  
  193.   ; Put the config files back in their places and delete the temp directory
  194.   CopyFiles "C:\Temp3141592\config.properties" "C:\app\config\config.properties"
  195.   RMDir /r "C:\Temp3141592"
  196. SectionEnd
  197. ;======================================================
  198. ;Descriptions
  199.  
  200.   ;Language strings
  201.   LangString DESC_InstallPatch ${LANG_ENGLISH} "This will install a patch to an existing app."
  202.   LangString DESC_InstallFull ${LANG_ENGLISH} "This will install a full app. PLEASE NOTE: This will delete any existing install."
  203.  
  204.   ;Assign language strings to sections
  205.   !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
  206.     !insertmacro MUI_DESCRIPTION_TEXT ${fullInstallSection} $(DESC_InstallFull)
  207.     !insertmacro MUI_DESCRIPTION_TEXT ${installPatchSection} $(DESC_InstallPatch)
  208.   !insertmacro MUI_FUNCTION_DESCRIPTION_END
  209.  
  210. ;======================================================
  211. ; Functions
  212.  
  213. Function .onInit
  214.     !insertmacro MUI_INSTALLOPTIONS_EXTRACT "..\customerConfig.ini"
  215.     !insertmacro MUI_INSTALLOPTIONS_EXTRACT "..\priorApp.ini"
  216.  
  217.     ;==============================================================
  218.     ; Mutually exclusive functions
  219.     Push $0
  220.  
  221.     StrCpy $R9 ${fullInstallSection}
  222.     SectionGetFlags ${fullInstallSection} $0
  223.     IntOp $0 $0 | ${SF_SELECTED}
  224.     SectionSetFlags ${fullInstallSection} $0
  225.  
  226.     SectionGetFlags ${installPatchSection} $0
  227.     IntOp $0 $0 & ${SECTION_OFF}
  228.     SectionSetFlags ${installPatchSection} $0
  229.  
  230.     Pop $0
  231.     ; END
  232.  
  233. FunctionEnd
  234.  
  235. ;==============================================================
  236. ; Mutually exclusive functions
  237. Function .onSelChange
  238.   Push $0
  239.  
  240.   StrCmp $R9 ${fullInstallSection} check_sec1
  241.  
  242.     SectionGetFlags ${fullInstallSection} $0
  243.     IntOp $0 $0 & ${SF_SELECTED}
  244.     IntCmp $0 ${SF_SELECTED} 0 done done
  245.       StrCpy $R9 ${fullInstallSection}
  246.       SectionGetFlags ${installPatchSection} $0
  247.       IntOp $0 $0 & ${SECTION_OFF}
  248.       SectionSetFlags ${installPatchSection} $0
  249.  
  250.     Goto done
  251.  
  252.   check_sec1:
  253.  
  254.     SectionGetFlags ${installPatchSection} $0
  255.     IntOp $0 $0 & ${SF_SELECTED}
  256.     IntCmp $0 ${SF_SELECTED} 0 done done
  257.       StrCpy $R9 ${installPatchSection}
  258.       SectionGetFlags ${fullInstallSection} $0
  259.       IntOp $0 $0 & ${SECTION_OFF}
  260.       SectionSetFlags ${fullInstallSection} $0
  261.  
  262.   done:
  263.  
  264.   Pop $0
  265. FunctionEnd
  266.  
  267. ;==============================================================
  268. ; Custom screen functions
  269. LangString TEXT_IO_TITLE ${LANG_ENGLISH} "Configuration page"
  270. LangString TEXT_IO_SUBTITLE ${LANG_ENGLISH} "This page will update application files based on your system configuration."
  271.  
  272. Function priorapp
  273.    ; read in section flag
  274.    Push $0
  275.    SectionGetFlags ${installPatchSection} $0
  276.    ; skip complete function if not selected. that way this InstallOptions screen doesn't show
  277.    ; if it's not needed (if they do a patch install, we don't need to ask them this question)
  278.    StrCmp $0 ${SF_SELECTED} configdone 0
  279.    !insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)"
  280.    !insertmacro MUI_INSTALLOPTIONS_DISPLAY "..\priorApp.ini"
  281.    !insertmacro MUI_INSTALLOPTIONS_READ $varPriorapp "..\priorApp.ini" "Field 2" "State"
  282.    configdone:
  283.    Pop $0
  284. FunctionEnd
  285.  
  286. Function customerConfig
  287.    ; read in section flag
  288.    Push $0
  289.    SectionGetFlags ${installPatchSection} $0
  290.    ; skip complete function if not selected
  291.    StrCmp $0 ${SF_SELECTED} configdone 0
  292.    !insertmacro MUI_HEADER_TEXT "$(TEXT_IO_TITLE)" "$(TEXT_IO_SUBTITLE)"
  293.    !insertmacro MUI_INSTALLOPTIONS_DISPLAY "..\customerConfig.ini"
  294.    !insertmacro MUI_INSTALLOPTIONS_READ $varCustomerName "..\customerConfig.ini" "Field 1" "State"
  295.    !insertmacro MUI_INSTALLOPTIONS_READ $varCustomerLicense "..\customerConfig.ini" "Field 2" "State"
  296.    configdone:
  297.    Pop $0
  298. FunctionEnd
  299.  
  300. Function AdvReplaceInFile
  301.          Exch $0 ;file to replace in
  302.          Exch
  303.          Exch $1 ;number to replace after
  304.          Exch
  305.          Exch 2
  306.          Exch $2 ;replace and onwards
  307.          Exch 2
  308.          Exch 3
  309.          Exch $3 ;replace with
  310.          Exch 3
  311.          Exch 4
  312.          Exch $4 ;to replace
  313.          Exch 4
  314.          Push $5 ;minus count
  315.          Push $6 ;universal
  316.          Push $7 ;end string
  317.          Push $8 ;left string
  318.          Push $9 ;right string
  319.          Push $R0 ;file1
  320.          Push $R1 ;file2
  321.          Push $R2 ;read
  322.          Push $R3 ;universal
  323.          Push $R4 ;count (onwards)
  324.          Push $R5 ;count (after)
  325.          Push $R6 ;temp file name
  326.          GetTempFileName $R6
  327.          FileOpen $R1 $0 r ;file to search in
  328.          FileOpen $R0 $R6 w ;temp file
  329.                   StrLen $R3 $4
  330.                   StrCpy $R4 -1
  331.                   StrCpy $R5 -1
  332.         loop_read:
  333.          ClearErrors
  334.          FileRead $R1 $R2 ;read line
  335.          IfErrors exit
  336.          StrCpy $5 0
  337.          StrCpy $7 $R2
  338.  
  339.         loop_filter:
  340.          IntOp $5 $5 - 1
  341.          StrCpy $6 $7 $R3 $5 ;search
  342.          StrCmp $6 "" file_write2
  343.          StrCmp $6 $4 0 loop_filter
  344.  
  345.          StrCpy $8 $7 $5 ;left part
  346.          IntOp $6 $5 + $R3
  347.          StrCpy $9 $7 "" $6 ;right part
  348.          StrCpy $7 $8$3$9 ;re-join
  349.  
  350.          IntOp $R4 $R4 + 1
  351.          StrCmp $2 all file_write1
  352.          StrCmp $R4 $2 0 file_write2
  353.          IntOp $R4 $R4 - 1
  354.  
  355.          IntOp $R5 $R5 + 1
  356.          StrCmp $1 all file_write1
  357.          StrCmp $R5 $1 0 file_write1
  358.          IntOp $R5 $R5 - 1
  359.          Goto file_write2
  360.  
  361.         file_write1:
  362.          FileWrite $R0 $7 ;write modified line
  363.          Goto loop_read
  364.  
  365.         file_write2:
  366.          FileWrite $R0 $R2 ;write unmodified line
  367.          Goto loop_read
  368.  
  369.         exit:
  370.          FileClose $R0
  371.          FileClose $R1
  372.  
  373.          SetDetailsPrint none
  374.          Delete $0
  375.          Rename $R6 $0
  376.          Delete $R6
  377.          SetDetailsPrint both
  378.  
  379.          Pop $R6
  380.          Pop $R5
  381.          Pop $R4
  382.          Pop $R3
  383.          Pop $R2
  384.          Pop $R1
  385.          Pop $R0
  386.          Pop $9
  387.          Pop $8
  388.          Pop $7
  389.          Pop $6
  390.          Pop $5
  391.          Pop $4
  392.          Pop $3
  393.          Pop $2
  394.          Pop $1
  395.          Pop $0
  396. FunctionEnd
  397.  

This category contains 2 examples, and has been viewed 34151 times.

  • Simple Starter - A simple NullSoft Installer Script example (7362 views)
  • Full Example - The full example of the simple script (10871 views)