RAWFILE.H 12 KB

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