SectionsFlags: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
No edit summary
Line 1: Line 1:
{{PageAuthor|Datenbert}}
{{PageAuthor|Tu Tong}}


== Description ==
== Description ==
Line 7: Line 7:
== Usage ==
== Usage ==
<highlight-nsis>
<highlight-nsis>
   !insertmacro SectionReSetFlags HKLM "${PRODUCT_UNINST_KEY}" "Sections"
   !insertmacro SectionWriteReg HKLM "${PRODUCT_UNINST_KEY}" "Sections"


   Function .onInit
   Function .onInit
Line 13: Line 13:
     !insertmacro SectionReSetFlags HKLM "${PRODUCT_UNINST_KEY}" "Sections"
     !insertmacro SectionReSetFlags HKLM "${PRODUCT_UNINST_KEY}" "Sections"


  FunctionEnd
  Function Uninstall
    !insertmacro SectionReadReg HKLM "${PRODUCT_UNINST_KEY}" "Sections"
   FunctionEnd
   FunctionEnd


</highlight-nsis>
</highlight-nsis>


== The Script ==
== Example ==
Please find an example below the following code.
 
<highlight-nsis>
<highlight-nsis>
; The defines for more than 8 installation types are included in
; SectionsFlags.nsi
; Sections.nsh
;
; This example demonstrates how to control section flags.
 
;--------------------------------
 
; Section define/macro header file
; See this header file for more info
 
!include "SectionFlags.nsh"
!include "SectionFlagsFuncs.nsh"
 
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\SectionsFlags_exam"
;--------------------------------
 
Name "SectionsFlags Example"
OutFile "SectionsFlags_exam.exe"
 
ShowInstDetails show
;--------------------------------
 
; Pages
 
Page components
Page instfiles
 
;--------------------------------
 
; Sections
 
Section !Required
  SectionIn RO
  Call Uninstall
  DetailPrint "Installed Section 0"
SectionEnd
 
Section "Group 1 - Option 1" g1o1
  DetailPrint "Installed Section 1"
SectionEnd
 
Section /o "Group 1 - Option 2" g1o2
  DetailPrint "Installed Section 2"
SectionEnd
 
Section /o "Group 1 - Option 3" g1o3
  DetailPrint "Installed Section 3"
SectionEnd
 
Section "Group 2 - Option 1" g2o1
  DetailPrint "Installed Section 4"
SectionEnd
 
Section /o "Group 2 - Option 2" g2o2
  DetailPrint "Installed Section 5"
SectionEnd
 
Section /o "Group 2 - Option 3" g2o3
  DetailPrint "Installed Section 6"
SectionEnd
 
Section "-"
DetailPrint "Installed Section 7"
!insertmacro SectionWriteReg HKLM "${PRODUCT_UNINST_KEY}" "Sections"
SectionEnd
 
 
Function .onInit


!define INSTTYPE_1 1
  !insertmacro SectionReSetFlags HKLM "${PRODUCT_UNINST_KEY}" "Sections"
!define INSTTYPE_2 2
!define INSTTYPE_3 4
!define INSTTYPE_4 8
!define INSTTYPE_5 16
!define INSTTYPE_6 32
!define INSTTYPE_7 64
!define INSTTYPE_8 128


!macro SetSectionInInstType SECTION_NAME WANTED_INSTTYPE
FunctionEnd
Push $0
SectionGetInstTypes "${SECTION_NAME}" $0
IntOp $0 $0 | ${WANTED_INSTTYPE}
SectionSetInstTypes "${SECTION_NAME}" $0
Pop $0
!macroend


!macro ClearSectionInInstType SECTION_NAME WANTED_INSTTYPE
Push $0
Push $1
SectionGetInstTypes "${SECTION_NAME}" $0
StrCpy $1 ${WANTED_INSTTYPE}
IntOp $1 $1 ~
IntOp $0 $0 & $1
SectionSetInstTypes "${SECTION_NAME}" $0
Pop $1
Pop $0
!macroend
</highlight-nsis>


== Example ==
Function Uninstall
Assume we have created four InstTypes:
  !insertmacro SectionReadReg $R0 $R1 HKLM "${PRODUCT_UNINST_KEY}" "Sections"
 
  ; $R0 stores the sections old flags
  ; $R1 stores the sections new flags


<highlight-nsis>
   ${Section} 6 $R0 $R1
   !ifndef NOINSTTYPES # allow user to switch the usage of InstTypes
     ${Repair}
     InstType "Full"                   # This is INSTTYPE_1
      DetailPrint "Repair Section 6"
     InstType "Typical"               # INSTTYPE_2
     ${Remove}
     InstType "Needed on this system" # INSTTYPE_3
      DetailPrint "Remove Section 6"
     InstType "None"                   # guess what? INSTTYPE_4!
  ${SectionEnd}
   !endif
 
</highlight-nsis>
  ${Section} 5 $R0 $R1
Furtheron we have three Sections "webserver", "database" and "source" - see a sample Definition for the first one:
     ${Repair}
      DetailPrint "Repair Section 5"
     ${Remove}
      DetailPrint "Remove Section 5"
   ${SectionEnd}


<highlight-nsis>
   ${Section} 4 $R0 $R1
   Section "Super Webserver" webserver
    ${Repair}
     [...codecodecode...]
      DetailPrint "Repair Section 4"
   SectionEnd
     ${Remove}
</highlight-nsis>
      DetailPrint "Remove Section 4"
The other sections are defined similar. This way, each section can be adressed by using ${section_name}.
   ${SectionEnd}


To set section "webserver" in InstType "Needed on this system", you'd only have to insert this line anywhere you need it in your code:
  ${Section} 3 $R0 $R1
<highlight-nsis>
    ${Repair}
  !insertmacro SetSectionInInstType  "${webserver}" "${INSTTYPE_3}"
      DetailPrint "Repair Section 3"
</highlight-nsis>
    ${Remove}
      DetailPrint "Remove Section 3"
  ${SectionEnd}


To clear for example section "source" from InstType "Typical", you'd use this:
  ${Section} 2 $R0 $R1
<highlight-nsis>
    ${Repair}
  !insertmacro ClearSectionInInstType  "${source}" "${INSTTYPE_2}"
      DetailPrint "Repair Section 2"
</highlight-nsis>
    ${Remove}
      DetailPrint "Remove Section 2"
  ${SectionEnd}


== Contact ==
  ${Section} 1 $R0 $R1
You may contact me via my homepage http://robertkehl.de/ if you feel you should.
    ${Repair}
      DetailPrint "Repair Section 1"
    ${Remove}
      DetailPrint "Remove Section 1"
  ${SectionEnd}


Have fun using your NSIS,
  ${Section} 0 $R0 $R1
    ${Repair}
      DetailPrint "Repair Section 0"
    ${Remove}
      DetailPrint "Remove Section 0"
  ${SectionEnd}


Robert Kehl
  DetailPrint "*******************************"
FunctionEnd
</highlight-nsis>


[[Category:Section Management Functions]]
[[Category:Section Management Functions]]

Revision as of 17:03, 18 October 2005

Author: Tu Tong (talk, contrib)


Description

These macros use to remember and restate Section Flags Macro works only on NSIS 2.10

Usage

  !insertmacro SectionWriteReg HKLM "${PRODUCT_UNINST_KEY}" "Sections"
 
  Function .onInit
 
    !insertmacro SectionReSetFlags HKLM "${PRODUCT_UNINST_KEY}" "Sections"
 
  FunctionEnd
 
  Function Uninstall
    !insertmacro SectionReadReg HKLM "${PRODUCT_UNINST_KEY}" "Sections"
  FunctionEnd

Example

; SectionsFlags.nsi
;
; This example demonstrates how to control section flags.
 
;--------------------------------
 
; Section define/macro header file
; See this header file for more info
 
!include "SectionFlags.nsh"
!include "SectionFlagsFuncs.nsh"
 
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\SectionsFlags_exam"
;--------------------------------
 
Name "SectionsFlags Example"
OutFile "SectionsFlags_exam.exe"
 
ShowInstDetails show
;--------------------------------
 
; Pages
 
Page components
Page instfiles
 
;--------------------------------
 
; Sections
 
Section !Required
  SectionIn RO
  Call Uninstall
  DetailPrint "Installed Section 0"
SectionEnd
 
Section "Group 1 - Option 1" g1o1
  DetailPrint "Installed Section 1"
SectionEnd
 
Section /o "Group 1 - Option 2" g1o2
  DetailPrint "Installed Section 2"
SectionEnd
 
Section /o "Group 1 - Option 3" g1o3
  DetailPrint "Installed Section 3"
SectionEnd
 
Section "Group 2 - Option 1" g2o1
  DetailPrint "Installed Section 4"
SectionEnd
 
Section /o "Group 2 - Option 2" g2o2
  DetailPrint "Installed Section 5"
SectionEnd
 
Section /o "Group 2 - Option 3" g2o3
  DetailPrint "Installed Section 6"
SectionEnd
 
Section "-"
 DetailPrint "Installed Section 7"
 !insertmacro SectionWriteReg HKLM "${PRODUCT_UNINST_KEY}" "Sections"
SectionEnd
 
 
Function .onInit
 
  !insertmacro SectionReSetFlags HKLM "${PRODUCT_UNINST_KEY}" "Sections"
 
FunctionEnd
 
 
Function Uninstall
  !insertmacro SectionReadReg $R0 $R1 HKLM "${PRODUCT_UNINST_KEY}" "Sections"
 
  ; $R0 stores the sections old flags
  ; $R1 stores the sections new flags
 
  ${Section} 6 $R0 $R1
    ${Repair}
      DetailPrint "Repair Section 6"
    ${Remove}
      DetailPrint "Remove Section 6"
  ${SectionEnd}
 
  ${Section} 5 $R0 $R1
    ${Repair}
      DetailPrint "Repair Section 5"
    ${Remove}
      DetailPrint "Remove Section 5"
  ${SectionEnd}
 
  ${Section} 4 $R0 $R1
    ${Repair}
      DetailPrint "Repair Section 4"
    ${Remove}
      DetailPrint "Remove Section 4"
  ${SectionEnd}
 
  ${Section} 3 $R0 $R1
    ${Repair}
      DetailPrint "Repair Section 3"
    ${Remove}
      DetailPrint "Remove Section 3"
  ${SectionEnd}
 
  ${Section} 2 $R0 $R1
    ${Repair}
      DetailPrint "Repair Section 2"
    ${Remove}
      DetailPrint "Remove Section 2"
  ${SectionEnd}
 
  ${Section} 1 $R0 $R1
    ${Repair}
      DetailPrint "Repair Section 1"
    ${Remove}
      DetailPrint "Remove Section 1"
  ${SectionEnd}
 
  ${Section} 0 $R0 $R1
    ${Repair}
      DetailPrint "Repair Section 0"
    ${Remove}
      DetailPrint "Remove Section 0"
  ${SectionEnd}
 
  DetailPrint "*******************************"
FunctionEnd