SectionsFlags: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
(use attach, not a manual link)
 
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{PageAuthor|Datenbert}}
{{PageAuthor|Tu Tong}}
 
== Download Link ==
<attach>SectionFlags.zip</attach>


== Description ==
== Description ==
These macros use to remember and restate Section Flags
These macros can remember or set section flags. This example show you how to get section flags and remember in windows registry after first install, installer will reset all the flags on next time to run installer. Funtion Uninstall  is called before install files sections...
Macro works only on NSIS 2.10


== Usage ==
== Usage ==
<highlight-nsis>
<highlight-nsis>
   !insertmacro SectionReSetFlags HKLM "${PRODUCT_UNINST_KEY}" "Sections"
   Section "Required"
    SectionIn RO
    Call Uninstall
  SectionEnd
 
  Insert code (Sections) here...
 
  Section "-"
    ${SectionWriteReg} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
  SectionEnd


   Function .onInit
   Function .onInit
    ${SectionResetFlags} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
  FunctionEnd


     !insertmacro SectionReSetFlags HKLM "${PRODUCT_UNINST_KEY}" "Sections"
  Function Uninstall
     ${SectionGetValues} HKLM "${PRODUCT_UNINST_KEY}" "Sections"


    ${Section} ${Section Index}
      ${Repair}
        insert code here...
      ${Remove}
        insert code here...
    ${SectionEnd}
   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 ".\SectionFunc.nsh"
;${SectionReadReg}
${SectionResetFlags}
${SectionWriteReg}
 
 
!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
SectionEnd


!define INSTTYPE_1 1
Section "Section 1" sec1
!define INSTTYPE_2 2
  SectionGetText ${sec1} $0
!define INSTTYPE_3 4
  DetailPrint "Installed $0"
!define INSTTYPE_4 8
SectionEnd
!define INSTTYPE_5 16
!define INSTTYPE_6 32
!define INSTTYPE_7 64
!define INSTTYPE_8 128


!macro SetSectionInInstType SECTION_NAME WANTED_INSTTYPE
Section /o "Section 2" sec2
Push $0
  SectionGetText ${sec2} $0
SectionGetInstTypes "${SECTION_NAME}" $0
  DetailPrint "Installed $0"
IntOp $0 $0 | ${WANTED_INSTTYPE}
SectionEnd
SectionSetInstTypes "${SECTION_NAME}" $0
Pop $0
!macroend


!macro ClearSectionInInstType SECTION_NAME WANTED_INSTTYPE
Section /o "Section 3" sec3
Push $0
  SectionGetText ${sec3} $0
Push $1
  DetailPrint "Installed $0"
SectionGetInstTypes "${SECTION_NAME}" $0
SectionEnd
StrCpy $1 ${WANTED_INSTTYPE}
IntOp $1 $1 ~
IntOp $0 $0 & $1
SectionSetInstTypes "${SECTION_NAME}" $0
Pop $1
Pop $0
!macroend
</highlight-nsis>


== Example ==
Section "-"
Assume we have created four InstTypes:
  ${SectionWriteReg} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
SectionEnd


<highlight-nsis>
Function .onInit
  !ifndef NOINSTTYPES # allow user to switch the usage of InstTypes
${SectionResetFlags} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
    InstType "Full"                   # This is INSTTYPE_1
FunctionEnd
    InstType "Typical"                # INSTTYPE_2
    InstType "Needed on this system"  # INSTTYPE_3
    InstType "None"                   # guess what? INSTTYPE_4!
  !endif
</highlight-nsis>
Furtheron we have three Sections "webserver", "database" and "source" - see a sample Definition for the first one:


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


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:
   ${SectionGetValues} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
<highlight-nsis>
   !insertmacro SetSectionInInstType  "${webserver}" "${INSTTYPE_3}"
</highlight-nsis>


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


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


Have fun using your NSIS,
  ${Section} ${sec3}
    ${Repair}
      DetailPrint "Repaired Section 3"
    ${Remove}
      DetailPrint "REMOVED Section 3"
  ${SectionEnd}


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


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

Latest revision as of 18:17, 19 January 2006

Author: Tu Tong (talk, contrib)


Download Link

SectionFlags.zip (3 KB)

Description

These macros can remember or set section flags. This example show you how to get section flags and remember in windows registry after first install, installer will reset all the flags on next time to run installer. Funtion Uninstall is called before install files sections...

Usage

  Section "Required"
    SectionIn RO
    Call Uninstall
  SectionEnd
 
  Insert code (Sections) here...
 
  Section "-"
    ${SectionWriteReg} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
  SectionEnd
 
  Function .onInit
    ${SectionResetFlags} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
  FunctionEnd
 
  Function Uninstall
    ${SectionGetValues} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
 
    ${Section} ${Section Index}
      ${Repair}
        insert code here...
      ${Remove}
        insert code here...
    ${SectionEnd}
  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 ".\SectionFunc.nsh"
;${SectionReadReg}
${SectionResetFlags}
${SectionWriteReg}
 
 
!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
SectionEnd
 
Section "Section 1" sec1
  SectionGetText ${sec1} $0
  DetailPrint "Installed $0"
SectionEnd
 
Section /o "Section 2" sec2
  SectionGetText ${sec2} $0
  DetailPrint "Installed $0"
SectionEnd
 
Section /o "Section 3" sec3
  SectionGetText ${sec3} $0
  DetailPrint "Installed $0"
SectionEnd
 
Section "-"
  ${SectionWriteReg} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
SectionEnd
 
Function .onInit
 ${SectionResetFlags} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
FunctionEnd
 
Function Uninstall
 
  ${SectionGetValues} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
 
  ${Section} ${sec1}
    ${Repair}
      DetailPrint "Repaired Section 1"
    ${Remove}
      DetailPrint "REMOVED Section 1"
  ${SectionEnd}
 
  ${Section} ${sec2}
    ${Repair}
      DetailPrint "Repaired Section 2"
    ${Remove}
      DetailPrint "REMOVED Section 2"
  ${SectionEnd}
 
  ${Section} ${sec3}
    ${Repair}
      DetailPrint "Repaired Section 3"
    ${Remove}
      DetailPrint "REMOVED Section 3"
  ${SectionEnd}
 
  DetailPrint "*******************************"
FunctionEnd