2014-08-04 12:12:15 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// File Functions
|
|
|
|
//
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2004-02-21 20:30:04 +00:00
|
|
|
#if defined _file_included
|
|
|
|
#endinput
|
|
|
|
#endif
|
|
|
|
#define _file_included
|
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
/* Reads content from directory.
|
2004-02-21 20:30:04 +00:00
|
|
|
* Returns index of next element or 0 when end of dir. is reached. */
|
2004-01-31 20:56:22 +00:00
|
|
|
native read_dir(const dirname[],pos,output[],len,&outlen);
|
|
|
|
|
|
|
|
/* Reads line from file. Returns index of next line or 0 when end of file is reached. */
|
|
|
|
native read_file(const file[],line,text[],len,&txtlen);
|
|
|
|
|
|
|
|
/* Writes text to file. Function returns 0 on failure.
|
2004-02-21 20:30:04 +00:00
|
|
|
* When line is set to -1, the text is added at the end of file. */
|
2004-01-31 20:56:22 +00:00
|
|
|
native write_file(const file[],const text[],line = -1);
|
|
|
|
|
|
|
|
/* Deletes file. Function returns 1 on success, 0 on failure. */
|
|
|
|
native delete_file(const file[]);
|
|
|
|
|
|
|
|
/* Checks for file. If file exists function returns 1, in other case 0. */
|
|
|
|
native file_exists(const file[]);
|
|
|
|
|
2006-04-27 17:31:38 +00:00
|
|
|
/* renames a file. returns 0 on failure, 1 on success.
|
2006-10-31 20:18:44 +00:00
|
|
|
* if relative true, rename_file will act like other natives which
|
|
|
|
* use the moddir as a base directory. otherwise, the current directory is
|
|
|
|
* undefined (but assumed to be hlds).
|
2006-04-27 17:31:38 +00:00
|
|
|
*/
|
2006-10-31 20:18:44 +00:00
|
|
|
native rename_file(const oldname[], const newname[], relative=0);
|
2006-04-27 17:31:38 +00:00
|
|
|
|
2005-07-07 19:53:02 +00:00
|
|
|
/* Checks if a directory exists */
|
|
|
|
native dir_exists(const dir[]);
|
|
|
|
|
2004-01-31 20:56:22 +00:00
|
|
|
/* Returns a file size in bytes if flag is set to 0.
|
2004-02-21 20:30:04 +00:00
|
|
|
* When flag is set to 1 returns number of lines in the file,
|
|
|
|
* and when flags is 2, function returns 1 if the file ends
|
|
|
|
* with line feed. If file doesn't exist returns -1. */
|
2004-04-03 20:05:27 +00:00
|
|
|
native file_size(const file[], flag=0);
|
|
|
|
|
|
|
|
#define SEEK_SET 0
|
|
|
|
#define SEEK_CUR 1
|
|
|
|
#define SEEK_END 2
|
|
|
|
|
2006-04-27 17:31:55 +00:00
|
|
|
//Open a file, returns a handle or 0 on failure
|
2005-05-29 16:36:35 +00:00
|
|
|
native fopen(const filename[],const mode[]);
|
2006-01-06 22:49:42 +00:00
|
|
|
|
|
|
|
//Closes a file handle
|
2004-04-03 20:05:27 +00:00
|
|
|
native fclose(file);
|
2006-01-06 22:49:42 +00:00
|
|
|
|
|
|
|
#define BLOCK_INT 4
|
|
|
|
#define BLOCK_SHORT 2
|
|
|
|
#define BLOCK_CHAR 1
|
|
|
|
#define BLOCK_BYTE 1
|
|
|
|
|
|
|
|
//The following functions work as such:
|
|
|
|
// RAW - means the array you pass is a raw bytestream, for experts only
|
|
|
|
// BLOCK - means you are passing in an array where each element will be written
|
|
|
|
// NORMAL - means you are writing only one element
|
|
|
|
// RAW and BLOCK return the number of blocks acted upon successfully
|
|
|
|
// NORMAL returns 1 on success
|
|
|
|
|
|
|
|
native fread(file, &data, mode);
|
|
|
|
native fread_blocks(file, data[], blocks, mode);
|
|
|
|
native fread_raw(file, stream[], blocksize, blocks);
|
|
|
|
native fwrite(file, data, mode);
|
|
|
|
native fwrite_blocks(file, const data[], blocks, mode);
|
|
|
|
native fwrite_raw(file, const stream[], blocksize, mode);
|
|
|
|
|
|
|
|
//Returns 1 if the file is ended, 0 otherwise
|
|
|
|
native feof(file);
|
|
|
|
|
|
|
|
//Reads a line from a text file -- includes newline!
|
|
|
|
native fgets(file, buffer[], maxlength);
|
|
|
|
|
2006-04-27 17:31:38 +00:00
|
|
|
//Writes a line to a text file. Returns # of characters written.
|
|
|
|
native fputs(file, const text[]);
|
|
|
|
|
2006-01-06 22:49:42 +00:00
|
|
|
//Writes a line to the file
|
2007-04-24 16:38:36 +00:00
|
|
|
native fprintf(file, const fmt[], any:...);
|
2006-01-06 22:49:42 +00:00
|
|
|
|
|
|
|
//Sets the current position in a file (see SEEK_ values above)
|
|
|
|
native fseek(file, position, start);
|
|
|
|
|
|
|
|
//Returns the current position in a file
|
|
|
|
native ftell(file);
|
2005-07-24 03:23:35 +00:00
|
|
|
|
2006-03-29 22:58:11 +00:00
|
|
|
//These are straight from the C standard.
|
|
|
|
native fgetc(file);
|
|
|
|
native fputc(file, data);
|
|
|
|
native fungetc(file, data);
|
|
|
|
|
2004-04-03 20:05:27 +00:00
|
|
|
//Return the size of a file
|
2007-04-24 16:38:36 +00:00
|
|
|
native filesize(const filename[], any:...);
|
2005-07-24 03:23:35 +00:00
|
|
|
|
2006-03-30 00:48:58 +00:00
|
|
|
//Attempts to remove a directory.
|
|
|
|
//Note that you cannot remove a directory that has files on most
|
|
|
|
// operating systems.
|
|
|
|
native rmdir(const path[]);
|
|
|
|
|
2007-08-07 00:54:22 +00:00
|
|
|
/* Returns 0 on success, like the POSIX specification */
|
|
|
|
native mkdir(const dirname[]);
|
|
|
|
|
|
|
|
|
2004-04-03 20:05:27 +00:00
|
|
|
//Delete a file (delete_file macro)
|
2006-04-10 14:02:37 +00:00
|
|
|
native unlink(const filename[]);
|
2004-04-03 20:05:27 +00:00
|
|
|
|
2005-07-13 23:30:28 +00:00
|
|
|
//Returns a handle to a directory
|
|
|
|
native open_dir(dir[], firstfile[], length);
|
|
|
|
native next_file(dirh, buffer[], length);
|
|
|
|
native close_dir(dirh);
|
2007-10-22 19:26:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads a file using the LoadFileForMe engine function.
|
|
|
|
*
|
|
|
|
* The data is truncated if there is not enough space. No null-terminator
|
|
|
|
* is applied; the data is the raw contents of the file.
|
|
|
|
*
|
|
|
|
* @param file File to load (may be a file from the GCF).
|
|
|
|
* @param buffer Buffer to store file contents.
|
|
|
|
* @param maxlength Maximum size of the file buffer.
|
|
|
|
* @param length Variable to store the file length. This may return
|
|
|
|
* a number larger than the buffer size.
|
|
|
|
* @return -1 if the file could not be loaded. Otherwise,
|
|
|
|
* the number of cells actually written to the buffer
|
|
|
|
* are returned.
|
|
|
|
*/
|
|
|
|
native LoadFileForMe(const file[], buffer[], maxlength, &length=0);
|
2009-02-07 23:43:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flushes a buffered output stream.
|
|
|
|
*
|
|
|
|
* @param file File handle, or 0 for all open streams.
|
|
|
|
* @return 0 on success, -1 on failure.
|
|
|
|
*/
|
|
|
|
native fflush(file);
|
|
|
|
|
2013-06-21 21:09:41 +00:00
|
|
|
enum FileTimeType
|
|
|
|
{
|
|
|
|
FileTime_LastAccess, /* Last access (not available on FAT) */
|
|
|
|
FileTime_Created, /* Creation (not available on FAT) */
|
2013-06-29 10:31:08 +00:00
|
|
|
FileTime_LastChange, /* Last modification */
|
2013-06-21 21:09:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a file timestamp as a unix timestamp.
|
|
|
|
*
|
|
|
|
* @param file File name.
|
|
|
|
* @param tmode Time mode. See FileTime_* constants.
|
|
|
|
* @return Returns a file timestamp as a unix timestamp.
|
|
|
|
*/
|
|
|
|
native GetFileTime( const file[], FileTimeType:tmode );
|