/[cvs]/joko/ToolBox/Windows/VpnDial-installer/file_functions.nsi
ViewVC logotype

Diff of /joko/ToolBox/Windows/VpnDial-installer/file_functions.nsi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by joko, Mon Nov 21 19:31:51 2005 UTC revision 1.2 by janosch, Tue Nov 22 14:28:15 2005 UTC
# Line 1  Line 1 
1  Function FileSearch  Function FileSearch
2    Exch $0 ;search for    Exch $0 ;search for
3    Exch    Exch
4    Exch $1 ;input file    Exch $1 ;input file
5    Exch    Exch
6    Push $2    Push $2
7    Push $3    Push $3
8    Push $4    Push $4
9    Push $5    Push $5
10    Push $6    Push $6
11    Push $7    Push $7
12    Push $8    Push $8
13    Push $9    Push $9
14    Push $R0    Push $R0
15      FileOpen $2 $1 r      FileOpen $2 $1 r
16      StrLen $4 $0      StrLen $4 $0
17      StrCpy $5 0      StrCpy $5 0
18      StrCpy $7 no      StrCpy $7 no
19      StrCpy $8 0      StrCpy $8 0
20      StrCpy $9 0      StrCpy $9 0
21    loop_main:    loop_main:
22      FileRead $2 $3      FileRead $2 $3
23      IfErrors done      IfErrors done
24     IntOp $R0 $R0 + $9     IntOp $R0 $R0 + $9
25      StrCpy $9 0      StrCpy $9 0
26      StrCpy $5 0      StrCpy $5 0
27    filter_top:    filter_top:
28     IntOp $5 $5 - 1     IntOp $5 $5 - 1
29      StrCpy $6 $3 $4 $5      StrCpy $6 $3 $4 $5
30      StrCmp $6 "" loop_main      StrCmp $6 "" loop_main
31      StrCmp $6 $0 0 filter_top      StrCmp $6 $0 0 filter_top
32      StrCpy $3 $3 $5      StrCpy $3 $3 $5
33      StrCpy $5 0      StrCpy $5 0
34     StrCpy $7 yes     StrCpy $7 yes
35     StrCpy $9 1     StrCpy $9 1
36     IntOp $8 $8 + 1     IntOp $8 $8 + 1
37    Goto filter_top    Goto filter_top
38    done:    done:
39      FileClose $2      FileClose $2
40      StrCpy $0 $8      StrCpy $0 $8
41      StrCpy $1 $7      StrCpy $1 $7
42      StrCpy $2 $R0      StrCpy $2 $R0
43    Pop $R0    Pop $R0
44    Pop $9    Pop $9
45    Pop $8    Pop $8
46    Pop $7    Pop $7
47    Pop $6    Pop $6
48    Pop $5    Pop $5
49    Pop $4    Pop $4
50    Pop $3    Pop $3
51    Exch 2    Exch 2
52    Exch $2 ;output number of lines    Exch $2 ;output number of lines
53    Exch 2    Exch 2
54    Exch    Exch
55    Exch $1 ;output yes/no    Exch $1 ;output yes/no
56    Exch    Exch
57    Exch $0 ;output count found    Exch $0 ;output count found
58  FunctionEnd  FunctionEnd
59    
60    
61  Function JoinFiles  Function JoinFiles
62    Exch $1    Exch $1
63    Exch    Exch
64    Exch $3    Exch $3
65    Exch    Exch
66    Exch 2    Exch 2
67    Exch $4    Exch $4
68    Exch 2    Exch 2
69    Push $0    Push $0
70    Push $2    Push $2
71    Push $5    Push $5
72      GetTempFileName $5      GetTempFileName $5
73      SetDetailsPrint none      SetDetailsPrint none
74      CopyFiles $1 $5      CopyFiles $1 $5
75      SetDetailsPrint both      SetDetailsPrint both
76    FileOpen $0 $5 a    FileOpen $0 $5 a
77    FileOpen $2 $3 r    FileOpen $2 $3 r
78    loop1:    loop1:
79      FileRead $0 $1      FileRead $0 $1
80      IfErrors doneloop1      IfErrors doneloop1
81    Goto loop1    Goto loop1
82    doneloop1:    doneloop1:
83      FileWrite $0 "$\r$\n$\r$\n$\r$\n" #Optional [divider]      FileWrite $0 "$\r$\n$\r$\n$\r$\n" #Optional [divider]
84    loop2:    loop2:
85      FileRead $2 $1      FileRead $2 $1
86      FileWrite $0 $1      FileWrite $0 $1
87      IfErrors done      IfErrors done
88    Goto loop2    Goto loop2
89    done:    done:
90       FileClose $2       FileClose $2
91       FileClose $0       FileClose $0
92      SetDetailsPrint none      SetDetailsPrint none
93      IfFileExists $4 0 +2      IfFileExists $4 0 +2
94      Delete $4      Delete $4
95      CopyFiles $5 $4      CopyFiles $5 $4
96      Delete $5      Delete $5
97      SetDetailsPrint both      SetDetailsPrint both
98    Pop $5    Pop $5
99    Pop $2    Pop $2
100    Pop $0    Pop $0
101    Pop $4    Pop $4
102    Pop $3    Pop $3
103    Pop $1    Pop $1
104  FunctionEnd  FunctionEnd
105    
106    
107  Function AdvReplaceInFile  Function AdvReplaceInFile
108    
109  ; Taken from http://nsis.sourceforge.net/archive/nsisweb.php?page=316&instances=0,11,311  ; Taken from http://nsis.sourceforge.net/archive/nsisweb.php?page=316&instances=0,11,311
110  ; Hacked by Jolo of Xegony to simplify the removal of a line  ; Hacked by Jolo of Xegony to simplify the removal of a line
111          ;; Note that this wont do the right thing if you're trying to          ;; Note that this wont do the right thing if you're trying to
112          ;; null out a substring within a line.  If the replacement is          ;; null out a substring within a line.  If the replacement is
113          ;; null, we're assuming you want to null out the entire line.          ;; null, we're assuming you want to null out the entire line.
114    
115      Exch $0 ;file to replace in      Exch $0 ;file to replace in
116      Exch      Exch
117      Exch $1 ;number to replace after      Exch $1 ;number to replace after
118      Exch      Exch
119      Exch 2      Exch 2
120      Exch $2 ;replace and onwards      Exch $2 ;replace and onwards
121      Exch 2      Exch 2
122      Exch 3      Exch 3
123      Exch $3 ;replace with      Exch $3 ;replace with
124      Exch 3      Exch 3
125      Exch 4      Exch 4
126      Exch $4 ;to replace      Exch $4 ;to replace
127      Exch 4      Exch 4
128      Push $5 ;minus count      Push $5 ;minus count
129      Push $6 ;universal      Push $6 ;universal
130      Push $7 ;end string      Push $7 ;end string
131      Push $8 ;left string      Push $8 ;left string
132      Push $9 ;right string      Push $9 ;right string
133      Push $R0 ;file1      Push $R0 ;file1
134      Push $R1 ;file2      Push $R1 ;file2
135      Push $R2 ;read      Push $R2 ;read
136      Push $R3 ;universal      Push $R3 ;universal
137      Push $R4 ;count (onwards)      Push $R4 ;count (onwards)
138      Push $R5 ;count (after)      Push $R5 ;count (after)
139      Push $R6 ;temp file name      Push $R6 ;temp file name
140    
141          GetTempFileName $R6          GetTempFileName $R6
142          FileOpen $R1 $0 r ;file to search in          FileOpen $R1 $0 r ;file to search in
143          FileOpen $R0 $R6 w ;temp file          FileOpen $R0 $R6 w ;temp file
144          StrLen $R3 $4                    ; $R3 = strlen(search_for)          StrLen $R3 $4                    ; $R3 = strlen(search_for)
145          StrCpy $R4 -1                    ; $R4 = -1          StrCpy $R4 -1                    ; $R4 = -1
146          StrCpy $R5 -1                    ; $R5 = -1          StrCpy $R5 -1                    ; $R5 = -1
147    
148      loop_read:      loop_read:
149          ClearErrors          ClearErrors
150          FileRead $R1 $R2 ;read line          FileRead $R1 $R2 ;read line
151          IfErrors exit          IfErrors exit
152    
153          StrCpy $5 0                      ; $ptr = 0          StrCpy $5 0                      ; $ptr = 0
154          StrCpy $7 $R2                    ; $line = current_line          StrCpy $7 $R2                    ; $line = current_line
155    
156      loop_filter:      loop_filter:
157          IntOp $5 $5 - 1                  ; $ptr--          IntOp $5 $5 - 1                  ; $ptr--
158          StrCpy $6 $7 $R3 $5 ;search      ; $examine = substr($line, len:len_search_for, ptr_from_end)          StrCpy $6 $7 $R3 $5 ;search      ; $examine = substr($line, len:len_search_for, ptr_from_end)
159          StrCmp $6 "" file_write2         ; if ($examine==NULL) write unmod'd line  # escape clause          StrCmp $6 "" file_write2         ; if ($examine==NULL) write unmod'd line  # escape clause
160          StrCmp $6 $4 0 loop_filter       ; if ($examine==$search_for) { continue; } else { loop_filter )          StrCmp $6 $4 0 loop_filter       ; if ($examine==$search_for) { continue; } else { loop_filter )
161    
162          ;; found it          ;; found it
163          ;; DetailPrint "Found: SEARCH[$4]"          ;; DetailPrint "Found: SEARCH[$4]"
164          StrCpy $8 $7 $5 ;left part       ; $left = substr($line, $ptr)          StrCpy $8 $7 $5 ;left part       ; $left = substr($line, $ptr)
165          IntOp $6 $5 + $R3                ; $6 = position + strlen(search_for)          IntOp $6 $5 + $R3                ; $6 = position + strlen(search_for)
166          StrCpy $9 $7 "" $6 ;right part   ; $right = line          StrCpy $9 $7 "" $6 ;right part   ; $right = line
167    
168          StrLen $6 $7                     ; $6 = strlen(line)          StrLen $6 $7                     ; $6 = strlen(line)
169    
170          StrCpy $7 $8$3$9 ;re-join        ; $line = $left + $replace + $right          StrCpy $7 $8$3$9 ;re-join        ; $line = $left + $replace + $right
171          ;; DetailPrint "new = [$8][$3][$9] = [$7]"          ;; DetailPrint "new = [$8][$3][$9] = [$7]"
172    
173          ;; what's this test for?          ;; what's this test for?
174          StrCmp -$6 $5 0 loop_filter      ; if (strlen($line) == len(ptr)) then {continue } else { scan more? }          StrCmp -$6 $5 0 loop_filter      ; if (strlen($line) == len(ptr)) then {continue } else { scan more? }
175    
176          ;; replacement qualifier(s)          ;; replacement qualifier(s)
177          ;; start replacing after $2 occurrences          ;; start replacing after $2 occurrences
178          IntOp $R4 $R4 + 1                          IntOp $R4 $R4 + 1                
179          StrCmp $2 all file_write1          StrCmp $2 all file_write1
180          StrCmp $R4 $2 0 file_write2          StrCmp $R4 $2 0 file_write2
181          IntOp $R4 $R4 - 1          IntOp $R4 $R4 - 1
182    
183          ;; replacement qualifier(s)          ;; replacement qualifier(s)
184          ;; replace next $1 occurrences          ;; replace next $1 occurrences
185          IntOp $R5 $R5 + 1          IntOp $R5 $R5 + 1
186          StrCmp $1 all file_write1          StrCmp $1 all file_write1
187          StrCmp $R5 $1 0 file_write1          StrCmp $R5 $1 0 file_write1
188          IntOp $R5 $R5 - 1          IntOp $R5 $R5 - 1
189      Goto file_write2      Goto file_write2
190    
191      file_write1:      file_write1:
192          ;; Note that this wont do the right thing if you're trying to          ;; Note that this wont do the right thing if you're trying to
193          ;; null out a substring within a line.  If the replacement is          ;; null out a substring within a line.  If the replacement is
194          ;; null, we're assuming you want to null out the entire line.          ;; null, we're assuming you want to null out the entire line.
195          StrCmp $3 "" loop_read 0                          ;; bail if we're trying to delete a line                    StrCmp $3 "" loop_read 0                          ;; bail if we're trying to delete a line          
196          ;; DetailPrint "WRITING MODIFIED = [$7]"          ;; DetailPrint "WRITING MODIFIED = [$7]"
197          FileWrite $R0 $7 ;write modified line          FileWrite $R0 $7 ;write modified line
198      Goto loop_read      Goto loop_read
199    
200      file_write2:      file_write2:
201          ;; DetailPrint "WRITING UNMODIFIED = [$R2]"          ;; DetailPrint "WRITING UNMODIFIED = [$R2]"
202          FileWrite $R0 $R2 ;write unmodified line          FileWrite $R0 $R2 ;write unmodified line
203      Goto loop_read      Goto loop_read
204    
205      exit:      exit:
206          FileClose $R0          FileClose $R0
207          FileClose $R1          FileClose $R1
208    
209          SetDetailsPrint none          SetDetailsPrint none
210          Delete $0          Delete $0
211          Rename $R6 $0          Rename $R6 $0
212          Delete $R6          Delete $R6
213          SetDetailsPrint both          SetDetailsPrint both
214    
215      Pop $R6      Pop $R6
216      Pop $R5      Pop $R5
217      Pop $R4      Pop $R4
218      Pop $R3      Pop $R3
219      Pop $R2      Pop $R2
220      Pop $R1      Pop $R1
221      Pop $R0      Pop $R0
222      Pop $9      Pop $9
223      Pop $8      Pop $8
224      Pop $7      Pop $7
225      Pop $6      Pop $6
226      Pop $5      Pop $5
227      Pop $4      Pop $4
228      Pop $3      Pop $3
229      Pop $2      Pop $2
230      Pop $1      Pop $1
231      Pop $0      Pop $0
232  FunctionEnd  FunctionEnd

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed