Skip to content
⌘ NSIS Forum Archive

Nested SectionGroup(s) - problem hiding Groups

5 posts

xbarns#

Nested SectionGroup(s) - problem hiding Groups

Hello all,

i have nested Section Groups as follows

SectionGroup "Features" SEC_GRP_FEATURES
  SectionGroup "Contract Plus" SEC_GRP_FEATURES_CONTRACT_PLUS
      Section /o "Building Contracts" SEC_FEATURE_CONTRACT_PLUS_BUILDING_CONTRACTS
    MessageBox MB_OK "Building" 
    SectionEnd
      Section /o "Vehicle Contracts" SEC_FEATURE_CONTRACT_PLUS_VEHICLE_CONTRACTS         
    MessageBox MB_OK "Vehicle"
    SectionEnd 
  SectionGroupEnd                    
  SectionGroup "Asset Plus"  SEC_GRP_FEATURES_ASSET_PLUS
    Section /o "Depreciation"  SEC_FEATURE_ASSET_PLUS_DEPRECIATION
      MessageBox MB_OK "Depreciation"
    SectionEnd
  SectionGroupEnd
SectionGroupEnd 
Now using a

!define MUI_PAGE_CUSTOMFUNCTION_PRE "SetFeatures"

i try to disable some features depending on a given license key, the code is as follows

Var /Global AmountFeatures
    Var /Global AmountFeaturesAsset
    Var /Global AmountFeaturesContract
    
    StrCpy $AmountFeatures 2 ;Maximum Amount of Groups in Folder Features 
    StrCpy $AmountFeaturesAsset 1 ;Maximum Amount of features contained in Group SEC_GRP_FEATURES_ASSET_PLUS
    StrCpy $AmountFeaturesContract 2 ;Maximum Amount of features contained in Group SEC_GRP_FEATURES_CONTRACT_PLUS
    
    MessageBox MB_OK "AmountFeatures: $AmountFeatures$\r$\nAmountFeaturesAsset: $AmountFeaturesAsset$\r$\nAmountFeaturesContract :$AmountFeaturesContract"
    
    Var /Global Inst_AssetPlus
    Var /Global Inst_ContractPlus
    
    ReadRegStr $Inst_AssetPlus HKLM "${REGKEY}" Inst_AssetPlus 
    ReadRegStr $Inst_ContractPlus HKLM "${REGKEY}" Inst_ContractPlus 
    
    MessageBox MB_OK "Inst_AssetPlus: $Inst_AssetPlus$\r$\nInst_ContractPlus: $Inst_ContractPlus"
         ${If} $Inst_AssetPlus != 1
        MessageBox MB_OK "Remove Feature Asset Plus Depreciation"
        !insertmacro ClearSectionFlag ${SEC_FEATURE_ASSET_PLUS_DEPRECIATION} ${SF_SELECTED}
        SectionSetText ${SEC_FEATURE_ASSET_PLUS_DEPRECIATION} "" 
        IntOp $AmountFeaturesAsset $AmountFeaturesAsset - 1
    ${EndIf}
    
    ${If} $Inst_ContractPlus != 1
        MessageBox MB_OK "Remove Features Contract Plus"
        !insertmacro ClearSectionFlag ${SEC_FEATURE_CONTRACT_PLUS_BUILDING_CONTRACTS} ${SF_SELECTED}
        SectionSetText ${SEC_FEATURE_CONTRACT_PLUS_BUILDING_CONTRACTS} "" 
        !insertmacro ClearSectionFlag ${SEC_FEATURE_CONTRACT_PLUS_VEHICLE_CONTRACTS} ${SF_SELECTED}
        SectionSetText ${SEC_FEATURE_CONTRACT_PLUS_VEHICLE_CONTRACTS} ""        
        IntOp $AmountFeaturesContract $AmountFeaturesContract - 2        
    ${EndIf}
    
    
    ${If} $AmountFeaturesAsset = 0 
        MessageBox MB_OK "Remove Feature Group Asset Plus"
            !insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_ASSET_PLUS} ${SF_SECGRP}
            !insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_ASSET_PLUS} ${SF_SECGRPEND} 
            !insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_ASSET_PLUS} ${SF_SELECTED}
            SectionSetText ${SEC_GRP_FEATURES_ASSET_PLUS} ""        
        IntOp $AmountFeatures $AmountFeatures - 1
    ${EndIf}
    
    ${If} $AmountFeaturesContract = 0 
        MessageBox MB_OK "Remove Feature Group Contract Plus"
            !insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_CONTRACT_PLUS} ${SF_SECGRP}
            !insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_CONTRACT_PLUS} ${SF_SECGRPEND} 
            !insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_CONTRACT_PLUS} ${SF_SELECTED}
            SectionSetText ${SEC_GRP_FEATURES_CONTRACT_PLUS} "" 
        IntOp $AmountFeatures $AmountFeatures - 1
    ${EndIf}
        
    ${If} $AmountFeatures = 0 
        MessageBox MB_OK "Remove Features Group"
        !insertmacro ClearSectionFlag ${SEC_GRP_FEATURES} ${SF_SECGRP}        
        !insertmacro ClearSectionFlag ${SEC_GRP_FEATURES} ${SF_SECGRPEND} 
        !insertmacro ClearSectionFlag ${SEC_GRP_FEATURES} ${SF_SELECTED} 
        SectionSetText ${SEC_GRP_FEATURES} "" 
    ${EndIf} 

Now if both "Features" are enabled it looks like this:



If only the "Contract" Features are enabled it still looks fine.


But if the Contract Features are disabled and the Asset Features are enabled it looks weird like this 🙁



I am using NSIS Unicode 2.42-6.

any help would be much appreciated.

Thanks a lot.
jpderuiter#
Hi,

I can reproduce your problem.
It occures in the ANSI version of NSIS as well.

I think it's a bug in NSIS, because if you swap the two sectiongroups (contract and asset), the contract sectiongroup hides correctly, but the asset sectiongroup doesn't.

I don't know a workaround for this issue as well.
Sorry I can't help you further.
jpderuiter#
Ok, after reading this post:
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.

I figured that the SectionGroupEnd needs the SF_SECGRPEND flag being cleared instead of the SectionGroup.

This is a little tricky, as to get the SectionGroupEnd identifier, you need to add 1 to the section identifier of the previous section.

You also need to make the SectionGroupEnd name "" as well (don't ask me why, but that works).

So you can leave the SF_SECGRPEND clearing of the Sectiongroup, and add the following lines after SectionSetText ${SEC_GRP_XXX_XXX} "":
IntOp $0 ${SEC_FEATURE_XXX_XXX} + 1 ; previous section
!insertmacro ClearSectionFlag $0 ${SF_SECGRPEND}
SectionSetText $0 ""
To make it clearer here is the complete working code:
Var /Global AmountFeatures 
Var /Global AmountFeaturesAsset
Var /Global AmountFeaturesContract

StrCpy $AmountFeatures 2 ;Maximum Amount of Groups in Folder Features
StrCpy $AmountFeaturesAsset 1 ;Maximum Amount of features contained in Group SEC_GRP_FEATURES_ASSET_PLUS
StrCpy $AmountFeaturesContract 2 ;Maximum Amount of features contained in Group SEC_GRP_FEATURES_CONTRACT_PLUS

MessageBox MB_OK "AmountFeatures: $AmountFeatures$\r$\nAmountFeaturesAsset: $AmountFeaturesAsset$\r$\nAmountFeaturesContract :$AmountFeaturesContract"

Var /Global Inst_AssetPlus
Var /Global Inst_ContractPlus

ReadRegStr $Inst_AssetPlus HKLM "${REGKEY}" Inst_AssetPlus
ReadRegStr $Inst_ContractPlus HKLM "${REGKEY}" Inst_ContractPlus

MessageBox MB_OK "Inst_AssetPlus: $Inst_AssetPlus$\r$\nInst_ContractPlus: $Inst_ContractPlus"
${If} $Inst_AssetPlus != 1
MessageBox MB_OK "Remove Feature Asset Plus Depreciation"
!insertmacro ClearSectionFlag ${SEC_FEATURE_ASSET_PLUS_DEPRECIATION} ${SF_SELECTED}
SectionSetText ${SEC_FEATURE_ASSET_PLUS_DEPRECIATION} ""
IntOp $AmountFeaturesAsset $AmountFeaturesAsset - 1
${EndIf}

${If} $Inst_ContractPlus != 1
MessageBox MB_OK "Remove Features Contract Plus"
!insertmacro ClearSectionFlag ${SEC_FEATURE_CONTRACT_PLUS_BUILDING_CONTRACTS} ${SF_SELECTED}
SectionSetText ${SEC_FEATURE_CONTRACT_PLUS_BUILDING_CONTRACTS} ""
!insertmacro ClearSectionFlag ${SEC_FEATURE_CONTRACT_PLUS_VEHICLE_CONTRACTS} ${SF_SELECTED}
SectionSetText ${SEC_FEATURE_CONTRACT_PLUS_VEHICLE_CONTRACTS} ""
IntOp $AmountFeaturesContract $AmountFeaturesContract - 2
${EndIf}

${If} $AmountFeaturesAsset = 0
MessageBox MB_OK "Remove Feature Group Asset Plus"
!insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_ASSET_PLUS} ${SF_SECGRP}
;!insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_ASSET_PLUS} ${SF_SECGRPEND}
!insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_ASSET_PLUS} ${SF_SELECTED}
SectionSetFlags ${SEC_GRP_FEATURES_ASSET_PLUS} 0
SectionSetText ${SEC_GRP_FEATURES_ASSET_PLUS} ""
IntOp $0 ${SEC_FEATURE_ASSET_PLUS_DEPRECIATION} + 1 ; Add 1 to get the SEC_GRP_FEATURES_ASSET_PLUS SectionGroupEnd identifier
!insertmacro ClearSectionFlag $0 ${SF_SECGRPEND}
SectionSetText $0 ""
IntOp $AmountFeatures $AmountFeatures - 1
${EndIf}

${If} $AmountFeaturesContract = 0
MessageBox MB_OK "Remove Feature Group Contract Plus"
!insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_CONTRACT_PLUS} ${SF_SECGRP}
;!insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_CONTRACT_PLUS} ${SF_SECGRPEND}
!insertmacro ClearSectionFlag ${SEC_GRP_FEATURES_CONTRACT_PLUS} ${SF_SELECTED}
SectionSetFlags ${SEC_GRP_FEATURES_CONTRACT_PLUS} 0
SectionSetText ${SEC_GRP_FEATURES_CONTRACT_PLUS} ""
IntOp $0 ${SEC_FEATURE_CONTRACT_PLUS_VEHICLE_CONTRACTS} + 1 ; Add 1 to get the SEC_GRP_FEATURES_CONTRACT_PLUS SectionGroupEnd identifier
!insertmacro ClearSectionFlag $0 ${SF_SECGRPEND}
SectionSetText $0 ""
IntOp $AmountFeatures $AmountFeatures - 1
${EndIf}

${If} $AmountFeatures = 0
MessageBox MB_OK "Remove Features Group"
!insertmacro ClearSectionFlag ${SEC_GRP_FEATURES} ${SF_SECGRP}
;!insertmacro ClearSectionFlag ${SEC_GRP_FEATURES} ${SF_SECGRPEND}
!insertmacro ClearSectionFlag ${SEC_GRP_FEATURES} ${SF_SELECTED}
SectionSetFlags ${SEC_GRP_FEATURES} 0
SectionSetText ${SEC_GRP_FEATURES} ""
IntOp $0 ${SEC_FEATURE_ASSET_PLUS_DEPRECIATION} + 2 ; Add 2 to get the SEC_GRP_FEATURES SectionGroupEnd identifier
!insertmacro ClearSectionFlag $0 ${SF_SECGRPEND}
SectionSetText $0 ""
${EndIf}