ConfigRead: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{PageAuthor|Instructor}}
{{PageAuthor|Instructor}}


== Links ==
{{User:Instructor/Headers/Template}}


; Latest version of headers "nsh.zip":
== Function Description ==
: 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==


<highlight-nsis>
<highlight-nsis>
____________________________________________________________________________
____________________________________________________________________________


                             ConfigRead v1.0
                             ConfigRead v1.1
____________________________________________________________________________
____________________________________________________________________________


Line 31: Line 26:


Note:
Note:
-Error flag if entry not found
-Error flag if file isn't exist
-Error flag if file isn't exist
</highlight-nsis>
</highlight-nsis>
Line 50: Line 46:
</highlight-nsis>
</highlight-nsis>


== The Function Code==
== Function Code ==


<highlight-nsis>
<highlight-nsis>
Line 79: Line 75:
readnext:
readnext:
FileRead $2 $3
FileRead $2 $3
IfErrors empty
IfErrors error
StrCpy $4 $3 $0
StrCpy $4 $3 $0
StrCmp $4 $1 0 readnext
StrCmp $4 $1 0 readnext
Line 91: Line 87:
error:
error:
SetErrors
SetErrors
empty:
StrCpy $0 ''
StrCpy $0 ''


Line 105: Line 99:
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>
 
Please Test First then Upload any script.. don't be gumrah
[[Category:Text Files Manipulation Functions]]
[[Category:Text Files Manipulation Functions]]

Latest revision as of 06:18, 19 June 2010

Author: Instructor (talk, contrib)


Page for NSIS 2.07 and below users

You can use the latest version of headers (recommended) or the following function code (put the function code in your script before calling it)

Function Description

____________________________________________________________________________
 
                            ConfigRead v1.1
____________________________________________________________________________
 
 
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 entry not found
-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

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 error
	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
	StrCpy $0 ''
 
	close:
	FileClose $2
 
	Pop $4
	Pop $3
	Pop $2
	Pop $1
	Exch $0
FunctionEnd

Please Test First then Upload any script.. don't be gumrah