rawfile.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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:: /Commando/Code/wwlib/rawfile.h $*
  25. * *
  26. * $Author:: Ian_l $*
  27. * *
  28. * $Modtime:: 10/31/01 2:00p $*
  29. * *
  30. * $Revision:: 9 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * RawFileClass::File_Name -- Returns with the filename associate with the file object. *
  35. * RawFileClass::RawFileClass -- Default constructor for a file object. *
  36. * RawFileClass::~RawFileClass -- Default deconstructor for a file object. *
  37. * RawFileClass::Is_Open -- Checks to see if the file is open or not. *
  38. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  39. #if _MSC_VER >= 1000
  40. #pragma once
  41. #endif // _MSC_VER >= 1000
  42. #ifndef RAWFILE_Hx
  43. #define RAWFILE_Hx
  44. //#include <errno.h>
  45. // #include "win.h"
  46. #ifdef _UNIX
  47. #include <stdio.h>
  48. #include "osdep.h"
  49. #define NULL_HANDLE NULL
  50. #define HANDLE_TYPE FILE*
  51. #else
  52. #define NULL_HANDLE INVALID_HANDLE_VALUE
  53. #define HANDLE_TYPE HANDLE
  54. #endif
  55. #include "wwfile.h"
  56. #ifndef WWERROR
  57. #define WWERROR -1
  58. #endif
  59. /*
  60. ** This is the definition of the raw file class. It is derived from the abstract base FileClass
  61. ** and handles the interface to the low level DOS routines. This is the first class in the
  62. ** chain of derived file classes that actually performs a useful function. With this class,
  63. ** I/O is possible. More sophisticated features, such as packed files, CD-ROM support,
  64. ** file caching, and XMS/EMS memory support, are handled by derived classes.
  65. **
  66. ** Of particular importance is the need to override the error routine if more sophisticated
  67. ** error handling is required. This is more than likely if greater functionality is derived
  68. ** from this base class.
  69. */
  70. class RawFileClass : public FileClass
  71. {
  72. typedef FileClass BASECLASS;
  73. public:
  74. /*
  75. ** This is a record of the access rights used to open the file. These rights are
  76. ** used if the file object is duplicated.
  77. */
  78. int Rights;
  79. RawFileClass(char const *filename);
  80. RawFileClass(void);
  81. RawFileClass (RawFileClass const & f);
  82. RawFileClass & operator = (RawFileClass const & f);
  83. virtual ~RawFileClass(void);
  84. virtual char const * File_Name(void) const;
  85. virtual char const * Set_Name(char const *filename);
  86. virtual int Create(void);
  87. virtual int Delete(void);
  88. virtual bool Is_Available(int forced=false);
  89. virtual bool Is_Open(void) const;
  90. virtual int Open(char const *filename, int rights=READ);
  91. virtual int Open(int rights=READ);
  92. virtual int Read(void *buffer, int size);
  93. virtual int Seek(int pos, int dir=SEEK_CUR);
  94. virtual int Size(void);
  95. virtual int Write(void const *buffer, int size);
  96. virtual void Close(void);
  97. virtual unsigned long Get_Date_Time(void);
  98. virtual bool Set_Date_Time(unsigned long datetime);
  99. virtual void Error(int error, int canretry = false, char const * filename=NULL);
  100. virtual void Bias(int start, int length=-1);
  101. virtual void * Get_File_Handle(void) { return Handle; }
  102. virtual void Attach (void *handle, int rights=READ);
  103. virtual void Detach (void);
  104. /*
  105. ** These bias values enable a sub-portion of a file to appear as if it
  106. ** were the whole file. This comes in very handy for multi-part files such as
  107. ** mixfiles.
  108. */
  109. int BiasStart;
  110. int BiasLength;
  111. protected:
  112. /*
  113. ** This function returns the largest size a low level DOS read or write may
  114. ** perform. Larger file transfers are performed in chunks of this size or less.
  115. */
  116. int Transfer_Block_Size(void);
  117. int Raw_Seek(int pos, int dir=SEEK_CUR);
  118. void Reset(void);
  119. private:
  120. /*
  121. ** This is the low level DOS handle. A -1 indicates an empty condition.
  122. */
  123. #ifdef _UNIX
  124. FILE* Handle;
  125. #else
  126. void * Handle;
  127. #endif
  128. /*
  129. ** This points to the filename as a NULL terminated string. It may point to either a
  130. ** constant or an allocated string as indicated by the "Allocated" flag.
  131. */
  132. char const * Filename;
  133. //
  134. // file date and time are in the following formats:
  135. //
  136. // date bits 0-4 day (0-31)
  137. // bits 5-8 month (1-12)
  138. // bits 9-15 year (0-119 representing 1980-2099)
  139. //
  140. // time bits 0-4 second/2 (0-29)
  141. // bits 5-10 minutes (0-59)
  142. // bits 11-15 hours (0-23)
  143. //
  144. unsigned short Date;
  145. unsigned short Time;
  146. /*
  147. ** Filenames that were assigned as part of the construction process
  148. ** are not allocated. It is assumed that the filename string is a
  149. ** constant in that case and thus making duplication unnecessary.
  150. ** This value will be non-zero if the filename has be allocated
  151. ** (using strdup()).
  152. */
  153. bool Allocated;
  154. };
  155. /***********************************************************************************************
  156. * RawFileClass::File_Name -- Returns with the filename associate with the file object. *
  157. * *
  158. * Use this routine to determine what filename is associated with this file object. If no *
  159. * filename has yet been assigned, then this routing will return NULL. *
  160. * *
  161. * INPUT: none *
  162. * *
  163. * OUTPUT: Returns with a pointer to the file name associated with this file object or NULL *
  164. * if one doesn't exist. *
  165. * *
  166. * WARNINGS: none *
  167. * *
  168. * HISTORY: *
  169. * 10/18/1994 JLB : Created. *
  170. *=============================================================================================*/
  171. inline char const * RawFileClass::File_Name(void) const
  172. {
  173. return(Filename);
  174. }
  175. #endif