2007-01-01 20:50:16 +01:00
|
|
|
/**
|
2007-02-12 10:00:55 +01:00
|
|
|
* vim: set ts=4 :
|
2007-08-15 08:19:30 +02:00
|
|
|
* =============================================================================
|
2007-01-26 03:07:24 +01:00
|
|
|
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
|
2007-08-15 08:19:30 +02:00
|
|
|
* =============================================================================
|
2007-01-26 03:07:24 +01:00
|
|
|
*
|
2007-08-15 08:19:30 +02:00
|
|
|
* This file is part of the SourceMod/SourcePawn SDK.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
2007-01-26 03:07:24 +01:00
|
|
|
*
|
|
|
|
* Version: $Id$
|
2007-01-01 20:50:16 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined _files_included
|
|
|
|
#endinput
|
|
|
|
#endif
|
|
|
|
#define _files_included
|
|
|
|
|
2007-03-15 21:44:23 +01:00
|
|
|
/* @global All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* File inode types.
|
|
|
|
*/
|
2007-01-01 20:50:16 +01:00
|
|
|
enum FileType
|
|
|
|
{
|
|
|
|
FileType_Unknown = 0, /* Unknown file type (device/socket) */
|
|
|
|
FileType_Directory = 1, /* File is a directory */
|
|
|
|
FileType_File = 2, /* File is a file */
|
|
|
|
};
|
|
|
|
|
2007-03-15 21:44:23 +01:00
|
|
|
#define PLATFORM_MAX_PATH 256 /**< Maximum path length. */
|
2007-01-01 20:50:16 +01:00
|
|
|
|
2007-03-15 21:44:23 +01:00
|
|
|
#define SEEK_SET 0 /**< Seek from start. */
|
|
|
|
#define SEEK_CUR 1 /**< Seek from current position. */
|
|
|
|
#define SEEK_END 2 /**< Seek from end position. */
|
2007-01-07 02:30:28 +01:00
|
|
|
|
2007-03-15 21:44:23 +01:00
|
|
|
/**
|
|
|
|
* Path types.
|
|
|
|
*/
|
2007-01-25 05:37:23 +01:00
|
|
|
enum PathType
|
|
|
|
{
|
2007-03-15 21:44:23 +01:00
|
|
|
Path_SM, /**< SourceMod root folder */
|
2007-01-25 05:37:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Builds a path relative to the SourceMod folder.
|
2007-01-25 05:37:23 +01:00
|
|
|
*
|
|
|
|
* @param type Type of path to build as the base.
|
|
|
|
* @param buffer Buffer to store the path.
|
|
|
|
* @param maxlength Maximum length of buffer.
|
|
|
|
* @param fmt Format string.
|
|
|
|
* @param ... Format arguments.
|
|
|
|
* @return Number of bytes written to buffer (not including null terminator).
|
|
|
|
*/
|
2007-03-16 21:39:32 +01:00
|
|
|
native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[], any:...);
|
2007-01-25 05:37:23 +01:00
|
|
|
|
2007-01-01 20:50:16 +01:00
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Opens a directory/folder for contents enumeration.
|
2007-01-01 20:50:16 +01:00
|
|
|
* @note Directories are closed with CloseHandle().
|
|
|
|
* @note Directories Handles can be cloned.
|
|
|
|
*
|
|
|
|
* @param path Path to open.
|
2007-01-25 05:37:23 +01:00
|
|
|
* @return A Handle to the directory, INVALID_HANDLE on open error.
|
2007-01-01 20:50:16 +01:00
|
|
|
*/
|
|
|
|
native Handle:OpenDirectory(const String:path[]);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Reads the current directory entry as a local filename, then moves to the next file.
|
2007-01-01 20:50:16 +01:00
|
|
|
* @note Contents of buffers are undefined when returning false.
|
|
|
|
* @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux.
|
|
|
|
*
|
|
|
|
* @param dir Handle to a directory.
|
|
|
|
* @param buffer String buffer to hold directory name.
|
|
|
|
* @param maxlength Maximum size of string buffer.
|
|
|
|
* @param type Optional variable to store the file type.
|
2007-01-25 05:37:23 +01:00
|
|
|
* @return True on success, false if there are no more files to read.
|
2007-01-01 20:50:16 +01:00
|
|
|
* @error Invalid or corrupt Handle.
|
|
|
|
*/
|
2007-01-01 22:46:33 +01:00
|
|
|
native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown);
|
2007-01-07 02:30:28 +01:00
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Opens a file.
|
2007-01-07 02:30:28 +01:00
|
|
|
* @note Files are closed with CloseHandle().
|
|
|
|
* @note File Handles can be cloned.
|
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param file File to open.
|
|
|
|
* @param mode Open mode.
|
|
|
|
* @return A Handle to the file, INVALID_HANDLE on open error.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native Handle:OpenFile(const String:file[], const String:mode[]);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Deletes a file.
|
2007-01-07 02:30:28 +01:00
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param path Path of the file to delete.
|
|
|
|
* @return True on success, false otherwise.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native bool:DeleteFile(const String:path[]);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Reads a line from a text file.
|
2007-01-07 02:30:28 +01:00
|
|
|
*
|
|
|
|
* @param hndl Handle to the file.
|
|
|
|
* @param buffer String buffer to hold the line.
|
|
|
|
* @param maxlength Maximum size of string buffer.
|
2007-01-25 05:37:23 +01:00
|
|
|
* @return True on success, false otherwise.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Tests if the end of file has been reached.
|
2007-01-07 02:30:28 +01:00
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param file Handle to the file.
|
|
|
|
* @return True if end of file has been reached, false otherwise.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native bool:IsEndOfFile(Handle:file);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Sets the file position indicator.
|
2007-01-07 02:30:28 +01:00
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param file Handle to the file.
|
|
|
|
* @param position Position relative to what is specified in whence.
|
|
|
|
* @param whence Look at the SEEK_* definitions.
|
|
|
|
* @return True on success, false otherwise.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native bool:FileSeek(Handle:file, position, whence);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Get current position in the file.
|
2007-01-07 02:30:28 +01:00
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param file Handle to the file.
|
|
|
|
* @return Value for the file position indicator.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native FilePosition(Handle:file);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Checks if a file exists.
|
2007-01-07 02:30:28 +01:00
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param path Path to the file.
|
|
|
|
* @return True if the file exists, false otherwise.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native bool:FileExists(const String:path[]);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Renames a file.
|
2007-01-07 02:30:28 +01:00
|
|
|
*
|
|
|
|
* @param newpath New path to the file.
|
|
|
|
* @param oldpath Path to the existing file.
|
2007-01-25 05:37:23 +01:00
|
|
|
* @return True on success, false otherwise.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native bool:RenameFile(const String:newpath[], const String:oldpath[]);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Checks if a directory exists.
|
2007-01-07 02:30:28 +01:00
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param path Path to the directory.
|
|
|
|
* @return True if the directory exists, false otherwise.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native bool:DirExists(const String:path[]);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Get the file size in bytes.
|
2007-01-07 02:30:28 +01:00
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param path Path to the file.
|
|
|
|
* @return File size in bytes, -1 if file not found.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native FileSize(const String:path[]);
|
|
|
|
|
2007-05-21 03:28:38 +02:00
|
|
|
/**
|
|
|
|
* Flushes a file's buffered output; any buffered output
|
|
|
|
* is immediately written to the file.
|
|
|
|
*
|
|
|
|
* @param file Handle to the file.
|
|
|
|
* @return True on success, false on failure.
|
|
|
|
*/
|
|
|
|
native FlushFile(Handle:file);
|
|
|
|
|
2007-01-07 02:30:28 +01:00
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Removes a directory.
|
2007-01-07 02:30:28 +01:00
|
|
|
* @note On most Operating Systems you cannot remove a directory which has files inside it.
|
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param path Path to the directory.
|
|
|
|
* @return True on success, false otherwise.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
|
|
|
native bool:RemoveDir(const String:path[]);
|
|
|
|
|
|
|
|
/**
|
2007-05-18 20:00:35 +02:00
|
|
|
* Writes a line of text in a file.
|
2007-01-07 02:30:28 +01:00
|
|
|
* @note This native will append the newline character.
|
|
|
|
*
|
2007-02-12 10:00:55 +01:00
|
|
|
* @param hndl Handle to the file.
|
|
|
|
* @param format Formatting rules.
|
|
|
|
* @param ... Variable number of format parameters.
|
|
|
|
* @return True on success, false otherwise.
|
2007-01-07 02:30:28 +01:00
|
|
|
*/
|
2007-03-16 21:39:32 +01:00
|
|
|
native bool:WriteFileLine(Handle:hndl, const String:format[], any:...);
|