Debian Codegraph @

Docs/src/file.but

raw
1 \S1{fileinst} File Instructions
2
3 \S2{FileClose} FileClose
4
5 \c handle
6
7 Closes a file handle opened with \R{FileOpen}{FileOpen}.
8
9 \S2{FileOpen} FileOpen
10
11 \c user_var(handle output) filename openmode
12
13 Opens a file named "filename" and sets the handle output variable with the handle. The openmode should be one of "r" (read) "w" (write, all contents of file are destroyed) or "a" (append, meaning opened for both read and write, contents preserved). In all open modes, the file pointer is placed at the beginning of the file. If the file cannot be opened the handle output is set to empty and the error flag is set.
14
15 If no absolute path is specified the current folder will be used. The current folder is the folder set using the last \R{setoutpath}{SetOutPath} instruction. If you have not used \R{setoutpath}{SetOutPath} the current folder is \R{varother}{$EXEDIR}.
16
17 \c FileOpen $0 $INSTDIR\file.dat r
18 \c FileClose $0
19
20 \S2{FileRead} FileRead
21
22 \c handle user_var(output) [maxlen]
23
24 Reads a string (ANSI characters) from a file opened with \R{FileOpen}{FileOpen}. The string is read until either a newline (or carriage return newline pair) occurs, or until a null byte is read, or until maxlen is met (if specified). By default, strings are limited to 1024 characters (a special build with larger NSIS_MAX_STRLEN can be compiled or downloaded). If the end of file is reached and no more data is available, the output string will be empty and the error flag will be set.
25
26 \NsisWarnBlockContainerBegin
27 \NsisBlockHeaderExeheadU
28 \#{This is a bug in exehead but it is probably a good idea to document it here...}
29 DBCS text is supported but conversion output is limited to UCS-2/BMP, surrogate pairs are not supported. The \NsisACPcp is used during the conversion.
30 \NsisWarnBlockContainerEnd
31
32
33 \c ClearErrors
34 \c FileOpen $0 $INSTDIR\file.dat r
35 \c IfErrors done
36 \c FileRead $0 $1
37 \c DetailPrint $1
38 \c FileClose $0
39 \c done:
40
41 \S2{FileReadUTF16LE} FileReadUTF16LE
42
43 \c handle user_var(output) [maxlen]
44
45 \NsisFuncReqU
46
47 Reads a string (UTF-16LE characters) from a file opened with \R{FileOpen}{FileOpen}. The string is read until either a newline (or carriage return newline pair) occurs, or until a null wide-character is read, or until maxlen is met (if specified). By default, strings are limited to 1024 characters (a special build with larger NSIS_MAX_STRLEN can be compiled or downloaded). If the end of file is reached and no more data is available, the output string will be empty and the error flag will be set. If present, the BOM at the start of the file is skipped.
48
49 \c ClearErrors
50 \c FileOpen $0 $INSTDIR\file.dat r
51 \c IfErrors done
52 \c FileReadUTF16LE $0 $1
53 \c DetailPrint $1
54 \c FileClose $0
55 \c done:
56
57 \S2{FileReadByte} FileReadByte
58
59 \c handle user_var(output)
60
61 Reads a byte from a file opened with \R{FileOpen}{FileOpen}. The byte is stored in the output as an integer (0-255). If the end of file is reached and no more data is available, the output will be empty and the error flag will be set.
62
63 \c ClearErrors
64 \c FileOpen $0 $INSTDIR\file.dat r
65 \c IfErrors done
66 \c FileReadByte $0 $1
67 \c FileReadByte $0 $2
68 \c DetailPrint "$1 $2"
69 \c FileClose $0
70 \c done:
71
72 \S2{FileReadWord} FileReadWord
73
74 \c handle user_var(output)
75
76 \NsisFuncReqU
77
78 Reads a word (2-bytes) from a file opened with \R{FileOpen}{FileOpen}. The word is stored in the output as an integer (0-65535). If the end of file is reached and no more data is available, the output will be empty and the error flag will be set.
79
80 \c ClearErrors
81 \c FileOpen $0 $INSTDIR\file.dat r
82 \c IfErrors done
83 \c FileReadWord $0 $1
84 \c FileReadWord $0 $2
85 \c DetailPrint "$1 $2"
86 \c FileClose $0
87 \c done:
88
89 \S2{FileSeek} FileSeek
90
91 \c handle offset [mode] [user_var(new position)]
92
93 Seeks a file opened with \R{FileOpen}{FileOpen}. If mode is omitted or specified as SET, the file is positioned to "offset", relative to the beginning of the file. If mode is specified as CUR, then the file is positioned to "offset", relative to the current file position. If mode is specified as END, then the file is positioned to "offset", relative to the end of the file. If the final parameter "new position" is specified, the new file position will be stored in that variable.
94
95 \c ClearErrors
96 \c FileOpen $0 $INSTDIR\file.dat r
97 \c IfErrors done
98 \c FileSeek $0 -5 END
99 \c FileRead $0 $1
100 \c DetailPrint $1
101 \c FileClose $0
102 \c done:
103
104 \S2{FileWrite} FileWrite
105
106 \c handle string
107
108 Writes an ANSI string to a file opened with \R{FileOpen}{FileOpen}. If an error occurs writing, the error flag will be set.
109
110 (If you are building a \R{intro-unicode}{Unicode installer}, the function converts the string to ANSI/MBCS. The \NsisACPcp is used during the conversion)
111
112 \c ClearErrors
113 \c FileOpen $0 $INSTDIR\file.dat w
114 \c IfErrors done
115 \c FileWrite $0 "some text"
116 \c FileClose $0
117 \c done:
118
119 \S2{FileWriteUTF16LE} FileWriteUTF16LE
120
121 \c [/BOM] handle string
122
123 \NsisFuncReqU
124
125 Writes a Unicode (UTF-16LE) string to a file opened with \R{FileOpen}{FileOpen}. If an error occurs, the error flag will be set. A BOM can be added to empty files with /BOM.
126
127 \c ClearErrors
128 \c FileOpen $0 $INSTDIR\file.dat w
129 \c IfErrors done
130 \c FileWriteUTF16LE $0 "some text"
131 \c FileClose $0
132 \c done:
133
134 \S2{FileWriteByte} FileWriteByte
135
136 \c handle string
137
138 Writes the integer interpretation of 'string' to a file opened with \R{FileOpen}{FileOpen}. The error flag is set if an error occurs while writing. The following code writes a "Carriage Return / Line Feed" pair to the file.
139
140 \c FileWriteByte file_handle "13"
141 \c FileWriteByte file_handle "10"
142
143 Note that only the low byte of the integer is used, i.e. writing 256 is the same as writing 0, etc.
144
145 \S2{FileWriteWord} FileWriteWord
146
147 \c handle string
148
149 \NsisFuncReqU
150
151 Writes the integer interpretation of 'string' as a WORD (2-bytes, range: 0-65535) to a file opened with \R{FileOpen}{FileOpen}. The error flag is set if an error occurs while writing. The following code writes a "Carriage Return / Line Feed" pair to the file.
152
153 \c FileWriteWord file_handle "13"
154 \c FileWriteWord file_handle "10"
155
156 Note that only the low WORD of the integer is used, i.e. writing 65536 is the same as writing 0, etc.
157
158 \S2{FindClose} FindClose
159
160 \c handle
161
162 Closes a search opened with \R{FindFirst}{FindFirst}.
163
164 \S2{FindFirst} FindFirst
165
166 \c user_var(handle output) user_var(filename output) filespec
167
168 Performs a search for 'filespec', placing the first file found in filename_output (a user variable). It also puts the handle of the search into handle_output (also a user variable). If no files are found, both outputs are set to empty and the error flag is set. \R{FindClose}{FindClose} must be used to close the handle. Note that the filename output is without path.
169
170 \c FindFirst $0 $1 $INSTDIR\*.txt
171 \c loop:
172 \c StrCmp $1 "" done
173 \c DetailPrint $1
174 \c FindNext $0 $1
175 \c Goto loop
176 \c done:
177 \c FindClose $0
178
179 \S2{FindNext} FindNext
180
181 \c handle user_var(filename_output)
182
183 Continues a search began with \R{FindFirst}{FindFirst}. handle should be the handle_output_variable returned by \R{FindFirst}{FindFirst}. If the search is completed (there are no more files), filename_output is set to empty and the error flag is set. Note that the filename output is without path.