FileRecode: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Adding new author and category links.) |
Instructor (talk | contribs) 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> | |||
____________________________________________________________________________ | ____________________________________________________________________________ | ||
LineSum | |||
____________________________________________________________________________ | ____________________________________________________________________________ | ||
Thanks Afrow UK (Based on his idea of Function "LineCount") | |||
Get sum of lines in text file. | |||
Syntax: | Syntax: | ||
${ | ${LineSum} "[File]" $var | ||
"[File | "[File]" ; Input file | ||
$var ; Result: Sum of lines | |||
Note: | Note: | ||
-Error flag if file isn't | -Error flag if input file isn't exists | ||
- | </highlight-nsis> | ||
<b>Example:</b> | |||
<highlight-nsis>Section | |||
${LineSum} "C:\a.log" $R0 | |||
; $R0="54" | |||
SectionEnd | |||
</highlight-nsis> | |||
== The Function Code== | |||
<highlight-nsis> | |||
Function FileRecode | Function FileRecode | ||
!define FileRecode `!insertmacro FileRecodeCall` | !define FileRecode `!insertmacro FileRecodeCall` |
Revision as of 14:25, 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
____________________________________________________________________________ LineSum ____________________________________________________________________________ Thanks Afrow UK (Based on his idea of Function "LineCount") Get sum of lines in text file. Syntax: ${LineSum} "[File]" $var "[File]" ; Input file $var ; Result: Sum of lines Note: -Error flag if input file isn't exists
Example:
Section ${LineSum} "C:\a.log" $R0 ; $R0="54" SectionEnd
The Function Code
Function FileRecode !define FileRecode `!insertmacro FileRecodeCall` !macro FileRecodeCall _FILE _FORMAT Push `${_FILE}` Push `${_FORMAT}` Call FileRecode !macroend Exch $1 Exch Exch $0 Exch Push $2 Push $3 Push $4 IfFileExists $0 0 error StrCmp $1 OemToChar +2 StrCmp $1 CharToOem 0 error FileOpen $2 $0 a IfErrors error FileSeek $2 0 END $3 System::Alloc $3 Pop $4 FileSeek $2 0 SET System::Call 'kernel32::ReadFile(i r2, i r4, i $3, t.,)' System::Call 'user32::$1Buff(i r4, i r4, i $3)' FileSeek $2 0 SET System::Call 'kernel32::WriteFile(i r2, i r4, i $3, t.,)' System::Free $4 FileClose $2 goto end error: SetErrors end: Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 FunctionEnd