FileRecode: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same 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>
____________________________________________________________________________
____________________________________________________________________________


                             LineSum
                             FileRecode
____________________________________________________________________________
____________________________________________________________________________
Thanks Afrow UK (Based on his idea of Function "LineCount")




Get sum of lines in text file.
Recode text file from DOS to Windows format and vice-versa.




Syntax:
Syntax:
${LineSum} "[File]" $var
${FileRecode} "[File]" "[Format]"


"[File]"      ; Input file
"[File]"        ;
$var          ; Result: Sum of lines
                ;
"[Format]"      ; OemToChar  -from DOS to Windows
                ; CharToOem  -from Windows to DOS




Note:
Note:
-Error flag if input file isn't exists
-Error flag if file isn't exist
-Error flag if syntax error
</highlight-nsis>
</highlight-nsis>


Line 37: Line 33:
<b>Example:</b>
<b>Example:</b>
<highlight-nsis>Section
<highlight-nsis>Section
${LineSum} "C:\a.log" $R0
${FileRecode} "C:\SCANDISK.LOG" "CharToOem"
; $R0="54"
SectionEnd
SectionEnd
</highlight-nsis>
</highlight-nsis>


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


<highlight-nsis>
<highlight-nsis>
Function FileRecode
Function FileRecode
!define FileRecode `!insertmacro FileRecodeCall`
!define FileRecode `!insertmacro FileRecodeCall`
Line 67: Line 63:


FileOpen $2 $0 a
FileOpen $2 $0 a
IfErrors error
FileSeek $2 0 END $3
FileSeek $2 0 END $3
System::Alloc $3
System::Alloc /NOUNLOAD $3
Pop $4
Pop $4
FileSeek $2 0 SET
FileSeek $2 0 SET
System::Call 'kernel32::ReadFile(i r2, i r4, i $3, t.,)'
System::Call /NOUNLOAD 'kernel32::ReadFile(i r2, i r4, i $3, t.,)'
System::Call 'user32::$1Buff(i r4, i r4, i $3)'
System::Call /NOUNLOAD 'user32::$1Buff(i r4, i r4, i $3)'
FileSeek $2 0 SET
FileSeek $2 0 SET
System::Call 'kernel32::WriteFile(i r2, i r4, i $3, t.,)'
System::Call /NOUNLOAD 'kernel32::WriteFile(i r2, i r4, i $3, t.,)'
 
System::Free $4
System::Free $4
FileClose $2
FileClose $2

Latest revision as of 07:30, 7 February 2006

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

____________________________________________________________________________
 
                            FileRecode
____________________________________________________________________________
 
 
Recode text file from DOS to Windows format and vice-versa.
 
 
Syntax:
${FileRecode} "[File]" "[Format]"
 
"[File]"        ;
                ;
"[Format]"      ; OemToChar   -from DOS to Windows
                ; CharToOem   -from Windows to DOS
 
 
Note:
-Error flag if file isn't exist
-Error flag if syntax error


Example:

Section
	${FileRecode} "C:\SCANDISK.LOG" "CharToOem"
SectionEnd

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
	FileSeek $2 0 END $3
	System::Alloc /NOUNLOAD $3
	Pop $4
	FileSeek $2 0 SET
	System::Call /NOUNLOAD 'kernel32::ReadFile(i r2, i r4, i $3, t.,)'
	System::Call /NOUNLOAD 'user32::$1Buff(i r4, i r4, i $3)'
	FileSeek $2 0 SET
	System::Call /NOUNLOAD '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