Get all section names of INI file: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
No edit summary
Line 17: Line 17:
   
   
"File"    ; name of the initialization file
"File"    ; name of the initialization file
"Function" ; Callback function then found
"Function" ; Callback function
   
   
Function "Function"
Function "Function"

Revision as of 20:01, 4 July 2005

Author: nechai (talk, contrib)


Links

If a function is used without header, put the function code in your script before calling it.

The Function Description

Based on the method to loop over a buffer of null-terminated strings in function "GetDrives"
 
Loop over all available sections in an INI file.
 
Syntax:
${GetSectionNames} "File" "Function"
 
"File"     ; name of the initialization file
"Function" ; Callback function
 
Function "Function"
         ; $9    "section name"
         ; $R0-$R9  are not used (save data in them).
 
         ; ...
 
         Push $var    ; If $var="StopGetSectionNames" Then exit from function
FunctionEnd

Example1:

Section
	${GetSectionNames} "c:\test.ini" "Example1"
SectionEnd
 
Function Example1
	MessageBox MB_OK "$9"
 
	Push $0
FunctionEnd

Example2:

Section
	${GetSectionNames} "c:\test.ini" "Example2"
SectionEnd
 
Function Example2
	StrCmp $9 $R0 0 +3
	StrCpy $R1 $9
	StrCpy $0 StopGetSectionNames
 
	Push $0
FunctionEnd

The Function Code

	!define GetSectionNames `!insertmacro GetSectionNamesCall`
 
	!macro GetSectionNamesCall _FILE _FUNC
		Push $0
		Push `${_FILE}`
		GetFunctionAddress $0 `${_FUNC}`
		Push `$0`
		Call GetSectionNames
		Pop $0
	!macroend
 
	Exch $1
	Exch
	Exch $0
	Exch
	Push $2
	Push $3
	Push $4
	Push $5
	Push $8
	Push $9
 
	System::Alloc 1024
	Pop $2
        StrCpy $3 $2
 
        System::Call "kernel32::GetPrivateProfileSectionNamesA(i, i, t) i(r3, 1024, r0) .r4"
 
	enumok:
        System::Call 'kernel32::lstrlenA(t) i(i r3) .r5'
	StrCmp $5 '0' enumex
 
	System::Call '*$3(&t1024 .r9)'
 
	Push $0
	Push $1
	Push $2
	Push $3
	Push $4
	Push $5
	Push $8
	Call $1
	Pop $9
	Pop $8
	Pop $5
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Pop $0
        StrCmp $9 'StopGetSectionNames' enumex
 
	enumnext:
	IntOp $3 $3 + $5
	IntOp $3 $3 + 1
	goto enumok
 
	enumex:
	System::Free $2
 
	Pop $9
	Pop $8
	Pop $5
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Pop $0
FunctionEnd