FileJoin: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Added category links.) |
m (Updated by user: Instructor (talk, contrib).) |
||
Line 7: | Line 7: | ||
: http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost | : http://forums.winamp.com/showthread.php?s=&threadid=203228&goto=lastpost | ||
If function used without header | If a function is used without an header, you should put the function below in your script before calling it. | ||
== The Function == | == The Function == | ||
<highlight-nsis>/*
____________________________________________________________________________ | <highlight-nsis>/*
____________________________________________________________________________ | ||
FileJoin v1.4 | |||
____________________________________________________________________________ | ____________________________________________________________________________ | ||
Thanks | Thanks Afrow UK (Based on his idea of Function "JoinFiles") | ||
Join two files in one (File1 + File2 = File3). | |||
Syntax: | Syntax: | ||
${ | ${FileJoin} "[File1]" "[File2]" "[File3]" | ||
"[ | |||
"[File1]" ; Input File1 | |||
"[File2]" ; Input File2 | |||
"[File3]" ; Output File3 | |||
; If [File3]="" Then add [File2] to [File1] | |||
Note: | Note: | ||
-Error flag if | -Error flag if input files aren't exists | ||
-Error flag if | -Error flag if output file path isn't exists | ||
Example1 (Join: a.log + b.log = Z.log): | |||
Section | Section | ||
${ | ${FileJoin} "C:\a.log" "C:\logs\b.log" "C:\Z.log" | ||
SectionEnd | |||
Example2 (Add: a.log + b.log = a.log): | |||
Section | |||
${FileJoin} "C:\a.log" "C:\logs\b.log" "C:\a.log" | |||
SectionEnd*/ | SectionEnd*/ | ||
Line 54: | Line 49: | ||
;--------------------------------------------------------------------------- | ;--------------------------------------------------------------------------- | ||
Function | Function FileJoin | ||
!define | !define FileJoin `!insertmacro FileJoinCall` | ||
!macro | !macro FileJoinCall _FILE1 _FILE2 _FILE3 | ||
Push `${ | Push `${_FILE1}` | ||
Push `${ | Push `${_FILE2}` | ||
Push `${_FILE3}` | |||
Call FileJoin | |||
!macroend | !macroend | ||
Exch $2 | |||
Exch | |||
Exch $1 | Exch $1 | ||
Exch | Exch | ||
Exch 2 | |||
Exch $0 | Exch $0 | ||
Exch | Exch 2 | ||
Push $3 | Push $3 | ||
Push $4 | Push $4 | ||
Push $5 | Push $5 | ||
ClearErrors | ClearErrors | ||
StrCpy $ | IfFileExists $0 0 error | ||
StrCmp $2 '\' 0 +3 | IfFileExists $1 0 error | ||
StrCpy $0 $0 -1 | StrCpy $3 0 | ||
IntOp $3 $3 - 1 | |||
StrCpy $4 $2 1 $3 | |||
StrCmp $4 \ +2 | |||
StrCmp $4 '' +3 -3 | |||
StrCpy $4 $2 $3 | |||
IfFileExists '$4\*.*' 0 error | |||
StrCmp $2 $0 0 +2 | |||
StrCpy $2 '' | |||
StrCmp $2 '' 0 +3 | |||
StrCpy $4 $0 | |||
goto +3 | |||
GetTempFileName $4 | |||
CopyFiles /SILENT $0 $4 | |||
FileOpen $3 $4 a | |||
IfErrors error | |||
FileSeek $3 -1 END | |||
FileRead $3 $5 | |||
StrCmp $5 '$\r' +3 | |||
StrCmp $5 '$' +2 | |||
FileWrite $3 '$\r$' | |||
;FileWrite $3 '$\r$--Divider--$\r$' | |||
FileOpen $0 $1 r | |||
IfErrors error | |||
FileRead $0 $5 | |||
IfErrors +3 | |||
FileWrite $3 $5 | |||
goto -3 | goto -3 | ||
FileClose $0 | |||
FileClose $3 | |||
StrCmp $2 '' end | |||
StrCmp $2 ' | Delete '$EXEDIR\$2' | ||
Rename $4 '$EXEDIR\$2' | |||
IfErrors 0 end | |||
Delete $2 | |||
Rename $4 $2 | |||
IfErrors 0 end | |||
error: | error: | ||
SetErrors | SetErrors | ||
end: | end: | ||
Pop $5 | Pop $5 | ||
Pop $4 | Pop $4 | ||
Line 165: | Line 123: | ||
Pop $2 | Pop $2 | ||
Pop $1 | Pop $1 | ||
Pop $0 | |||
FunctionEnd | FunctionEnd | ||
</highlight-nsis> | </highlight-nsis> | ||
[[{{ns:14}}:Text Files Manipulation Functions]] | [[{{ns:14}}:Text Files Manipulation Functions]] |
Revision as of 09:39, 24 June 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 an header, you should put the function below in your script before calling it.
The Function
/* ____________________________________________________________________________ FileJoin v1.4 ____________________________________________________________________________ Thanks Afrow UK (Based on his idea of Function "JoinFiles") Join two files in one (File1 + File2 = File3). Syntax: ${FileJoin} "[File1]" "[File2]" "[File3]" "[File1]" ; Input File1 "[File2]" ; Input File2 "[File3]" ; Output File3 ; If [File3]="" Then add [File2] to [File1] Note: -Error flag if input files aren't exists -Error flag if output file path isn't exists Example1 (Join: a.log + b.log = Z.log): Section ${FileJoin} "C:\a.log" "C:\logs\b.log" "C:\Z.log" SectionEnd Example2 (Add: a.log + b.log = a.log): Section ${FileJoin} "C:\a.log" "C:\logs\b.log" "C:\a.log" SectionEnd*/ ;--------------------------------------------------------------------------- Function FileJoin !define FileJoin `!insertmacro FileJoinCall` !macro FileJoinCall _FILE1 _FILE2 _FILE3 Push `${_FILE1}` Push `${_FILE2}` Push `${_FILE3}` Call FileJoin !macroend Exch $2 Exch Exch $1 Exch Exch 2 Exch $0 Exch 2 Push $3 Push $4 Push $5 ClearErrors IfFileExists $0 0 error IfFileExists $1 0 error StrCpy $3 0 IntOp $3 $3 - 1 StrCpy $4 $2 1 $3 StrCmp $4 \ +2 StrCmp $4 '' +3 -3 StrCpy $4 $2 $3 IfFileExists '$4\*.*' 0 error StrCmp $2 $0 0 +2 StrCpy $2 '' StrCmp $2 '' 0 +3 StrCpy $4 $0 goto +3 GetTempFileName $4 CopyFiles /SILENT $0 $4 FileOpen $3 $4 a IfErrors error FileSeek $3 -1 END FileRead $3 $5 StrCmp $5 '$\r' +3 StrCmp $5 '$' +2 FileWrite $3 '$\r$' ;FileWrite $3 '$\r$--Divider--$\r$' FileOpen $0 $1 r IfErrors error FileRead $0 $5 IfErrors +3 FileWrite $3 $5 goto -3 FileClose $0 FileClose $3 StrCmp $2 '' end Delete '$EXEDIR\$2' Rename $4 '$EXEDIR\$2' IfErrors 0 end Delete $2 Rename $4 $2 IfErrors 0 end error: SetErrors end: Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0 FunctionEnd