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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Tue Nov 22 14:28:15 2005 UTC (19 years ago) by janosch
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +232 -232 lines
*** empty log message ***

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

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