|
dvander@252
|
1 |
/** |
|
ds@475
|
2 |
* vim: set ts=4 : |
|
ds@1330
|
3 |
* ============================================================================= |
|
dvander@374
|
4 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
ds@1330
|
5 |
* ============================================================================= |
|
ds@1330
|
6 |
* |
|
ds@1330
|
7 |
* This file is part of the SourceMod/SourcePawn SDK. |
|
dvander@374
|
8 |
* |
|
ds@1330
|
9 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1330
|
10 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1330
|
11 |
* Free Software Foundation. |
|
ds@1330
|
12 |
* |
|
ds@1330
|
13 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1330
|
14 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1330
|
15 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1330
|
16 |
* details. |
|
ds@1330
|
17 |
* |
|
ds@1330
|
18 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1330
|
19 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ds@1330
|
20 |
* |
|
ds@1330
|
21 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1330
|
22 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1330
|
23 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1330
|
24 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1330
|
25 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1330
|
26 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1330
|
27 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1330
|
28 |
* or <http://www.sourcemod.net/license.php>. |
|
dvander@374
|
29 |
* |
|
dvander@374
|
30 |
* Version: $Id$ |
|
dvander@252
|
31 |
*/ |
|
dvander@252
|
32 |
|
|
dvander@252
|
33 |
#if defined _files_included |
|
dvander@252
|
34 |
#endinput |
|
dvander@252
|
35 |
#endif |
|
dvander@252
|
36 |
#define _files_included |
|
dvander@252
|
37 |
|
|
dvander@619
|
38 |
/* @global All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */ |
|
dvander@619
|
39 |
|
|
dvander@619
|
40 |
/** |
|
dvander@619
|
41 |
* File inode types. |
|
dvander@619
|
42 |
*/ |
|
dvander@252
|
43 |
enum FileType |
|
dvander@252
|
44 |
{ |
|
dvander@252
|
45 |
FileType_Unknown = 0, /* Unknown file type (device/socket) */ |
|
dvander@252
|
46 |
FileType_Directory = 1, /* File is a directory */ |
|
dvander@252
|
47 |
FileType_File = 2, /* File is a file */ |
|
dvander@252
|
48 |
}; |
|
dvander@252
|
49 |
|
|
dvander@1370
|
50 |
/** |
|
dvander@1370
|
51 |
* File time modes. |
|
dvander@1370
|
52 |
*/ |
|
dvander@1370
|
53 |
enum FileTimeMode |
|
dvander@1370
|
54 |
{ |
|
dvander@1370
|
55 |
FileTime_LastAccess = 0, /* Last access (does not work on FAT) */ |
|
dvander@1370
|
56 |
FileTime_Created = 1, /* Creation (does not work on FAT) */ |
|
dvander@1370
|
57 |
FileTime_LastChange = 2, /* Last modification */ |
|
dvander@1370
|
58 |
}; |
|
dvander@1370
|
59 |
|
|
dvander@619
|
60 |
#define PLATFORM_MAX_PATH 256 /**< Maximum path length. */ |
|
dvander@252
|
61 |
|
|
dvander@619
|
62 |
#define SEEK_SET 0 /**< Seek from start. */ |
|
dvander@619
|
63 |
#define SEEK_CUR 1 /**< Seek from current position. */ |
|
dvander@619
|
64 |
#define SEEK_END 2 /**< Seek from end position. */ |
|
faluco@274
|
65 |
|
|
dvander@619
|
66 |
/** |
|
dvander@619
|
67 |
* Path types. |
|
dvander@619
|
68 |
*/ |
|
dvander@345
|
69 |
enum PathType |
|
dvander@345
|
70 |
{ |
|
dvander@619
|
71 |
Path_SM, /**< SourceMod root folder */ |
|
dvander@345
|
72 |
}; |
|
dvander@345
|
73 |
|
|
dvander@345
|
74 |
/** |
|
dvander@812
|
75 |
* Builds a path relative to the SourceMod folder. |
|
dvander@345
|
76 |
* |
|
dvander@345
|
77 |
* @param type Type of path to build as the base. |
|
dvander@345
|
78 |
* @param buffer Buffer to store the path. |
|
dvander@345
|
79 |
* @param maxlength Maximum length of buffer. |
|
dvander@345
|
80 |
* @param fmt Format string. |
|
dvander@345
|
81 |
* @param ... Format arguments. |
|
dvander@345
|
82 |
* @return Number of bytes written to buffer (not including null terminator). |
|
dvander@345
|
83 |
*/ |
|
ds@634
|
84 |
native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[], any:...); |
|
dvander@345
|
85 |
|
|
dvander@252
|
86 |
/** |
|
dvander@812
|
87 |
* Opens a directory/folder for contents enumeration. |
|
dvander@252
|
88 |
* @note Directories are closed with CloseHandle(). |
|
dvander@252
|
89 |
* @note Directories Handles can be cloned. |
|
dvander@252
|
90 |
* |
|
dvander@252
|
91 |
* @param path Path to open. |
|
dvander@345
|
92 |
* @return A Handle to the directory, INVALID_HANDLE on open error. |
|
dvander@252
|
93 |
*/ |
|
dvander@252
|
94 |
native Handle:OpenDirectory(const String:path[]); |
|
dvander@252
|
95 |
|
|
dvander@252
|
96 |
/** |
|
dvander@812
|
97 |
* Reads the current directory entry as a local filename, then moves to the next file. |
|
dvander@252
|
98 |
* @note Contents of buffers are undefined when returning false. |
|
dvander@252
|
99 |
* @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux. |
|
dvander@252
|
100 |
* |
|
dvander@252
|
101 |
* @param dir Handle to a directory. |
|
dvander@252
|
102 |
* @param buffer String buffer to hold directory name. |
|
dvander@252
|
103 |
* @param maxlength Maximum size of string buffer. |
|
dvander@252
|
104 |
* @param type Optional variable to store the file type. |
|
dvander@345
|
105 |
* @return True on success, false if there are no more files to read. |
|
dvander@252
|
106 |
* @error Invalid or corrupt Handle. |
|
dvander@252
|
107 |
*/ |
|
dvander@257
|
108 |
native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown); |
|
faluco@274
|
109 |
|
|
faluco@274
|
110 |
/** |
|
dvander@812
|
111 |
* Opens a file. |
|
faluco@274
|
112 |
* @note Files are closed with CloseHandle(). |
|
faluco@274
|
113 |
* @note File Handles can be cloned. |
|
faluco@274
|
114 |
* |
|
ds@475
|
115 |
* @param file File to open. |
|
ds@475
|
116 |
* @param mode Open mode. |
|
ds@475
|
117 |
* @return A Handle to the file, INVALID_HANDLE on open error. |
|
faluco@274
|
118 |
*/ |
|
faluco@274
|
119 |
native Handle:OpenFile(const String:file[], const String:mode[]); |
|
faluco@274
|
120 |
|
|
faluco@274
|
121 |
/** |
|
dvander@812
|
122 |
* Deletes a file. |
|
faluco@274
|
123 |
* |
|
ds@475
|
124 |
* @param path Path of the file to delete. |
|
ds@475
|
125 |
* @return True on success, false otherwise. |
|
faluco@274
|
126 |
*/ |
|
faluco@274
|
127 |
native bool:DeleteFile(const String:path[]); |
|
faluco@274
|
128 |
|
|
faluco@274
|
129 |
/** |
|
dvander@812
|
130 |
* Reads a line from a text file. |
|
faluco@274
|
131 |
* |
|
faluco@274
|
132 |
* @param hndl Handle to the file. |
|
faluco@274
|
133 |
* @param buffer String buffer to hold the line. |
|
faluco@274
|
134 |
* @param maxlength Maximum size of string buffer. |
|
dvander@345
|
135 |
* @return True on success, false otherwise. |
|
faluco@274
|
136 |
*/ |
|
faluco@274
|
137 |
native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength); |
|
faluco@274
|
138 |
|
|
faluco@274
|
139 |
/** |
|
dvander@812
|
140 |
* Tests if the end of file has been reached. |
|
faluco@274
|
141 |
* |
|
ds@475
|
142 |
* @param file Handle to the file. |
|
ds@475
|
143 |
* @return True if end of file has been reached, false otherwise. |
|
faluco@274
|
144 |
*/ |
|
faluco@274
|
145 |
native bool:IsEndOfFile(Handle:file); |
|
faluco@274
|
146 |
|
|
faluco@274
|
147 |
/** |
|
dvander@812
|
148 |
* Sets the file position indicator. |
|
faluco@274
|
149 |
* |
|
ds@475
|
150 |
* @param file Handle to the file. |
|
ds@475
|
151 |
* @param position Position relative to what is specified in whence. |
|
ds@475
|
152 |
* @param whence Look at the SEEK_* definitions. |
|
ds@475
|
153 |
* @return True on success, false otherwise. |
|
faluco@274
|
154 |
*/ |
|
faluco@274
|
155 |
native bool:FileSeek(Handle:file, position, whence); |
|
faluco@274
|
156 |
|
|
faluco@274
|
157 |
/** |
|
dvander@812
|
158 |
* Get current position in the file. |
|
faluco@274
|
159 |
* |
|
ds@475
|
160 |
* @param file Handle to the file. |
|
ds@475
|
161 |
* @return Value for the file position indicator. |
|
faluco@274
|
162 |
*/ |
|
faluco@274
|
163 |
native FilePosition(Handle:file); |
|
faluco@274
|
164 |
|
|
faluco@274
|
165 |
/** |
|
dvander@812
|
166 |
* Checks if a file exists. |
|
faluco@274
|
167 |
* |
|
ds@475
|
168 |
* @param path Path to the file. |
|
ds@475
|
169 |
* @return True if the file exists, false otherwise. |
|
faluco@274
|
170 |
*/ |
|
faluco@274
|
171 |
native bool:FileExists(const String:path[]); |
|
faluco@274
|
172 |
|
|
faluco@274
|
173 |
/** |
|
dvander@812
|
174 |
* Renames a file. |
|
faluco@274
|
175 |
* |
|
faluco@274
|
176 |
* @param newpath New path to the file. |
|
faluco@274
|
177 |
* @param oldpath Path to the existing file. |
|
dvander@345
|
178 |
* @return True on success, false otherwise. |
|
faluco@274
|
179 |
*/ |
|
faluco@274
|
180 |
native bool:RenameFile(const String:newpath[], const String:oldpath[]); |
|
faluco@274
|
181 |
|
|
faluco@274
|
182 |
/** |
|
dvander@812
|
183 |
* Checks if a directory exists. |
|
faluco@274
|
184 |
* |
|
ds@475
|
185 |
* @param path Path to the directory. |
|
ds@475
|
186 |
* @return True if the directory exists, false otherwise. |
|
faluco@274
|
187 |
*/ |
|
faluco@274
|
188 |
native bool:DirExists(const String:path[]); |
|
faluco@274
|
189 |
|
|
faluco@274
|
190 |
/** |
|
dvander@812
|
191 |
* Get the file size in bytes. |
|
faluco@274
|
192 |
* |
|
ds@475
|
193 |
* @param path Path to the file. |
|
ds@475
|
194 |
* @return File size in bytes, -1 if file not found. |
|
faluco@274
|
195 |
*/ |
|
faluco@274
|
196 |
native FileSize(const String:path[]); |
|
faluco@274
|
197 |
|
|
faluco@274
|
198 |
/** |
|
dvander@821
|
199 |
* Flushes a file's buffered output; any buffered output |
|
dvander@821
|
200 |
* is immediately written to the file. |
|
dvander@821
|
201 |
* |
|
dvander@821
|
202 |
* @param file Handle to the file. |
|
dvander@821
|
203 |
* @return True on success, false on failure. |
|
dvander@821
|
204 |
*/ |
|
dvander@821
|
205 |
native FlushFile(Handle:file); |
|
dvander@821
|
206 |
|
|
dvander@821
|
207 |
/** |
|
dvander@812
|
208 |
* Removes a directory. |
|
faluco@274
|
209 |
* @note On most Operating Systems you cannot remove a directory which has files inside it. |
|
faluco@274
|
210 |
* |
|
ds@475
|
211 |
* @param path Path to the directory. |
|
ds@475
|
212 |
* @return True on success, false otherwise. |
|
faluco@274
|
213 |
*/ |
|
faluco@274
|
214 |
native bool:RemoveDir(const String:path[]); |
|
faluco@274
|
215 |
|
|
faluco@274
|
216 |
/** |
|
dvander@812
|
217 |
* Writes a line of text in a file. |
|
faluco@274
|
218 |
* @note This native will append the newline character. |
|
faluco@274
|
219 |
* |
|
ds@475
|
220 |
* @param hndl Handle to the file. |
|
ds@475
|
221 |
* @param format Formatting rules. |
|
ds@475
|
222 |
* @param ... Variable number of format parameters. |
|
ds@475
|
223 |
* @return True on success, false otherwise. |
|
faluco@274
|
224 |
*/ |
|
ds@634
|
225 |
native bool:WriteFileLine(Handle:hndl, const String:format[], any:...); |
|
dvander@1370
|
226 |
|
|
dvander@1370
|
227 |
/** |
|
dvander@1370
|
228 |
* Returns a file timestamp as a unix timestamp. |
|
dvander@1370
|
229 |
* |
|
dvander@1370
|
230 |
* @param file File name. |
|
dvander@1370
|
231 |
* @param tmode Time mode. |
|
dvander@1370
|
232 |
* @return Time value, or -1 on failure. |
|
dvander@1370
|
233 |
*/ |
|
dvander@1370
|
234 |
native GetFileTime(const String:file[], FileTimeMode:tmode); |
|
dvander@1378
|
235 |
|
|
dvander@1378
|
236 |
/** |
|
dvander@1378
|
237 |
* Same as LogToFile(), except uses an open file Handle. The file must |
|
dvander@1378
|
238 |
* be opened in text appending mode. |
|
dvander@1378
|
239 |
* |
|
dvander@1378
|
240 |
* @param hndl Handle to the file. |
|
dvander@1378
|
241 |
* @param message Message format. |
|
dvander@1378
|
242 |
* @param ... Message format parameters. |
|
dvander@1378
|
243 |
* @noreturn |
|
dvander@1378
|
244 |
* @error Invalid Handle. |
|
dvander@1378
|
245 |
*/ |
|
dvander@1378
|
246 |
native LogToOpenFile(Handle:hndl, const String:message[], any:...); |
|
dvander@1378
|
247 |
|
|
dvander@1378
|
248 |
/** |
|
dvander@1378
|
249 |
* Same as LogToFileEx(), except uses an open file Handle. The file must |
|
dvander@1378
|
250 |
* be opened in text appending mode. |
|
dvander@1378
|
251 |
* |
|
dvander@1378
|
252 |
* @param hndl Handle to the file. |
|
dvander@1378
|
253 |
* @param message Message format. |
|
dvander@1378
|
254 |
* @param ... Message format parameters. |
|
dvander@1378
|
255 |
* @noreturn |
|
dvander@1378
|
256 |
* @error Invalid Handle. |
|
dvander@1378
|
257 |
*/ |
|
dvander@1378
|
258 |
native LogToOpenFileEx(Handle:hndl, const String:message[], any:...); |
|
dvander@1378
|
259 |
|