RAWFILE.H 12 KB

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