dvander@252: /** dvander@374: * =============================================================== dvander@374: * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. dvander@374: * =============================================================== dvander@374: * dvander@374: * This file is part of the SourceMod/SourcePawn SDK. This file may only be used dvander@374: * or modified under the Terms and Conditions of its License Agreement, which is found dvander@374: * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins dvander@374: * may change at any time. To view the latest information, see: dvander@374: * http://www.sourcemod.net/license.php dvander@374: * dvander@374: * Version: $Id$ dvander@252: */ dvander@252: dvander@252: #if defined _files_included dvander@252: #endinput dvander@252: #endif dvander@252: #define _files_included dvander@252: dvander@252: /* @note All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */ dvander@252: dvander@252: enum FileType dvander@252: { dvander@252: FileType_Unknown = 0, /* Unknown file type (device/socket) */ dvander@252: FileType_Directory = 1, /* File is a directory */ dvander@252: FileType_File = 2, /* File is a file */ dvander@252: }; dvander@252: dvander@257: #define PLATFORM_MAX_PATH 256 dvander@252: faluco@274: #define SEEK_SET 0 faluco@274: #define SEEK_CUR 1 faluco@274: #define SEEK_END 2 faluco@274: dvander@345: enum PathType dvander@345: { dvander@345: Path_SM, /* SourceMod root folder */ dvander@345: }; dvander@345: dvander@345: /** dvander@345: * @brief Builds a path relative to the SourceMod folder. dvander@345: * dvander@345: * @param type Type of path to build as the base. dvander@345: * @param buffer Buffer to store the path. dvander@345: * @param maxlength Maximum length of buffer. dvander@345: * @param fmt Format string. dvander@345: * @param ... Format arguments. dvander@345: * @return Number of bytes written to buffer (not including null terminator). dvander@345: */ dvander@345: native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[], ...); dvander@345: dvander@252: /** dvander@252: * @brief Opens a directory/folder for contents enumeration. dvander@252: * @note Directories are closed with CloseHandle(). dvander@252: * @note Directories Handles can be cloned. dvander@252: * dvander@252: * @param path Path to open. dvander@345: * @return A Handle to the directory, INVALID_HANDLE on open error. dvander@252: */ dvander@252: native Handle:OpenDirectory(const String:path[]); dvander@252: dvander@252: /** dvander@252: * @brief Reads the current directory entry as a local filename, then moves to the next file. dvander@252: * @note Contents of buffers are undefined when returning false. dvander@252: * @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux. dvander@252: * dvander@252: * @param dir Handle to a directory. dvander@252: * @param buffer String buffer to hold directory name. dvander@252: * @param maxlength Maximum size of string buffer. dvander@252: * @param type Optional variable to store the file type. dvander@345: * @return True on success, false if there are no more files to read. dvander@252: * @error Invalid or corrupt Handle. dvander@252: */ dvander@257: native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown); faluco@274: faluco@274: /** faluco@274: * @brief Opens a file. faluco@274: * @note Files are closed with CloseHandle(). faluco@274: * @note File Handles can be cloned. faluco@274: * dvander@345: * @param file File to open. dvander@345: * @param mode Open mode. faluco@274: * @return A Handle to the file, INVALID_HANDLE on open error. faluco@274: */ faluco@274: native Handle:OpenFile(const String:file[], const String:mode[]); faluco@274: faluco@274: /** faluco@274: * @brief Deletes a file. faluco@274: * dvander@345: * @param path Path of the file to delete. faluco@274: * @return True on success, false otherwise. faluco@274: */ faluco@274: native bool:DeleteFile(const String:path[]); faluco@274: faluco@274: /** faluco@274: * @brief Reads a line from a text file. faluco@274: * faluco@274: * @param hndl Handle to the file. faluco@274: * @param buffer String buffer to hold the line. faluco@274: * @param maxlength Maximum size of string buffer. dvander@345: * @return True on success, false otherwise. faluco@274: */ faluco@274: native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength); faluco@274: faluco@274: /** faluco@274: * @brief Tests if the end of file has been reached. faluco@274: * dvander@345: * @param file Handle to the file. faluco@274: * @return True if end of file has been reached, false otherwise. faluco@274: */ faluco@274: native bool:IsEndOfFile(Handle:file); faluco@274: faluco@274: /** faluco@274: * @brief Sets the file position indicator. faluco@274: * dvander@345: * @param file Handle to the file. dvander@345: * @param position Position relative to what is specified in whence. dvander@345: * @param whence Look at the SEEK_* definitions. faluco@274: * @return True on success, false otherwise. faluco@274: */ faluco@274: native bool:FileSeek(Handle:file, position, whence); faluco@274: faluco@274: /** faluco@274: * @brief Get current position in the file. faluco@274: * dvander@345: * @param file Handle to the file. faluco@274: * @return Value for the file position indicator. faluco@274: */ faluco@274: native FilePosition(Handle:file); faluco@274: faluco@274: /** faluco@274: * @brief Checks if a file exists. faluco@274: * dvander@345: * @param path Path to the file. faluco@274: * @return True if the file exists, false otherwise. faluco@274: */ faluco@274: native bool:FileExists(const String:path[]); faluco@274: faluco@274: /** faluco@274: * @brief Renames a file. faluco@274: * faluco@274: * @param newpath New path to the file. faluco@274: * @param oldpath Path to the existing file. dvander@345: * @return True on success, false otherwise. faluco@274: */ faluco@274: native bool:RenameFile(const String:newpath[], const String:oldpath[]); faluco@274: faluco@274: /** faluco@274: * @brief Checks if a directory exists. faluco@274: * dvander@345: * @param path Path to the directory. faluco@274: * @return True if the directory exists, false otherwise. faluco@274: */ faluco@274: native bool:DirExists(const String:path[]); faluco@274: faluco@274: /** faluco@274: * @brief Get the file size in bytes. faluco@274: * dvander@345: * @param path Path to the file. faluco@274: * @return File size in bytes, -1 if file not found. faluco@274: */ faluco@274: native FileSize(const String:path[]); faluco@274: faluco@274: /** faluco@274: * @brief Removes a directory. faluco@274: * @note On most Operating Systems you cannot remove a directory which has files inside it. faluco@274: * dvander@345: * @param path Path to the directory. faluco@274: * @return True on success, false otherwise. faluco@274: */ faluco@274: native bool:RemoveDir(const String:path[]); faluco@274: faluco@274: /** faluco@274: * @brief Writes a line of text in a file. faluco@274: * @note This native will append the newline character. faluco@274: * dvander@345: * @param hndl Handle to the file. dvander@345: * @param format Formatting rules. dvander@345: * @param ... Variable number of format parameters. faluco@274: * @return True on success, false otherwise. faluco@274: */ faluco@275: native bool:WriteFileLine(Handle:hndl, const String:format[], {Handle,Float,String,_}:...);