LogicLib - ForEachReg

From NSIS Wiki
Jump to navigationJump to search
Author: Zinthose (talk, contrib)


About

Library to extend the LogicLib library to enumerate the registry keys and values. Only limitation is that the stack must be maintained for the enumeration counter.

LogicLib_ForEachReg.nsh

!ifndef ___LogicLib_ForEachReg_NSH___
!define ___LogicLib_ForEachReg_NSH___
 
; -----------------------------
;    LogicLib_ForEachReg.nsh
; -----------------------------
;
; Library to extend the 'LogicLib' library's existing functions.
;
 
!include LogicLib.nsh
 
; -----------------------
;     ForEachRegKey
; -----------------------
;
;   Example:
;       ${ForEachRegKey} $0 HKLM 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'
;           ${ForEachRegValue} $1 HKLM 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\$0'
;               DetailPrint "$0 = $1"
;           ${NextRegValue}
;       ${NextRegKey}
;
 
## LogicLib Registry Library
    !define ForEachRegKey `!insertmacro _ForEachReg Key`
    !define ForEachRegValue `!insertmacro _ForEachReg Value`
    !macro _ForEachReg _n _outKeyName _inRootKey _inSubKey
        !verbose push
        !verbose ${LOGICLIB_VERBOSITY}
        !insertmacro _PushLogic
        !define ${_Logic}ForEachReg${_n} _LogicLib_Label_${LOGICLIB_COUNTER}
        !insertmacro _IncreaseCounter
        !insertmacro _LOGICLIB_TEMP
        Push 0
        ${${_Logic}ForEachReg${_n}}:
        !insertmacro _PushScope ExitForEachReg${_n} _LogicLib_Label_${LOGICLIB_COUNTER}
        !insertmacro _IncreaseCounter
        !insertmacro _PushScope Break ${_ExitForEachReg${_n}}
        Pop $_LOGICLIB_TEMP
        EnumReg${_n} ${_outKeyName} ${_inRootKey} '${_inSubKey}' $_LOGICLIB_TEMP
        StrCmp ${_outKeyName} "" ${_ExitForEachReg${_n}}
        IntOp $_LOGICLIB_TEMP $_LOGICLIB_TEMP + 1
        Push $_LOGICLIB_TEMP
        !insertmacro _PushScope Continue _LogicLib_Label_${LOGICLIB_COUNTER}
        !insertmacro _IncreaseCounter
        !define ${_Logic}Condition
        !verbose pop
    !macroend
 
    !define NextRegKey      `!insertmacro _NextReg Key`
    !define NextRegValue    `!insertmacro _NextReg Value`
    !macro _NextReg _n
        !verbose push
        !verbose ${LOGICLIB_VERBOSITY}
        !ifndef _Logic | ${_Logic}ForEachReg${_n}
            !error "Cannot use NextReg${_n} without a preceding ForEachReg${_n}"
        !endif
        ${_Continue}:
        Goto ${${_Logic}ForEachReg${_n}}
        Goto ${_Continue}
        Goto ${_ExitForEachReg${_n}}
        ${_ExitForEachReg${_n}}:
        !insertmacro _PopScope Continue
        !insertmacro _PopScope Break
        !insertmacro _PopScope ExitForEachReg${_n}
        !undef ${_Logic}ForEachReg${_n}
        !insertmacro _PopLogic
        !verbose pop
    !macroend
!endif