Fixed tabs, hopefully...
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is part of the SourceMod/SourcePawn SDK. This file may only be used
8 * or modified under the Terms and Conditions of its License Agreement, which is found
9 * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins
10 * may change at any time. To view the latest information, see:
11 * http://www.sourcemod.net/license.php
16 #if defined _files_included
19 #define _files_included
21 /* @note All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */
25 FileType_Unknown = 0, /* Unknown file type (device/socket) */
26 FileType_Directory = 1, /* File is a directory */
27 FileType_File = 2, /* File is a file */
30 #define PLATFORM_MAX_PATH 256
38 Path_SM, /* SourceMod root folder */
42 * @brief Builds a path relative to the SourceMod folder.
44 * @param type Type of path to build as the base.
45 * @param buffer Buffer to store the path.
46 * @param maxlength Maximum length of buffer.
47 * @param fmt Format string.
48 * @param ... Format arguments.
49 * @return Number of bytes written to buffer (not including null terminator).
51 native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[], ...);
54 * @brief Opens a directory/folder for contents enumeration.
55 * @note Directories are closed with CloseHandle().
56 * @note Directories Handles can be cloned.
58 * @param path Path to open.
59 * @return A Handle to the directory, INVALID_HANDLE on open error.
61 native Handle:OpenDirectory(const String:path[]);
64 * @brief Reads the current directory entry as a local filename, then moves to the next file.
65 * @note Contents of buffers are undefined when returning false.
66 * @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux.
68 * @param dir Handle to a directory.
69 * @param buffer String buffer to hold directory name.
70 * @param maxlength Maximum size of string buffer.
71 * @param type Optional variable to store the file type.
72 * @return True on success, false if there are no more files to read.
73 * @error Invalid or corrupt Handle.
75 native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown);
78 * @brief Opens a file.
79 * @note Files are closed with CloseHandle().
80 * @note File Handles can be cloned.
82 * @param file File to open.
83 * @param mode Open mode.
84 * @return A Handle to the file, INVALID_HANDLE on open error.
86 native Handle:OpenFile(const String:file[], const String:mode[]);
89 * @brief Deletes a file.
91 * @param path Path of the file to delete.
92 * @return True on success, false otherwise.
94 native bool:DeleteFile(const String:path[]);
97 * @brief Reads a line from a text file.
99 * @param hndl Handle to the file.
100 * @param buffer String buffer to hold the line.
101 * @param maxlength Maximum size of string buffer.
102 * @return True on success, false otherwise.
104 native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
107 * @brief Tests if the end of file has been reached.
109 * @param file Handle to the file.
110 * @return True if end of file has been reached, false otherwise.
112 native bool:IsEndOfFile(Handle:file);
115 * @brief Sets the file position indicator.
117 * @param file Handle to the file.
118 * @param position Position relative to what is specified in whence.
119 * @param whence Look at the SEEK_* definitions.
120 * @return True on success, false otherwise.
122 native bool:FileSeek(Handle:file, position, whence);
125 * @brief Get current position in the file.
127 * @param file Handle to the file.
128 * @return Value for the file position indicator.
130 native FilePosition(Handle:file);
133 * @brief Checks if a file exists.
135 * @param path Path to the file.
136 * @return True if the file exists, false otherwise.
138 native bool:FileExists(const String:path[]);
141 * @brief Renames a file.
143 * @param newpath New path to the file.
144 * @param oldpath Path to the existing file.
145 * @return True on success, false otherwise.
147 native bool:RenameFile(const String:newpath[], const String:oldpath[]);
150 * @brief Checks if a directory exists.
152 * @param path Path to the directory.
153 * @return True if the directory exists, false otherwise.
155 native bool:DirExists(const String:path[]);
158 * @brief Get the file size in bytes.
160 * @param path Path to the file.
161 * @return File size in bytes, -1 if file not found.
163 native FileSize(const String:path[]);
166 * @brief Removes a directory.
167 * @note On most Operating Systems you cannot remove a directory which has files inside it.
169 * @param path Path to the directory.
170 * @return True on success, false otherwise.
172 native bool:RemoveDir(const String:path[]);
175 * @brief Writes a line of text in a file.
176 * @note This native will append the newline character.
178 * @param hndl Handle to the file.
179 * @param format Formatting rules.
180 * @param ... Variable number of format parameters.
181 * @return True on success, false otherwise.
183 native bool:WriteFileLine(Handle:hndl, const String:format[], {Handle,Float,String,_}:...);