plugins/include/files.inc
author David Anderson <dvander@alliedmods.net>
Tue Aug 14 01:00:42 2007 +0000 (2007-08-14)
changeset 1324 9d1983bf06c7
parent 821 c5b4dca7f8ac
child 1330 ab94316bb52b
permissions -rw-r--r--
added SQL_CheckConfig() so sql admin plugins can default back
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     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
    12  *
    13  * Version: $Id$
    14  */
    15 
    16 #if defined _files_included
    17  #endinput
    18 #endif
    19 #define _files_included
    20 
    21 /* @global All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */
    22 
    23 /**
    24  * File inode types.
    25  */
    26 enum FileType
    27 {
    28 	FileType_Unknown = 0,	/* Unknown file type (device/socket) */
    29 	FileType_Directory = 1,	/* File is a directory */
    30 	FileType_File = 2,		/* File is a file */
    31 };
    32 
    33 #define PLATFORM_MAX_PATH		256		/**< Maximum path length. */
    34 
    35 #define SEEK_SET 0						/**< Seek from start. */
    36 #define SEEK_CUR 1						/**< Seek from current position. */
    37 #define SEEK_END 2						/**< Seek from end position. */
    38 
    39 /**
    40  * Path types.
    41  */
    42 enum PathType
    43 {
    44 	Path_SM,		/**< SourceMod root folder */	
    45 };
    46 
    47 /**
    48  * Builds a path relative to the SourceMod folder.
    49  *
    50  * @param type			Type of path to build as the base.
    51  * @param buffer		Buffer to store the path.
    52  * @param maxlength		Maximum length of buffer.
    53  * @param fmt			Format string.
    54  * @param ...			Format arguments.
    55  * @return				Number of bytes written to buffer (not including null terminator).
    56  */
    57 native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[], any:...);
    58 
    59 /**
    60  * Opens a directory/folder for contents enumeration.
    61  * @note Directories are closed with CloseHandle().
    62  * @note Directories Handles can be cloned.
    63  *
    64  * @param path			Path to open.
    65  * @return				A Handle to the directory, INVALID_HANDLE on open error.
    66  */
    67 native Handle:OpenDirectory(const String:path[]);
    68 
    69 /**
    70  * Reads the current directory entry as a local filename, then moves to the next file.
    71  * @note Contents of buffers are undefined when returning false.
    72  * @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux.
    73  * 
    74  * @param dir			Handle to a directory.
    75  * @param buffer		String buffer to hold directory name.
    76  * @param maxlength		Maximum size of string buffer.
    77  * @param type			Optional variable to store the file type.
    78  * @return				True on success, false if there are no more files to read.
    79  * @error				Invalid or corrupt Handle. 
    80  */
    81 native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown);
    82 
    83 /**
    84  * Opens a file.
    85  * @note Files are closed with CloseHandle().
    86  * @note File Handles can be cloned.
    87  *
    88  * @param file			File to open.
    89  * @param mode			Open mode.
    90  * @return				A Handle to the file, INVALID_HANDLE on open error.
    91  */
    92 native Handle:OpenFile(const String:file[], const String:mode[]);
    93 
    94 /**
    95  * Deletes a file.
    96  *
    97  * @param path			Path of the file to delete.
    98  * @return				True on success, false otherwise.
    99  */
   100 native bool:DeleteFile(const String:path[]);
   101 
   102 /**
   103  * Reads a line from a text file.
   104  *
   105  * @param hndl			Handle to the file.
   106  * @param buffer		String buffer to hold the line.
   107  * @param maxlength		Maximum size of string buffer.	
   108  * @return				True on success, false otherwise.
   109  */
   110 native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
   111 
   112 /**
   113  * Tests if the end of file has been reached.
   114  *
   115  * @param file			Handle to the file.
   116  * @return				True if end of file has been reached, false otherwise.
   117  */
   118 native bool:IsEndOfFile(Handle:file);
   119 
   120 /**
   121  * Sets the file position indicator.
   122  *
   123  * @param file			Handle to the file.
   124  * @param position		Position relative to what is specified in whence.
   125  * @param whence		Look at the SEEK_* definitions.
   126  * @return				True on success, false otherwise.
   127  */
   128 native bool:FileSeek(Handle:file, position, whence);
   129 
   130 /**
   131  * Get current position in the file.
   132  *
   133  * @param file			Handle to the file.
   134  * @return				Value for the file position indicator.
   135  */
   136 native FilePosition(Handle:file);
   137 
   138 /**
   139  * Checks if a file exists.
   140  *
   141  * @param path			Path to the file.
   142  * @return				True if the file exists, false otherwise.
   143  */
   144 native bool:FileExists(const String:path[]);
   145 
   146 /**
   147  * Renames a file.
   148  *
   149  * @param newpath		New path to the file.
   150  * @param oldpath		Path to the existing file.
   151  * @return				True on success, false otherwise.
   152  */
   153 native bool:RenameFile(const String:newpath[], const String:oldpath[]);
   154 
   155 /**
   156  * Checks if a directory exists.
   157  *
   158  * @param path			Path to the directory.
   159  * @return				True if the directory exists, false otherwise.
   160  */
   161 native bool:DirExists(const String:path[]);
   162 
   163 /**
   164  * Get the file size in bytes.
   165  *
   166  * @param path			Path to the file.
   167  * @return				File size in bytes, -1 if file not found.
   168  */
   169 native FileSize(const String:path[]);
   170 
   171 /**
   172  * Flushes a file's buffered output; any buffered output
   173  * is immediately written to the file.
   174  *
   175  * @param file			Handle to the file.
   176  * @return				True on success, false on failure.
   177  */
   178 native FlushFile(Handle:file);
   179 
   180 /**
   181  * Removes a directory.
   182  * @note On most Operating Systems you cannot remove a directory which has files inside it.
   183  *
   184  * @param path			Path to the directory.
   185  * @return				True on success, false otherwise.
   186  */
   187 native bool:RemoveDir(const String:path[]);
   188 
   189 /**
   190  * Writes a line of text in a file.
   191  * @note This native will append the newline character.
   192  *
   193  * @param hndl			Handle to the file.
   194  * @param format		Formatting rules.
   195  * @param ...			Variable number of format parameters.
   196  * @return				True on success, false otherwise.
   197  */
   198 native bool:WriteFileLine(Handle:hndl, const String:format[], any:...);