RAWFILE.H 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: F:\projects\c&c\vcs\code\rawfile.h_v 2.15 06 Sep 1995 16:29:30 JOE_BOSTIC $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Westwood Library *
  24. * *
  25. * File Name : RAWFILE.H *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : August 8, 1994 *
  30. * *
  31. * Last Update : October 18, 1994 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * RawFileClass::File_Name -- Returns with the filename associate with the file object. *
  36. * RawFileClass::RawFileClass -- Default constructor for a file object. *
  37. * RawFileClass::Is_Open -- Checks to see if the file is open or not. *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #ifndef RAWFILE_H
  40. #define RAWFILE_H
  41. #define WIN32 1
  42. #ifndef _WIN32 // Denzil 6/2/98 Watcom 11.0 complains without this check
  43. #define _WIN32
  44. #endif // _WIN32
  45. #include <windows.h>
  46. //#include <wwlib32.h>
  47. #include <limits.h>
  48. #include <errno.h>
  49. #include <windows.h>
  50. //#include <algo.h>
  51. #include "wwfile.h"
  52. #ifdef NEVER
  53. /*
  54. ** This is a duplicate of the error numbers. The error handler for the RawFileClass handles
  55. ** these errors. If the error routine is overridden and additional errors are defined, then
  56. ** use numbers starting with 100. Note that these errors here are listed in numerical order.
  57. ** These errors are defined in the standard header file "ERRNO.H".
  58. */
  59. EZERO, // Non-error.
  60. EINVFNC, // Invalid function number.
  61. ENOFILE, // File not found.
  62. ENOENT=ENOFILE, // No such file or directory.
  63. ENOPATH, // Path not found.
  64. EMFILE, // Too many open files.
  65. EACCES, // Permission denied.
  66. EBADF, // Bad file number.
  67. ECONTR, // Memory blocks destroyed.
  68. ENOMEM, // Not enough core memory.
  69. EINVMEM, // Invalid memory block address.
  70. EINVENV, // Invalid environment.
  71. EINVFMT, // Invalid format.
  72. EINVACC, // Invalid access code.
  73. EINVDAT, // Invalid data.
  74. EFAULT, // Unknown error.
  75. EINVDRV, // Invalid drive specified.
  76. ENODEV=EINVDRV, // No such device.
  77. ECURDIR, // Attempt to remove CurDir.
  78. ENOTSAM, // Not same device.
  79. ENMFILE, // No more files.
  80. EINVAL, // Invalid argument.
  81. E2BIG, // Argument list too long.
  82. ENOEXEC, // exec format error.
  83. EXDEV, // Cross-device link.
  84. ENFILE, // Too many open files.
  85. ECHILD, // No child process.
  86. ENOTTY, // not used
  87. ETXTBSY, // not used
  88. EFBIG, // not used
  89. ENOSPC, // No space left on device.
  90. ESPIPE, // Illegal seek.
  91. EROFS, // Read-only file system.
  92. EMLINK, // not used
  93. EPIPE, // Broken pipe.
  94. EDOM, // Math argument.
  95. ERANGE, // Result too large.
  96. EEXIST, // File already exists.
  97. EDEADLOCK, // Locking violation.
  98. EPERM, // Operation not permitted.
  99. ESRCH, // not used
  100. EINTR, // Interrupted function call.
  101. EIO, // Input/output error.
  102. ENXIO, // No such device or address.
  103. EAGAIN, // Resource temporarily unavailable.
  104. ENOTBLK, // not used
  105. EBUSY, // Resource busy.
  106. ENOTDIR, // not used
  107. EISDIR, // not used
  108. EUCLEAN, // not used
  109. #endif
  110. /*
  111. ** This is the definition of the raw file class. It is derived from the abstract base FileClass
  112. ** and handles the interface to the low level DOS routines. This is the first class in the
  113. ** chain of derived file classes that actually performs a useful function. With this class,
  114. ** I/O is possible. More sophisticated features, such as packed files, CD-ROM support,
  115. ** file caching, and XMS/EMS memory support, are handled by derived classes.
  116. **
  117. ** Of particular importance is the need to override the error routine if more sophisticated
  118. ** error handling is required. This is more than likely if greater functionality is derived
  119. ** from this base class.
  120. */
  121. class RawFileClass : public FileClass
  122. {
  123. public:
  124. /*
  125. ** This is a record of the access rights used to open the file. These rights are
  126. ** used if the file object is duplicated.
  127. */
  128. int Rights;
  129. RawFileClass(char const *filename);
  130. RawFileClass(void);
  131. RawFileClass (RawFileClass const & f);
  132. RawFileClass & operator = (RawFileClass const & f);
  133. virtual ~RawFileClass(void) {if (Allocated && Filename) free((char *)Filename);};
  134. virtual char const * File_Name(void) const;
  135. virtual char const * Set_Name(char const *filename);
  136. virtual int Create(void);
  137. virtual int Delete(void);
  138. virtual int Is_Available(int forced=false);
  139. virtual int Is_Open(void) const;
  140. virtual int Open(char const *filename, int rights=READ);
  141. virtual int Open(int rights=READ);
  142. virtual long Read(void *buffer, long size);
  143. virtual long Seek(long pos, int dir=SEEK_CUR);
  144. virtual long Size(void);
  145. virtual long Write(void const *buffer, long size);
  146. virtual void Close(void);
  147. virtual void Error(int error, int canretry = false, char const * filename=NULL);
  148. virtual void Set_Buffer_Size(int size);
  149. protected:
  150. /*
  151. ** This function returns the largest size a low level DOS read or write may
  152. ** perform. Larger file transfers are performed in chunks of this size or less.
  153. */
  154. long Transfer_Block_Size(void) {return (long)((unsigned)UINT_MAX)-16L;};
  155. private:
  156. /*
  157. ** This is the low level DOS handle. A -1 indicates an empty condition.
  158. */
  159. int Handle;
  160. /*
  161. ** This points to the filename as a NULL terminated string. It may point to either a
  162. ** constant or an allocated string as indicated by the "Allocated" flag.
  163. */
  164. char const * const Filename;
  165. /*
  166. ** Filenames that were assigned as part of the construction process
  167. ** are not allocated. It is assumed that the filename string is a
  168. ** constant in that case and thus making duplication unnecessary.
  169. ** This value will be non-zero if the filename has be allocated
  170. ** (using strdup()).
  171. */
  172. unsigned Allocated:1;
  173. };
  174. /***********************************************************************************************
  175. * RawFileClass::File_Name -- Returns with the filename associate with the file object. *
  176. * *
  177. * Use this routine to determine what filename is associated with this file object. If no *
  178. * filename has yet been assigned, then this routing will return NULL. *
  179. * *
  180. * INPUT: none *
  181. * *
  182. * OUTPUT: Returns with a pointer to the file name associated with this file object or NULL *
  183. * if one doesn't exist. *
  184. * *
  185. * WARNINGS: none *
  186. * *
  187. * HISTORY: *
  188. ;* 10/18/1994 JLB : Created. *
  189. *=============================================================================================*/
  190. inline char const * RawFileClass::File_Name(void) const
  191. {
  192. return Filename;
  193. }
  194. /***********************************************************************************************
  195. * RawFileClass::RawFileClass -- Default constructor for a file object. *
  196. * *
  197. * This constructs a null file object. A null file object has no file handle or filename *
  198. * associated with it. In order to use a file object created in this fashion it must be *
  199. * assigned a name and then opened. *
  200. * *
  201. * INPUT: none *
  202. * *
  203. * OUTPUT: none *
  204. * *
  205. * WARNINGS: none *
  206. * *
  207. * HISTORY: *
  208. ;* 10/18/1994 JLB : Created. *
  209. *=============================================================================================*/
  210. inline RawFileClass::RawFileClass(void) : Filename(0)
  211. {
  212. Handle = -1;
  213. Allocated = false;
  214. }
  215. /***********************************************************************************************
  216. * RawFileClass::Is_Open -- Checks to see if the file is open or not. *
  217. * *
  218. * Use this routine to determine if the file is open. It returns true if it is. *
  219. * *
  220. * INPUT: none *
  221. * *
  222. * OUTPUT: bool; Is the file open? *
  223. * *
  224. * *
  225. * WARNINGS: none *
  226. * *
  227. * HISTORY: *
  228. ;* 10/18/1994 JLB : Created. *
  229. *=============================================================================================*/
  230. inline int RawFileClass::Is_Open(void) const
  231. {
  232. return (Handle != -1);
  233. }
  234. #endif