plugins/include/files.inc
changeset 1796 db3a25745a2b
parent 1729 0f60cc4ce8bb
child 1797 9242d6aa9f5b
     1.1 --- a/plugins/include/files.inc	Fri Dec 14 23:27:34 2007 +0000
     1.2 +++ b/plugins/include/files.inc	Sun Dec 16 23:11:00 2007 +0000
     1.3 @@ -159,6 +159,112 @@
     1.4  native bool:ReadFileLine(Handle:hndl, String:buffer[], maxlength);
     1.5  
     1.6  /**
     1.7 + * Reads binary data from a file.
     1.8 + *
     1.9 + * @param hndl			Handle to the file.
    1.10 + * @param items			Array to store each item read.  
    1.11 + * @param num_items		Number of items to read into the array.
    1.12 + * @param size			Size of each element, in bytes, to be read.
    1.13 + *						Valid sizes are 1, 2, or 4.
    1.14 + * @return				Number of elements read, or -1 on error.
    1.15 + */
    1.16 +native ReadFile(Handle:hndl, items[], num_items, size);
    1.17 +
    1.18 +/**
    1.19 + * Reads a UTF8 or ANSI string from a file.
    1.20 + *
    1.21 + * @param hndl			Handle to the file.
    1.22 + * @param buffer		Buffer to store the string.
    1.23 + * @param max_size		Maximum size of the string buffer.
    1.24 + * @param stop			If true, reading will stop once max_size-1 bytes have 
    1.25 + *						been read.  If false, reading will stop once a NUL 
    1.26 + *						terminator is reached.  The buffer will simply be 
    1.27 + *						terminated in either case, the difference is in how 
    1.28 + *						the far the file position is changed.
    1.29 + * @return				Number of characters written to the buffer, or -1 
    1.30 + *						if an error was encountered.
    1.31 + * @error				Invalid Handle, or read_count > max_size.
    1.32 + */
    1.33 +native ReadFileString(Handle:hndl, String:buffer[], max_size, read_count=-1);
    1.34 +
    1.35 +/**
    1.36 + * Writes binary data to a file.
    1.37 + *
    1.38 + * @param hndl			Handle to the file.
    1.39 + * @param items			Array of items to write.  The data is read directly. 
    1.40 + *						That is, in 1 or 2-byte mode, the lower byte(s) in 
    1.41 + *						each cell are used directly, rather than performing 
    1.42 + *						any casts from a 4-byte number to a smaller number.
    1.43 + * @param num_items		Number of items in the array.
    1.44 + * @param size			Size of each item in the array in bytes.  
    1.45 + *						Valid sizes are 1, 2, or 4.
    1.46 + * @return				True on success, false on error.
    1.47 + */
    1.48 +native bool:WriteFile(Handle:hndl, const items[], num_items, size);
    1.49 +
    1.50 +/**
    1.51 + * Writes a binary string to a file.
    1.52 + *
    1.53 + * @param hndl			Handle to th efile.
    1.54 + * @param buffer		String to write.
    1.55 + * @param term			True to append NUL terminator, false otherwise.
    1.56 + * @return				True on success, false on error.
    1.57 + */
    1.58 +native bool:WriteFileString(Handle:hndl, const String:buffer[], bool:term);
    1.59 +
    1.60 +/**
    1.61 + * Writes a line of text to a text file.  A newline is automatically appended.
    1.62 + *
    1.63 + * @param hndl			Handle to the file.
    1.64 + * @param format		Formatting rules.
    1.65 + * @param ...			Variable number of format parameters.
    1.66 + * @return				True on success, false otherwise.
    1.67 + */
    1.68 +native bool:WriteFileLine(Handle:hndl, const String:format[], any:...);
    1.69 +
    1.70 +/**
    1.71 + * Reads a single binary cell from a file.
    1.72 + *
    1.73 + * @param hndl			Handle to the file.
    1.74 + * @param data			Variable to store the data read.
    1.75 + * @param size			Size of the data to read in bytes.  Valid 
    1.76 + *						sizes are 1, 2, or 4 bytes.
    1.77 + * @return				Number of elements read (max 1), or -1 on error.
    1.78 + */
    1.79 +stock ReadFileCell(Handle:hndl, &data, size)
    1.80 +{
    1.81 +	new array[1], ret;
    1.82 +	
    1.83 +	if ((ret = ReadFile(hndl, array, 1, size)) == 1)
    1.84 +	{
    1.85 +		data = array[0];
    1.86 +	}
    1.87 +	
    1.88 +	return ret;
    1.89 +}
    1.90 +
    1.91 +/**
    1.92 + * Writes a single binary cell to a file.
    1.93 + *
    1.94 + * @param hndl			Handle to the file.
    1.95 + * @param data			Cell to write to the file.
    1.96 + * @param size			Size of the data to read in bytes.  Valid 
    1.97 + *						sizes are 1, 2, or 4 bytes.  If the size 
    1.98 + *						is less than 4 bytes, the data is truncated 
    1.99 + *						rather than casted.  That is, only the lower 
   1.100 + *						bits will be read.
   1.101 + * @return				True on success, false on error.
   1.102 + */
   1.103 +stock bool:WriteFileCell(Handle:hndl, data, size)
   1.104 +{
   1.105 +	new array[1];
   1.106 +	
   1.107 +	array[0] = data;
   1.108 +	
   1.109 +	return WriteFile(hndl, array, 1, size);
   1.110 +}
   1.111 + 
   1.112 +/**
   1.113   * Tests if the end of file has been reached.
   1.114   *
   1.115   * @param file			Handle to the file.
   1.116 @@ -171,10 +277,10 @@
   1.117   *
   1.118   * @param file			Handle to the file.
   1.119   * @param position		Position relative to what is specified in whence.
   1.120 - * @param whence		Look at the SEEK_* definitions.
   1.121 + * @param where			SEEK_ constant value of where to see from.
   1.122   * @return				True on success, false otherwise.
   1.123   */
   1.124 -native bool:FileSeek(Handle:file, position, whence);
   1.125 +native bool:FileSeek(Handle:file, position, where);
   1.126  
   1.127  /**
   1.128   * Get current position in the file.
   1.129 @@ -236,17 +342,6 @@
   1.130  native bool:RemoveDir(const String:path[]);
   1.131  
   1.132  /**
   1.133 - * Writes a line of text in a file.
   1.134 - * @note This native will append the newline character.
   1.135 - *
   1.136 - * @param hndl			Handle to the file.
   1.137 - * @param format		Formatting rules.
   1.138 - * @param ...			Variable number of format parameters.
   1.139 - * @return				True on success, false otherwise.
   1.140 - */
   1.141 -native bool:WriteFileLine(Handle:hndl, const String:format[], any:...);
   1.142 -
   1.143 -/**
   1.144   * Returns a file timestamp as a unix timestamp.
   1.145   *
   1.146   * @param file			File name.