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