Get vertical space of INI file value
From NSIS Wiki
Jump to navigationJump to search
Author: Afrow UK (talk, contrib) |
Description
This function was written for Angus Leeming. It finds out how much vertical space in lines an INI file value takes up.
Usage
${GetValueVertSpace} $R0 "path\to\file.ini" "section_name" "key_name"
Example
${GetValueVertSpace} $R0 "$INSTDIR\temp.ini" "blah" "meh"
Value of meh is:
ja bah he teh
$R0 is now 5 lines.
Note
File can use TrimNewLines if you
!define UseTrimNewLines
at the top of the Function.
Otherwise, it will simply use $\r$\n as a new line.
The Function
#!define UseTrimNewLines Function GetValueVertSpace Exch $R0 ;key name Exch Exch $R1 ;section Exch 2 Exch $R2 ;ini file Exch 2 Push $R3 Push $R4 FileOpen $R3 $R2 r FindSection: ClearErrors FileRead $R3 $R2 IfErrors DoneRead !ifdef UseTrimNewLines Push $R2 Call TrimnewLines Pop $R2 StrCmp $R2 "[$R1]" 0 FindSection !undef UseTrimNewLines !else StrCmp $R2 "[$R1]$\r$\n" 0 FindSection !endif StrLen $R1 $R0 IntOp $R1 $R1 + 1 FindKey: ClearErrors FileRead $R3 $R2 IfErrors DoneRead StrCpy $R2 $R2 $R1 StrCmp $R2 "$R0=" 0 FindKey StrCpy $R0 1 CountLines: ClearErrors FileRead $R3 $R2 IfErrors DoneRead StrCpy $R1 -1 IntOp $R1 $R1 + 1 StrCpy $R4 $R2 1 $R1 StrCmp $R4 "" 0 +3 IntOp $R0 $R0 + 1 Goto CountLines StrCmp $R4 = 0 -5 DoneRead: FileClose $R3 Pop $R4 Pop $R3 Pop $R2 Pop $R1 Exch $R0 FunctionEnd !macro GetValueVertSpace Var File Section Key Push "${File}" Push "${Section}" Push "${Key}" Call GetValueVertSpace Pop "${Var}" !macroend !define GetValueVertSpace "!insertmacro GetValueVertSpace"
-Stu