rawfilem.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. ** Command & Conquer Renegade(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. /***********************************************************************************************
  19. *** 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 ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Command & Conquer *
  23. * *
  24. * $Archive:: /G/wdump/RAWFILEM.H $*
  25. * *
  26. * $Author:: Eric_c $*
  27. * *
  28. * $Modtime:: 7/28/97 3:36p $*
  29. * *
  30. * $Revision:: 3 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * RawFileMClass::File_Name -- Returns with the filename associate with the file object. *
  35. * RawFileMClass::RawFileMClass -- Default constructor for a file object. *
  36. * RawFileMClass::~RawFileMClass -- Default deconstructor for a file object. *
  37. * RawFileMClass::Is_Open -- Checks to see if the file is open or not. *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #ifndef RAWFILEM_Hx
  40. #define RAWFILEM_Hx
  41. #include <errno.h>
  42. #include <limits.h>
  43. #include <stddef.h>
  44. #include <stdlib.h>
  45. #include "win.h"
  46. #define NULL_HANDLE INVALID_HANDLE_VALUE
  47. #define HANDLE_TYPE HANDLE
  48. #include "wwfile.h"
  49. #ifdef NEVER
  50. /*
  51. ** This is a duplicate of the error numbers. The error handler for the RawFileMClass handles
  52. ** these errors. If the error routine is overridden and additional errors are defined, then
  53. ** use numbers starting with 100. Note that these errors here are listed in numerical order.
  54. ** These errors are defined in the standard header file "ERRNO.H".
  55. */
  56. EZERO, // Non-error.
  57. EINVFNC, // Invalid function number.
  58. ENOFILE, // File not found.
  59. ENOENT=ENOFILE, // No such file or directory.
  60. ENOPATH, // Path not found.
  61. EMFILE, // Too many open files.
  62. EACCES, // Permission denied.
  63. EBADF, // Bad file number.
  64. ECONTR, // Memory blocks destroyed.
  65. ENOMEM, // Not enough core memory.
  66. EINVMEM, // Invalid memory block address.
  67. EINVENV, // Invalid environment.
  68. EINVFMT, // Invalid format.
  69. EINVACC, // Invalid access code.
  70. EINVDAT, // Invalid data.
  71. EFAULT, // Unknown error.
  72. EINVDRV, // Invalid drive specified.
  73. ENODEV=EINVDRV, // No such device.
  74. ECURDIR, // Attempt to remove CurDir.
  75. ENOTSAM, // Not same device.
  76. ENMFILE, // No more files.
  77. EINVAL, // Invalid argument.
  78. E2BIG, // Argument list too long.
  79. ENOEXEC, // exec format error.
  80. EXDEV, // Cross-device link.
  81. ENFILE, // Too many open files.
  82. ECHILD, // No child process.
  83. ENOTTY, // not used
  84. ETXTBSY, // not used
  85. EFBIG, // not used
  86. ENOSPC, // No space left on device.
  87. ESPIPE, // Illegal seek.
  88. EROFS, // Read-only file system.
  89. EMLINK, // not used
  90. EPIPE, // Broken pipe.
  91. EDOM, // Math argument.
  92. ERANGE, // Result too large.
  93. EEXIST, // File already exists.
  94. EDEADLOCK, // Locking violation.
  95. EPERM, // Operation not permitted.
  96. ESRCH, // not used
  97. EINTR, // Interrupted function call.
  98. EIO, // Input/output error.
  99. ENXIO, // No such device or address.
  100. EAGAIN, // Resource temporarily unavailable.
  101. ENOTBLK, // not used
  102. EBUSY, // Resource busy.
  103. ENOTDIR, // not used
  104. EISDIR, // not used
  105. EUCLEAN, // not used
  106. #endif
  107. #ifndef WWERROR
  108. #define WWERROR -1
  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 RawFileMClass : public FileClass
  122. {
  123. typedef FileClass BASECLASS;
  124. public:
  125. /*
  126. ** This is a record of the access rights used to open the file. These rights are
  127. ** used if the file object is duplicated.
  128. */
  129. int Rights;
  130. int Error_Number; // added by ehc to allow multithread library usage
  131. RawFileMClass(char const *filename);
  132. RawFileMClass(void);
  133. RawFileMClass (RawFileMClass const & f);
  134. RawFileMClass & operator = (RawFileMClass const & f);
  135. virtual ~RawFileMClass(void);
  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 bool Is_Available(int forced=false);
  141. virtual bool Is_Open(void) const;
  142. virtual int Open(char const *filename, int rights=READ);
  143. virtual int Open(int rights=READ);
  144. virtual int Read(void *buffer, int size);
  145. virtual int Seek(int pos, int dir=SEEK_CUR);
  146. virtual int Size(void);
  147. virtual int Write(void const *buffer, int size);
  148. virtual void Close(void);
  149. virtual unsigned long Get_Date_Time(void);
  150. virtual bool Set_Date_Time(unsigned long datetime);
  151. virtual void Error(int error, int canretry = false, char const * filename=NULL);
  152. void Bias(int start, int length=-1);
  153. HANDLE_TYPE Get_File_Handle(void) { return (Handle); };
  154. /*
  155. ** These bias values enable a sub-portion of a file to appear as if it
  156. ** were the whole file. This comes in very handy for multi-part files such as
  157. ** mixfiles.
  158. */
  159. int BiasStart;
  160. int BiasLength;
  161. protected:
  162. /*
  163. ** This function returns the largest size a low level DOS read or write may
  164. ** perform. Larger file transfers are performed in chunks of this size or less.
  165. */
  166. int Transfer_Block_Size(void) {return (int)((unsigned)UINT_MAX)-16L;};
  167. int Raw_Seek(int pos, int dir=SEEK_CUR);
  168. private:
  169. /*
  170. ** This is the low level DOS handle. A -1 indicates an empty condition.
  171. */
  172. HANDLE_TYPE Handle;
  173. /*
  174. ** This points to the filename as a NULL terminated string. It may point to either a
  175. ** constant or an allocated string as indicated by the "Allocated" flag.
  176. */
  177. char const * Filename;
  178. //
  179. // file date and time are in the following formats:
  180. //
  181. // date bits 0-4 day (0-31)
  182. // bits 5-8 month (1-12)
  183. // bits 9-15 year (0-119 representing 1980-2099)
  184. //
  185. // time bits 0-4 second/2 (0-29)
  186. // bits 5-10 minutes (0-59)
  187. // bits 11-15 hours (0-23)
  188. //
  189. unsigned short Date;
  190. unsigned short Time;
  191. /*
  192. ** Filenames that were assigned as part of the construction process
  193. ** are not allocated. It is assumed that the filename string is a
  194. ** constant in that case and thus making duplication unnecessary.
  195. ** This value will be non-zero if the filename has be allocated
  196. ** (using strdup()).
  197. */
  198. bool Allocated;
  199. };
  200. /***********************************************************************************************
  201. * RawFileMClass::File_Name -- Returns with the filename associate with the file object. *
  202. * *
  203. * Use this routine to determine what filename is associated with this file object. If no *
  204. * filename has yet been assigned, then this routing will return NULL. *
  205. * *
  206. * INPUT: none *
  207. * *
  208. * OUTPUT: Returns with a pointer to the file name associated with this file object or NULL *
  209. * if one doesn't exist. *
  210. * *
  211. * WARNINGS: none *
  212. * *
  213. * HISTORY: *
  214. * 10/18/1994 JLB : Created. *
  215. *=============================================================================================*/
  216. inline char const * RawFileMClass::File_Name(void) const
  217. {
  218. return(Filename);
  219. }
  220. /***********************************************************************************************
  221. * RawFileMClass::RawFileMClass -- Default constructor for a file object. *
  222. * *
  223. * This constructs a null file object. A null file object has no file handle or filename *
  224. * associated with it. In order to use a file object created in this fashion it must be *
  225. * assigned a name and then opened. *
  226. * *
  227. * INPUT: none *
  228. * *
  229. * OUTPUT: none *
  230. * *
  231. * WARNINGS: none *
  232. * *
  233. * HISTORY: *
  234. * 10/18/1994 JLB : Created. *
  235. *=============================================================================================*/
  236. inline RawFileMClass::RawFileMClass(void) :
  237. Rights(READ),
  238. BiasStart(0),
  239. BiasLength(-1),
  240. Handle(INVALID_HANDLE_VALUE),
  241. Filename(0),
  242. Date(0),
  243. Time(0),
  244. Allocated(false)
  245. {
  246. }
  247. /***********************************************************************************************
  248. * RawFileMClass::~RawFileMClass -- Default deconstructor for a file object. *
  249. * *
  250. * This constructs a null file object. A null file object has no file handle or filename *
  251. * associated with it. In order to use a file object created in this fashion it must be *
  252. * assigned a name and then opened. *
  253. * *
  254. * INPUT: none *
  255. * *
  256. * OUTPUT: none *
  257. * *
  258. * WARNINGS: none *
  259. * *
  260. * HISTORY: *
  261. * 10/18/1994 JLB : Created. *
  262. *=============================================================================================*/
  263. inline RawFileMClass::~RawFileMClass(void)
  264. {
  265. Close();
  266. if (Allocated && Filename) {
  267. free((char *)Filename);
  268. Filename = NULL;
  269. Allocated = false;
  270. }
  271. }
  272. /***********************************************************************************************
  273. * RawFileMClass::Is_Open -- Checks to see if the file is open or not. *
  274. * *
  275. * Use this routine to determine if the file is open. It returns true if it is. *
  276. * *
  277. * INPUT: none *
  278. * *
  279. * OUTPUT: bool; Is the file open? *
  280. * *
  281. * *
  282. * WARNINGS: none *
  283. * *
  284. * HISTORY: *
  285. * 10/18/1994 JLB : Created. *
  286. *=============================================================================================*/
  287. inline bool RawFileMClass::Is_Open(void) const
  288. {
  289. return(Handle != INVALID_HANDLE_VALUE);
  290. }
  291. #endif