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