ConfigRead: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Adding new author and category links.)
No edit summary
Line 2: Line 2:


== Links ==
== Links ==
; Latest version of headers "nsh.zip":
; Latest version of headers "nsh.zip":
: http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost
: http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost


== The Function ==
If a function is used without header, put the function code in your script before calling it.
<highlight-nsis>/*
 
== The Function Description==
 
<highlight-nsis>
____________________________________________________________________________
____________________________________________________________________________


Line 28: Line 32:
Note:
Note:
-Error flag if file isn't exist
-Error flag if file isn't exist
</highlight-nsis>






Example1:
<b>Example1:</b>
Section
<highlight-nsis>Section
${ConfigRead} "C:\AUTOEXEC.BAT" "SET winbootdir=" $R0
${ConfigRead} "C:\AUTOEXEC.BAT" "SET winbootdir=" $R0
;$R0=C:\WINDOWS
;$R0=C:\WINDOWS
SectionEnd
SectionEnd
</highlight-nsis>


Example2:
<b>Example2:</b>
Section
<highlight-nsis>Section
${ConfigRead} "C:\apache\conf\httpd.conf" "Timeout " $R0
${ConfigRead} "C:\apache\conf\httpd.conf" "Timeout " $R0
;$R0=30
;$R0=30
SectionEnd*/
SectionEnd
 
</highlight-nsis>


;---------------------------------------------------------------------------
== The Function Code==


<highlight-nsis>
Function ConfigRead
Function ConfigRead
!define ConfigRead `!insertmacro ConfigReadCall`
!define ConfigRead `!insertmacro ConfigReadCall`

Revision as of 14:28, 4 July 2005

Author: Instructor (talk, contrib)


Links

Latest version of headers "nsh.zip"
http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost

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

The Function Description

____________________________________________________________________________
 
                            ConfigRead v1.0
____________________________________________________________________________
 
 
Read value from entry name in config file.
 
 
Syntax:
${ConfigRead} "[File]" "[Entry]" $var
 
"[File]"      ; config file
              ;
"[Entry]"     ; entry name
              ;
$var          ; Result:  Value
 
 
Note:
-Error flag if file isn't exist


Example1:

Section
	${ConfigRead} "C:\AUTOEXEC.BAT" "SET winbootdir=" $R0
	;$R0=C:\WINDOWS
SectionEnd

Example2:

Section
	${ConfigRead} "C:\apache\conf\httpd.conf" "Timeout " $R0
	;$R0=30
SectionEnd

The Function Code

Function ConfigRead
	!define ConfigRead `!insertmacro ConfigReadCall`
 
	!macro ConfigReadCall _FILE _ENTRY _RESULT
		Push `${_FILE}`
		Push `${_ENTRY}`
		Call ConfigRead
		Pop ${_RESULT}
	!macroend
 
	Exch $1
	Exch
	Exch $0
	Exch
	Push $2
	Push $3
	Push $4
	ClearErrors
 
	FileOpen $2 $0 r
	IfErrors error
	StrLen $0 $1
	StrCmp $0 0 error
 
	readnext:
	FileRead $2 $3
	IfErrors empty
	StrCpy $4 $3 $0
	StrCmp $4 $1 0 readnext
	StrCpy $0 $3 '' $0
	StrCpy $4 $0 1 -1
	StrCmp $4 '$\r' +2
	StrCmp $4 '$\n' 0 close
	StrCpy $0 $0 -1
	goto -4
 
	error:
	SetErrors
 
	empty:
	StrCpy $0 ''
 
	close:
	FileClose $2
 
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Exch $0
FunctionEnd