--- joko/ToolBox/Windows/VpnDial-installer/file_functions.nsi 2005/11/21 19:31:51 1.1 +++ joko/ToolBox/Windows/VpnDial-installer/file_functions.nsi 2005/11/22 14:28:15 1.2 @@ -1,232 +1,232 @@ -Function FileSearch - Exch $0 ;search for - Exch - Exch $1 ;input file - Exch - Push $2 - Push $3 - Push $4 - Push $5 - Push $6 - Push $7 - Push $8 - Push $9 - Push $R0 - FileOpen $2 $1 r - StrLen $4 $0 - StrCpy $5 0 - StrCpy $7 no - StrCpy $8 0 - StrCpy $9 0 - loop_main: - FileRead $2 $3 - IfErrors done - IntOp $R0 $R0 + $9 - StrCpy $9 0 - StrCpy $5 0 - filter_top: - IntOp $5 $5 - 1 - StrCpy $6 $3 $4 $5 - StrCmp $6 "" loop_main - StrCmp $6 $0 0 filter_top - StrCpy $3 $3 $5 - StrCpy $5 0 - StrCpy $7 yes - StrCpy $9 1 - IntOp $8 $8 + 1 - Goto filter_top - done: - FileClose $2 - StrCpy $0 $8 - StrCpy $1 $7 - StrCpy $2 $R0 - Pop $R0 - Pop $9 - Pop $8 - Pop $7 - Pop $6 - Pop $5 - Pop $4 - Pop $3 - Exch 2 - Exch $2 ;output number of lines - Exch 2 - Exch - Exch $1 ;output yes/no - Exch - Exch $0 ;output count found -FunctionEnd - - -Function JoinFiles - Exch $1 - Exch - Exch $3 - Exch - Exch 2 - Exch $4 - Exch 2 - Push $0 - Push $2 - Push $5 - GetTempFileName $5 - SetDetailsPrint none - CopyFiles $1 $5 - SetDetailsPrint both - FileOpen $0 $5 a - FileOpen $2 $3 r - loop1: - FileRead $0 $1 - IfErrors doneloop1 - Goto loop1 - doneloop1: - FileWrite $0 "$\r$\n$\r$\n$\r$\n" #Optional [divider] - loop2: - FileRead $2 $1 - FileWrite $0 $1 - IfErrors done - Goto loop2 - done: - FileClose $2 - FileClose $0 - SetDetailsPrint none - IfFileExists $4 0 +2 - Delete $4 - CopyFiles $5 $4 - Delete $5 - SetDetailsPrint both - Pop $5 - Pop $2 - Pop $0 - Pop $4 - Pop $3 - Pop $1 -FunctionEnd - - -Function AdvReplaceInFile - -; Taken from http://nsis.sourceforge.net/archive/nsisweb.php?page=316&instances=0,11,311 -; Hacked by Jolo of Xegony to simplify the removal of a line - ;; Note that this wont do the right thing if you're trying to - ;; null out a substring within a line. If the replacement is - ;; null, we're assuming you want to null out the entire line. - - Exch $0 ;file to replace in - Exch - Exch $1 ;number to replace after - Exch - Exch 2 - Exch $2 ;replace and onwards - Exch 2 - Exch 3 - Exch $3 ;replace with - Exch 3 - Exch 4 - Exch $4 ;to replace - Exch 4 - Push $5 ;minus count - Push $6 ;universal - Push $7 ;end string - Push $8 ;left string - Push $9 ;right string - Push $R0 ;file1 - Push $R1 ;file2 - Push $R2 ;read - Push $R3 ;universal - Push $R4 ;count (onwards) - Push $R5 ;count (after) - Push $R6 ;temp file name - - GetTempFileName $R6 - FileOpen $R1 $0 r ;file to search in - FileOpen $R0 $R6 w ;temp file - StrLen $R3 $4 ; $R3 = strlen(search_for) - StrCpy $R4 -1 ; $R4 = -1 - StrCpy $R5 -1 ; $R5 = -1 - - loop_read: - ClearErrors - FileRead $R1 $R2 ;read line - IfErrors exit - - StrCpy $5 0 ; $ptr = 0 - StrCpy $7 $R2 ; $line = current_line - - loop_filter: - IntOp $5 $5 - 1 ; $ptr-- - StrCpy $6 $7 $R3 $5 ;search ; $examine = substr($line, len:len_search_for, ptr_from_end) - StrCmp $6 "" file_write2 ; if ($examine==NULL) write unmod'd line # escape clause - StrCmp $6 $4 0 loop_filter ; if ($examine==$search_for) { continue; } else { loop_filter ) - - ;; found it - ;; DetailPrint "Found: SEARCH[$4]" - StrCpy $8 $7 $5 ;left part ; $left = substr($line, $ptr) - IntOp $6 $5 + $R3 ; $6 = position + strlen(search_for) - StrCpy $9 $7 "" $6 ;right part ; $right = line - - StrLen $6 $7 ; $6 = strlen(line) - - StrCpy $7 $8$3$9 ;re-join ; $line = $left + $replace + $right - ;; DetailPrint "new = [$8][$3][$9] = [$7]" - - ;; what's this test for? - StrCmp -$6 $5 0 loop_filter ; if (strlen($line) == len(ptr)) then {continue } else { scan more? } - - ;; replacement qualifier(s) - ;; start replacing after $2 occurrences - IntOp $R4 $R4 + 1 - StrCmp $2 all file_write1 - StrCmp $R4 $2 0 file_write2 - IntOp $R4 $R4 - 1 - - ;; replacement qualifier(s) - ;; replace next $1 occurrences - IntOp $R5 $R5 + 1 - StrCmp $1 all file_write1 - StrCmp $R5 $1 0 file_write1 - IntOp $R5 $R5 - 1 - Goto file_write2 - - file_write1: - ;; Note that this wont do the right thing if you're trying to - ;; null out a substring within a line. If the replacement is - ;; null, we're assuming you want to null out the entire line. - StrCmp $3 "" loop_read 0 ;; bail if we're trying to delete a line - ;; DetailPrint "WRITING MODIFIED = [$7]" - FileWrite $R0 $7 ;write modified line - Goto loop_read - - file_write2: - ;; DetailPrint "WRITING UNMODIFIED = [$R2]" - FileWrite $R0 $R2 ;write unmodified line - Goto loop_read - - exit: - FileClose $R0 - FileClose $R1 - - SetDetailsPrint none - Delete $0 - Rename $R6 $0 - Delete $R6 - SetDetailsPrint both - - Pop $R6 - Pop $R5 - Pop $R4 - Pop $R3 - Pop $R2 - Pop $R1 - Pop $R0 - Pop $9 - Pop $8 - Pop $7 - Pop $6 - Pop $5 - Pop $4 - Pop $3 - Pop $2 - Pop $1 - Pop $0 -FunctionEnd +Function FileSearch + Exch $0 ;search for + Exch + Exch $1 ;input file + Exch + Push $2 + Push $3 + Push $4 + Push $5 + Push $6 + Push $7 + Push $8 + Push $9 + Push $R0 + FileOpen $2 $1 r + StrLen $4 $0 + StrCpy $5 0 + StrCpy $7 no + StrCpy $8 0 + StrCpy $9 0 + loop_main: + FileRead $2 $3 + IfErrors done + IntOp $R0 $R0 + $9 + StrCpy $9 0 + StrCpy $5 0 + filter_top: + IntOp $5 $5 - 1 + StrCpy $6 $3 $4 $5 + StrCmp $6 "" loop_main + StrCmp $6 $0 0 filter_top + StrCpy $3 $3 $5 + StrCpy $5 0 + StrCpy $7 yes + StrCpy $9 1 + IntOp $8 $8 + 1 + Goto filter_top + done: + FileClose $2 + StrCpy $0 $8 + StrCpy $1 $7 + StrCpy $2 $R0 + Pop $R0 + Pop $9 + Pop $8 + Pop $7 + Pop $6 + Pop $5 + Pop $4 + Pop $3 + Exch 2 + Exch $2 ;output number of lines + Exch 2 + Exch + Exch $1 ;output yes/no + Exch + Exch $0 ;output count found +FunctionEnd + + +Function JoinFiles + Exch $1 + Exch + Exch $3 + Exch + Exch 2 + Exch $4 + Exch 2 + Push $0 + Push $2 + Push $5 + GetTempFileName $5 + SetDetailsPrint none + CopyFiles $1 $5 + SetDetailsPrint both + FileOpen $0 $5 a + FileOpen $2 $3 r + loop1: + FileRead $0 $1 + IfErrors doneloop1 + Goto loop1 + doneloop1: + FileWrite $0 "$\r$\n$\r$\n$\r$\n" #Optional [divider] + loop2: + FileRead $2 $1 + FileWrite $0 $1 + IfErrors done + Goto loop2 + done: + FileClose $2 + FileClose $0 + SetDetailsPrint none + IfFileExists $4 0 +2 + Delete $4 + CopyFiles $5 $4 + Delete $5 + SetDetailsPrint both + Pop $5 + Pop $2 + Pop $0 + Pop $4 + Pop $3 + Pop $1 +FunctionEnd + + +Function AdvReplaceInFile + +; Taken from http://nsis.sourceforge.net/archive/nsisweb.php?page=316&instances=0,11,311 +; Hacked by Jolo of Xegony to simplify the removal of a line + ;; Note that this wont do the right thing if you're trying to + ;; null out a substring within a line. If the replacement is + ;; null, we're assuming you want to null out the entire line. + + Exch $0 ;file to replace in + Exch + Exch $1 ;number to replace after + Exch + Exch 2 + Exch $2 ;replace and onwards + Exch 2 + Exch 3 + Exch $3 ;replace with + Exch 3 + Exch 4 + Exch $4 ;to replace + Exch 4 + Push $5 ;minus count + Push $6 ;universal + Push $7 ;end string + Push $8 ;left string + Push $9 ;right string + Push $R0 ;file1 + Push $R1 ;file2 + Push $R2 ;read + Push $R3 ;universal + Push $R4 ;count (onwards) + Push $R5 ;count (after) + Push $R6 ;temp file name + + GetTempFileName $R6 + FileOpen $R1 $0 r ;file to search in + FileOpen $R0 $R6 w ;temp file + StrLen $R3 $4 ; $R3 = strlen(search_for) + StrCpy $R4 -1 ; $R4 = -1 + StrCpy $R5 -1 ; $R5 = -1 + + loop_read: + ClearErrors + FileRead $R1 $R2 ;read line + IfErrors exit + + StrCpy $5 0 ; $ptr = 0 + StrCpy $7 $R2 ; $line = current_line + + loop_filter: + IntOp $5 $5 - 1 ; $ptr-- + StrCpy $6 $7 $R3 $5 ;search ; $examine = substr($line, len:len_search_for, ptr_from_end) + StrCmp $6 "" file_write2 ; if ($examine==NULL) write unmod'd line # escape clause + StrCmp $6 $4 0 loop_filter ; if ($examine==$search_for) { continue; } else { loop_filter ) + + ;; found it + ;; DetailPrint "Found: SEARCH[$4]" + StrCpy $8 $7 $5 ;left part ; $left = substr($line, $ptr) + IntOp $6 $5 + $R3 ; $6 = position + strlen(search_for) + StrCpy $9 $7 "" $6 ;right part ; $right = line + + StrLen $6 $7 ; $6 = strlen(line) + + StrCpy $7 $8$3$9 ;re-join ; $line = $left + $replace + $right + ;; DetailPrint "new = [$8][$3][$9] = [$7]" + + ;; what's this test for? + StrCmp -$6 $5 0 loop_filter ; if (strlen($line) == len(ptr)) then {continue } else { scan more? } + + ;; replacement qualifier(s) + ;; start replacing after $2 occurrences + IntOp $R4 $R4 + 1 + StrCmp $2 all file_write1 + StrCmp $R4 $2 0 file_write2 + IntOp $R4 $R4 - 1 + + ;; replacement qualifier(s) + ;; replace next $1 occurrences + IntOp $R5 $R5 + 1 + StrCmp $1 all file_write1 + StrCmp $R5 $1 0 file_write1 + IntOp $R5 $R5 - 1 + Goto file_write2 + + file_write1: + ;; Note that this wont do the right thing if you're trying to + ;; null out a substring within a line. If the replacement is + ;; null, we're assuming you want to null out the entire line. + StrCmp $3 "" loop_read 0 ;; bail if we're trying to delete a line + ;; DetailPrint "WRITING MODIFIED = [$7]" + FileWrite $R0 $7 ;write modified line + Goto loop_read + + file_write2: + ;; DetailPrint "WRITING UNMODIFIED = [$R2]" + FileWrite $R0 $R2 ;write unmodified line + Goto loop_read + + exit: + FileClose $R0 + FileClose $R1 + + SetDetailsPrint none + Delete $0 + Rename $R6 $0 + Delete $R6 + SetDetailsPrint both + + Pop $R6 + Pop $R5 + Pop $R4 + Pop $R3 + Pop $R2 + Pop $R1 + Pop $R0 + Pop $9 + Pop $8 + Pop $7 + Pop $6 + Pop $5 + Pop $4 + Pop $3 + Pop $2 + Pop $1 + Pop $0 +FunctionEnd