plugins/include/files.inc
author Scott Ehlert <ds@alliedmods.net>
Tue Mar 06 04:50:30 2007 +0000 (2007-03-06)
changeset 577 39a746736a0f
parent 475 bb11d7eaae0f
child 619 6934bf39171e
permissions -rw-r--r--
Creating/Firing/Canceling events now use CStack to avoid the need to use new when possible
dvander@252
     1
/**
ds@475
     2
 * vim: set ts=4 :
dvander@374
     3
 * ===============================================================
dvander@374
     4
 * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
dvander@374
     5
 * ===============================================================
dvander@374
     6
 *
dvander@374
     7
 *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
dvander@374
     8
 * or modified under the Terms and Conditions of its License Agreement, which is found 
dvander@374
     9
 * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
dvander@374
    10
 * may change at any time.  To view the latest information, see:
dvander@374
    11
 *   http://www.sourcemod.net/license.php
dvander@374
    12
 *
dvander@374
    13
 * Version: $Id$
dvander@252
    14
 */
dvander@252
    15
dvander@252
    16
#if defined _files_included
dvander@252
    17
 #endinput
dvander@252
    18
#endif
dvander@252
    19
#define _files_included
dvander@252
    20
dvander@252
    21
/* @note All paths in SourceMod natives are relative to the mod folder unless otherwise noted. */
dvander@252
    22
 
dvander@252
    23
enum FileType
dvander@252
    24
{
dvander@252
    25
	FileType_Unknown = 0,	/* Unknown file type (device/socket) */
dvander@252
    26
	FileType_Directory = 1,	/* File is a directory */
dvander@252
    27
	FileType_File = 2,		/* File is a file */
dvander@252
    28
};
dvander@252
    29
dvander@257
    30
#define PLATFORM_MAX_PATH		256
dvander@252
    31
faluco@274
    32
#define SEEK_SET 0
faluco@274
    33
#define SEEK_CUR 1
faluco@274
    34
#define SEEK_END 2
faluco@274
    35
dvander@345
    36
enum PathType
dvander@345
    37
{
dvander@345
    38
	Path_SM,		/* SourceMod root folder */	
dvander@345
    39
};
dvander@345
    40
dvander@345
    41
/**
dvander@345
    42
 * @brief Builds a path relative to the SourceMod folder.
dvander@345
    43
 *
dvander@345
    44
 * @param type			Type of path to build as the base.
dvander@345
    45
 * @param buffer		Buffer to store the path.
dvander@345
    46
 * @param maxlength		Maximum length of buffer.
dvander@345
    47
 * @param fmt			Format string.
dvander@345
    48
 * @param ...			Format arguments.
dvander@345
    49
 * @return				Number of bytes written to buffer (not including null terminator).
dvander@345
    50
 */
dvander@345
    51
native BuildPath(PathType:type, String:buffer[], maxlength, const String:fmt[], ...);
dvander@345
    52
dvander@252
    53
/**
dvander@252
    54
 * @brief Opens a directory/folder for contents enumeration.
dvander@252
    55
 * @note Directories are closed with CloseHandle().
dvander@252
    56
 * @note Directories Handles can be cloned.
dvander@252
    57
 *
dvander@252
    58
 * @param path			Path to open.
dvander@345
    59
 * @return				A Handle to the directory, INVALID_HANDLE on open error.
dvander@252
    60
 */
dvander@252
    61
native Handle:OpenDirectory(const String:path[]);
dvander@252
    62
dvander@252
    63
/**
dvander@252
    64
 * @brief Reads the current directory entry as a local filename, then moves to the next file.
dvander@252
    65
 * @note Contents of buffers are undefined when returning false.
dvander@252
    66
 * @note Both the '.' and '..' automatic directory entries will be retrieved for Windows and Linux.
dvander@252
    67
 * 
dvander@252
    68
 * @param dir			Handle to a directory.
dvander@252
    69
 * @param buffer		String buffer to hold directory name.
dvander@252
    70
 * @param maxlength		Maximum size of string buffer.
dvander@252
    71
 * @param type			Optional variable to store the file type.
dvander@345
    72
 * @return				True on success, false if there are no more files to read.
dvander@252
    73
 * @error				Invalid or corrupt Handle. 
dvander@252
    74
 */
dvander@257
    75
native bool:ReadDirEntry(Handle:dir, String:buffer[], maxlength, &FileType:type=FileType_Unknown);
faluco@274
    76
faluco@274
    77
/**
faluco@274
    78
 * @brief Opens a file.
faluco@274
    79
 * @note Files are closed with CloseHandle().
faluco@274
    80
 * @note File Handles can be cloned.
faluco@274
    81
 *
ds@475
    82
 * @param file			File to open.
ds@475
    83
 * @param mode			Open mode.
ds@475
    84
 * @return				A Handle to the file, INVALID_HANDLE on open error.
faluco@274
    85
 */
faluco@274
    86
native Handle:OpenFile(const String:file[], const String:mode[]);
faluco@274
    87
faluco@274
    88
/**
faluco@274
    89
 * @brief Deletes a file.
faluco@274
    90
 *
ds@475
    91
 * @param path			Path of the file to delete.
ds@475
    92
 * @return				True on success, false otherwise.
faluco@274
    93
 */
faluco@274
    94
native bool:DeleteFile(const String:path[]);
faluco@274
    95
faluco@274
    96
/**
faluco@274
    97
 * @brief Reads a line from a text file.
faluco@274
    98
 *
faluco@274
    99
 * @param hndl			Handle to the file.
faluco@274
   100
 * @param buffer		String buffer to hold the line.
faluco@274
   101
 * @param maxlength		Maximum size of string buffer.	
dvander@345
   102
 * @return				True on success, false otherwise.
faluco@274
   103
 */
faluco@274
   104
native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
faluco@274
   105
faluco@274
   106
/**
faluco@274
   107
 * @brief Tests if the end of file has been reached.
faluco@274
   108
 *
ds@475
   109
 * @param file			Handle to the file.
ds@475
   110
 * @return				True if end of file has been reached, false otherwise.
faluco@274
   111
 */
faluco@274
   112
native bool:IsEndOfFile(Handle:file);
faluco@274
   113
faluco@274
   114
/**
faluco@274
   115
 * @brief Sets the file position indicator.
faluco@274
   116
 *
ds@475
   117
 * @param file			Handle to the file.
ds@475
   118
 * @param position		Position relative to what is specified in whence.
ds@475
   119
 * @param whence		Look at the SEEK_* definitions.
ds@475
   120
 * @return				True on success, false otherwise.
faluco@274
   121
 */
faluco@274
   122
native bool:FileSeek(Handle:file, position, whence);
faluco@274
   123
faluco@274
   124
/**
faluco@274
   125
 * @brief Get current position in the file.
faluco@274
   126
 *
ds@475
   127
 * @param file			Handle to the file.
ds@475
   128
 * @return				Value for the file position indicator.
faluco@274
   129
 */
faluco@274
   130
native FilePosition(Handle:file);
faluco@274
   131
faluco@274
   132
/**
faluco@274
   133
 * @brief Checks if a file exists.
faluco@274
   134
 *
ds@475
   135
 * @param path			Path to the file.
ds@475
   136
 * @return				True if the file exists, false otherwise.
faluco@274
   137
 */
faluco@274
   138
native bool:FileExists(const String:path[]);
faluco@274
   139
faluco@274
   140
/**
faluco@274
   141
 * @brief Renames a file.
faluco@274
   142
 *
faluco@274
   143
 * @param newpath		New path to the file.
faluco@274
   144
 * @param oldpath		Path to the existing file.
dvander@345
   145
 * @return				True on success, false otherwise.
faluco@274
   146
 */
faluco@274
   147
native bool:RenameFile(const String:newpath[], const String:oldpath[]);
faluco@274
   148
faluco@274
   149
/**
faluco@274
   150
 * @brief Checks if a directory exists.
faluco@274
   151
 *
ds@475
   152
 * @param path			Path to the directory.
ds@475
   153
 * @return				True if the directory exists, false otherwise.
faluco@274
   154
 */
faluco@274
   155
native bool:DirExists(const String:path[]);
faluco@274
   156
faluco@274
   157
/**
faluco@274
   158
 * @brief Get the file size in bytes.
faluco@274
   159
 *
ds@475
   160
 * @param path			Path to the file.
ds@475
   161
 * @return				File size in bytes, -1 if file not found.
faluco@274
   162
 */
faluco@274
   163
native FileSize(const String:path[]);
faluco@274
   164
faluco@274
   165
/**
faluco@274
   166
 * @brief Removes a directory.
faluco@274
   167
 * @note On most Operating Systems you cannot remove a directory which has files inside it.
faluco@274
   168
 *
ds@475
   169
 * @param path			Path to the directory.
ds@475
   170
 * @return				True on success, false otherwise.
faluco@274
   171
 */
faluco@274
   172
native bool:RemoveDir(const String:path[]);
faluco@274
   173
faluco@274
   174
/**
faluco@274
   175
 * @brief Writes a line of text in a file.
faluco@274
   176
 * @note This native will append the newline character.
faluco@274
   177
 *
ds@475
   178
 * @param hndl			Handle to the file.
ds@475
   179
 * @param format		Formatting rules.
ds@475
   180
 * @param ...			Variable number of format parameters.
ds@475
   181
 * @return				True on success, false otherwise.
faluco@274
   182
 */
faluco@275
   183
native bool:WriteFileLine(Handle:hndl, const String:format[], {Handle,Float,String,_}:...);