plugins/include/files.inc
author Borja Ferrer <faluco@alliedmods.net>
Sun Jan 07 01:32:08 2007 +0000 (2007-01-07)
changeset 275 81670bcf543e
parent 274 959c85596341
child 345 df0b05b4f50d
permissions -rw-r--r--
i have a hat
     1 /**
     2  * :TODO: license info
     3  */
     4 
     5 #if defined _files_included
     6  #endinput
     7 #endif
     8 #define _files_included
     9 
    10 /* @note All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */
    11  
    12 enum FileType
    13 {
    14 	FileType_Unknown = 0,	/* Unknown file type (device/socket) */
    15 	FileType_Directory = 1,	/* File is a directory */
    16 	FileType_File = 2,		/* File is a file */
    17 };
    18 
    19 #define PLATFORM_MAX_PATH		256
    20 
    21 #define SEEK_SET 0
    22 #define SEEK_CUR 1
    23 #define SEEK_END 2
    24 
    25 /**
    26  * @brief Opens a directory/folder for contents enumeration.
    27  * @note Directories are closed with CloseHandle().
    28  * @note Directories Handles can be cloned.
    29  *
    30  * @param path			Path to open.
    31  * @return			A Handle to the directory, INVALID_HANDLE on open error.
    32  */
    33 native Handle:OpenDirectory(const String:path[]);
    34 
    35 /**
    36  * @brief Reads the current directory entry as a local filename, then moves to the next file.
    37  * @note Contents of buffers are undefined when returning false.
    38  * @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux.
    39  * 
    40  * @param dir			Handle to a directory.
    41  * @param buffer		String buffer to hold directory name.
    42  * @param maxlength		Maximum size of string buffer.
    43  * @param type			Optional variable to store the file type.
    44  * @return			True on success, false if there are no more files to read.
    45  * @error				Invalid or corrupt Handle. 
    46  */
    47 native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown);
    48 
    49 /**
    50  * @brief Opens a file.
    51  * @note Files are closed with CloseHandle().
    52  * @note File Handles can be cloned.
    53  *
    54  * @param file			File to open.
    55  * @param mode			Open mode.
    56  * @return			A Handle to the file, INVALID_HANDLE on open error.
    57  */
    58 native Handle:OpenFile(const String:file[], const String:mode[]);
    59 
    60 /**
    61  * @brief Deletes a file.
    62  *
    63  * @param path			Path of the file to delete.
    64  * @return			True on success, false otherwise.
    65  */
    66 native bool:DeleteFile(const String:path[]);
    67 
    68 /**
    69  * @brief Reads a line from a text file.
    70  *
    71  * @param hndl			Handle to the file.
    72  * @param buffer		String buffer to hold the line.
    73  * @param maxlength		Maximum size of string buffer.	
    74  * @return			True on success, false otherwise.
    75  */
    76 native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
    77 
    78 /**
    79  * @brief Tests if the end of file has been reached.
    80  *
    81  * @param file			Handle to the file.
    82  * @return			True if end of file has been reached, false otherwise.
    83  */
    84 native bool:IsEndOfFile(Handle:file);
    85 
    86 /**
    87  * @brief Sets the file position indicator.
    88  *
    89  * @param file			Handle to the file.
    90  * @param position		Position relative to what is specified in whence.
    91  * @param whence		Look at the SEEK_* definitions.
    92  * @return			True on success, false otherwise.
    93  */
    94 native bool:FileSeek(Handle:file, position, whence);
    95 
    96 /**
    97  * @brief Get current position in the file.
    98  *
    99  * @param file			Handle to the file.
   100  * @return			Value for the file position indicator.
   101  */
   102 native FilePosition(Handle:file);
   103 
   104 /**
   105  * @brief Checks if a file exists.
   106  *
   107  * @param path			Path to the file.
   108  * @return			True if the file exists, false otherwise.
   109  */
   110 native bool:FileExists(const String:path[]);
   111 
   112 /**
   113  * @brief Renames a file.
   114  *
   115  * @param newpath		New path to the file.
   116  * @param oldpath		Path to the existing file.
   117  * @return			True on success, false otherwise.
   118  */
   119 native bool:RenameFile(const String:newpath[], const String:oldpath[]);
   120 
   121 /**
   122  * @brief Checks if a directory exists.
   123  *
   124  * @param path			Path to the directory.
   125  * @return			True if the directory exists, false otherwise.
   126  */
   127 native bool:DirExists(const String:path[]);
   128 
   129 /**
   130  * @brief Get the file size in bytes.
   131  *
   132  * @param path			Path to the file.
   133  * @return			File size in bytes, -1 if file not found.
   134  */
   135 native FileSize(const String:path[]);
   136 
   137 /**
   138  * @brief Removes a directory.
   139  * @note On most Operating Systems you cannot remove a directory which has files inside it.
   140  *
   141  * @param path			Path to the directory.
   142  * @return			True on success, false otherwise.
   143  */
   144 native bool:RemoveDir(const String:path[]);
   145 
   146 /**
   147  * @brief Writes a line of text in a file.
   148  * @note This native will append the newline character.
   149  *
   150  * @param hndl			Handle to the file.
   151  * @param format		Formatting rules.
   152  * @param ...			Variable number of format parameters.
   153  * @return			True on success, false otherwise.
   154  */
   155 native bool:WriteFileLine(Handle:hndl, const String:format[], {Handle,Float,String,_}:...);