FileRecode: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Created by user: [[{{ns:2}}:|]] ([[{{ns:3}}:|talk]], [[{{ns:-1}}:Contributions/|contrib]]).)
 
m (Forgot to put authors and categories in.)
Line 80: Line 80:
FunctionEnd
FunctionEnd
</highlight-nsis>
</highlight-nsis>
[[{{ns:14}}:Text Files Manipulation Functions]]

Revision as of 07:24, 21 May 2005

The Function

/*
____________________________________________________________________________
 
                            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 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 $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