Get vertical space of INI file value: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
No edit summary |
m (Mentioned the unit of measurement "lines".) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|Afrow UK}} | |||
== Description == | == Description == | ||
This function was written for [[User:Angus_Leeming|Angus Leeming]]. It finds out how much vertical space | This function was written for [[User:Angus_Leeming|Angus Leeming]]. It finds out how much vertical space in lines an INI file value takes up. | ||
== Usage == | == Usage == | ||
Line 21: | Line 23: | ||
teh</highlight-nsis> | teh</highlight-nsis> | ||
'''$R0''' is now ''5''. | '''$R0''' is now ''5'' lines. | ||
== Note == | == Note == | ||
File can use TrimNewLines if you <highlight-nsis>!define UseTrimNewLines</highlight-nsis> at the top of the Function. | File can use [[Trim newlines|TrimNewLines]] if you <highlight-nsis>!define UseTrimNewLines</highlight-nsis> at the top of the Function. | ||
Otherwise, it will simply use '''$\r$\n''' as a new line. | Otherwise, it will simply use '''$\r$\n''' as a new line. | ||
Line 106: | Line 108: | ||
-Stu | -Stu | ||
[[Category:INI, CSV & Registry Functions]] |
Latest revision as of 13:27, 30 June 2005
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