SectionsFlags: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
mNo edit summary
(use attach, not a manual link)
 
(5 intermediate revisions by 3 users not shown)
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)
<attach>SectionFlags.zip</attach>


== Description ==
== Description ==
These macros can remember or set section flags. Macros work only on NSIS 2.10 or higher.
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 ==
== Usage ==
<highlight-nsis>
<highlight-nsis>
   !insertmacro SectionWriteReg HKLM "${PRODUCT_UNINST_KEY}" "Sections"
   Section "Required"
    SectionIn RO
    Call Uninstall
  SectionEnd


   Function .onInit
   Insert code (Sections) here...


     !insertmacro SectionReSetFlags HKLM "${PRODUCT_UNINST_KEY}" "Sections"
  Section "-"
     ${SectionWriteReg} HKLM "${PRODUCT_UNINST_KEY}" "Sections"
  SectionEnd


  Function .onInit
    ${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"
     ${Section} ${Section Index}
 
      ${Repair}
        insert code here...
      ${Remove}
        insert code here...
    ${SectionEnd}
   FunctionEnd
   FunctionEnd


Line 36: Line 48:
; Section define/macro header file
; Section define/macro header file
; See this header file for more info
; See this header file for more info
!include ".\SectionFunc.nsh"
;${SectionReadReg}
${SectionResetFlags}
${SectionWriteReg}


!include "SectionFlags.nsh"
!include "SectionFlagsFuncs.nsh"


!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\SectionsFlags_exam"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\SectionsFlags_exam"
Line 50: Line 64:


; Pages
; Pages
Page components
Page components
Page instfiles
Page instfiles
Line 61: Line 74:
   SectionIn RO
   SectionIn RO
   Call Uninstall
   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
SectionEnd


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


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


Section /o "Group 2 - Option 2" g2o2
Section /o "Section 3" sec3
   DetailPrint "Installed Section 5"
   SectionGetText ${sec3} $0
SectionEnd
   DetailPrint "Installed $0"
 
Section /o "Group 2 - Option 3" g2o3
   DetailPrint "Installed Section 6"
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} 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
   ${Section} ${sec1}
     ${Repair}
     ${Repair}
       DetailPrint "Repair Section 2"
       DetailPrint "Repaired Section 1"
     ${Remove}
     ${Remove}
       DetailPrint "Remove Section 2"
       DetailPrint "REMOVED Section 1"
   ${SectionEnd}
   ${SectionEnd}


   ${Section} 1 $R0 $R1
   ${Section} ${sec2}
     ${Repair}
     ${Repair}
       DetailPrint "Repair Section 1"
       DetailPrint "Repaired Section 2"
     ${Remove}
     ${Remove}
       DetailPrint "Remove Section 1"
       DetailPrint "REMOVED Section 2"
   ${SectionEnd}
   ${SectionEnd}


   ${Section} 0 $R0 $R1
   ${Section} ${sec3}
     ${Repair}
     ${Repair}
       DetailPrint "Repair Section 0"
       DetailPrint "Repaired Section 3"
     ${Remove}
     ${Remove}
       DetailPrint "Remove Section 0"
       DetailPrint "REMOVED Section 3"
   ${SectionEnd}
   ${SectionEnd}



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