SectionsFlags: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 2: Line 2:


== Download Link ==
== Download Link ==
[[File:Zip.gif]] [http://forums.winamp.com/attachment.php?s=c7b247e1b5b6706e63dda436ca6032ca&postid=1786717 sectionflags.zip] (4 KB)
[[File:Zip.gif]] [http://forums.winamp.com/attachment.php?s=9a45f721526b0833445d8df1ef580a27&postid=1845800] (4 KB)


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


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


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


Line 36: Line 34:
; Section define/macro header file
; Section define/macro header file
; See this header file for more info
; See this header file for more info
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\SectionsFlags_exam"


!include "SectionFlags.nsh"
!define DEBUG
!include "SectionFlagsFuncs.nsh"
 
!include "SectionFunc.nsh"
;${SectionReadReg}
${SectionResetFlags}
${SectionWriteReg}


!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\SectionsFlags_exam"
;--------------------------------
;--------------------------------


Line 61: Line 63:
   SectionIn RO
   SectionIn RO
   Call Uninstall
   Call Uninstall
  DetailPrint "Installed Section 0"
SectionEnd
SectionEnd


Section "Group 1 - Option 1" g1o1
Section "Group 1 - Option 1" g1o1
   DetailPrint "Installed Section 1"
  SectionGetText ${g1o1} $0
   DetailPrint "Installed Section $0"
SectionEnd
SectionEnd


Section /o "Group 1 - Option 2" g1o2
Section /o "Group 1 - Option 2" g1o2
   DetailPrint "Installed Section 2"
  SectionGetText ${g1o2} $0
   DetailPrint "Installed Section $0"
SectionEnd
SectionEnd


Section /o "Group 1 - Option 3" g1o3
Section /o "Group 1 - Option 3" g1o3
   DetailPrint "Installed Section 3"
  SectionGetText ${g1o3} $0
   DetailPrint "Installed Section $0"
SectionEnd
SectionEnd


Section "Group 2 - Option 1" g2o1
Section "Group 2 - Option 1" g2o1
   DetailPrint "Installed Section 4"
  SectionGetText ${g2o1} $0
   DetailPrint "Installed Section $0"
SectionEnd
SectionEnd


Section /o "Group 2 - Option 2" g2o2
Section /o "Group 2 - Option 2" g2o2
   DetailPrint "Installed Section 5"
  SectionGetText ${g2o2} $0
   DetailPrint "Installed Section $0"
SectionEnd
SectionEnd


Section /o "Group 2 - Option 3" g2o3
Section /o "Group 2 - Option 3" g2o3
   DetailPrint "Installed Section 6"
  SectionGetText ${g2o3} $0
   DetailPrint "Installed Section $0"
SectionEnd
SectionEnd


Section "-"
Section "-"
DetailPrint "Installed Section 7"
  ${SectionWriteReg} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
!insertmacro SectionWriteReg HKLM "${PRODUCT_UNINST_KEY}" "Sections"
SectionEnd
SectionEnd


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


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


   ; $R0 stores the sections old flags
   ${SectionGetValues} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
  ; $R1 stores the sections new flags
    
   ; $0 - $3 used by macro
   ${Section} ${g2o3}
 
   ${Section} 6 $R0 $R1
     ${Repair}
     ${Repair}
       DetailPrint "Repair Section 6"
       DetailPrint "Repaired Group 2 - Option 3"
     ${Remove}
     ${Remove}
       DetailPrint "Remove Section 6"
       DetailPrint "Removed Group 2 - Option 3"
   ${SectionEnd}
   ${SectionEnd}
    
    
   ${Section} 5 $R0 $R1
   ${Section} ${g2o2}
    ${Repair}
      DetailPrint "Repair Section 5"
    ${Remove}
      DetailPrint "Remove Section 5"
  ${SectionEnd}
 
  ${Section} 4 $R0 $R1
     ${Repair}
     ${Repair}
       DetailPrint "Repair Section 4"
       DetailPrint "Repaired Group 2 - Option 2"
     ${Remove}
     ${Remove}
       DetailPrint "Remove Section 4"
       DetailPrint "Removed Group 2 - Option 2"
   ${SectionEnd}
   ${SectionEnd}


   ${Section} 3 $R0 $R1
   ${Section} ${g2o1}
     ${Repair}
     ${Repair}
       DetailPrint "Repair Section 3"
       DetailPrint "Repaired Group 2 - Option 1"
     ${Remove}
     ${Remove}
       DetailPrint "Remove Section 3"
       DetailPrint "Removed Group 2 - Option 1"
   ${SectionEnd}
   ${SectionEnd}


   ${Section} 2 $R0 $R1
   ${Section} ${g1o3}
     ${Repair}
     ${Repair}
       DetailPrint "Repair Section 2"
       DetailPrint "Repaired Group 1 - Option 3"
     ${Remove}
     ${Remove}
       DetailPrint "Remove Section 2"
       DetailPrint "Removed Group 1 - Option 3"
   ${SectionEnd}
   ${SectionEnd}


   ${Section} 1 $R0 $R1
   ${Section} ${g1o2}
     ${Repair}
     ${Repair}
       DetailPrint "Repair Section 1"
       DetailPrint "Repaired Group 1 - Option 2"
     ${Remove}
     ${Remove}
       DetailPrint "Remove Section 1"
       DetailPrint "Removed Group 1 - Option 2"
   ${SectionEnd}
   ${SectionEnd}


   ${Section} 0 $R0 $R1
   ${Section} ${g1o1}
     ${Repair}
     ${Repair}
       DetailPrint "Repair Section 0"
       DetailPrint "Repaired Group 1 - Option 1"
     ${Remove}
     ${Remove}
       DetailPrint "Remove Section 0"
       DetailPrint "Removed Group 1 - Option 1"
   ${SectionEnd}
   ${SectionEnd}



Revision as of 22:31, 16 January 2006

Author: Tu Tong (talk, contrib)


Download Link

Zip.gif [1] (4 KB)

Description

These macros can remember or set section flags.

Usage

  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"
  FunctionEnd

Example

; SectionsFlags.nsi
;
; This example demonstrates how to control section flags.
 
;--------------------------------
 
; Section define/macro header file
; See this header file for more info
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\SectionsFlags_exam"
 
!define DEBUG
 
!include "SectionFunc.nsh"
;${SectionReadReg}
${SectionResetFlags}
${SectionWriteReg}
 
;--------------------------------
 
Name "SectionsFlags Example"
OutFile "SectionsFlags_exam.exe"
 
ShowInstDetails show
;--------------------------------
 
; Pages
 
Page components
Page instfiles
 
;--------------------------------
 
; Sections
 
Section !Required
  SectionIn RO
  Call Uninstall
SectionEnd
 
Section "Group 1 - Option 1" g1o1
  SectionGetText ${g1o1} $0
  DetailPrint "Installed Section $0"
SectionEnd
 
Section /o "Group 1 - Option 2" g1o2
  SectionGetText ${g1o2} $0
  DetailPrint "Installed Section $0"
SectionEnd
 
Section /o "Group 1 - Option 3" g1o3
  SectionGetText ${g1o3} $0
  DetailPrint "Installed Section $0"
SectionEnd
 
Section "Group 2 - Option 1" g2o1
  SectionGetText ${g2o1} $0
  DetailPrint "Installed Section $0"
SectionEnd
 
Section /o "Group 2 - Option 2" g2o2
  SectionGetText ${g2o2} $0
  DetailPrint "Installed Section $0"
SectionEnd
 
Section /o "Group 2 - Option 3" g2o3
  SectionGetText ${g2o3} $0
  DetailPrint "Installed Section $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} ${g2o3}
    ${Repair}
      DetailPrint "Repaired Group 2 - Option 3"
    ${Remove}
      DetailPrint "Removed Group 2 - Option 3"
  ${SectionEnd}
 
  ${Section} ${g2o2}
    ${Repair}
      DetailPrint "Repaired Group 2 - Option 2"
    ${Remove}
      DetailPrint "Removed Group 2 - Option 2"
  ${SectionEnd}
 
  ${Section} ${g2o1}
    ${Repair}
      DetailPrint "Repaired Group 2 - Option 1"
    ${Remove}
      DetailPrint "Removed Group 2 - Option 1"
  ${SectionEnd}
 
  ${Section} ${g1o3}
    ${Repair}
      DetailPrint "Repaired Group 1 - Option 3"
    ${Remove}
      DetailPrint "Removed Group 1 - Option 3"
  ${SectionEnd}
 
  ${Section} ${g1o2}
    ${Repair}
      DetailPrint "Repaired Group 1 - Option 2"
    ${Remove}
      DetailPrint "Removed Group 1 - Option 2"
  ${SectionEnd}
 
  ${Section} ${g1o1}
    ${Repair}
      DetailPrint "Repaired Group 1 - Option 1"
    ${Remove}
      DetailPrint "Removed Group 1 - Option 1"
  ${SectionEnd}
 
  DetailPrint "*******************************"
FunctionEnd