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