rawfile.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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:: Jani_p $*
  27. * *
  28. * $Modtime:: 11/25/01 11:52a $*
  29. * *
  30. * $Revision:: 10 $*
  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. #include "wwstring.h"
  57. #ifndef WWERROR
  58. #define WWERROR -1
  59. #endif
  60. /*
  61. ** This is the definition of the raw file class. It is derived from the abstract base FileClass
  62. ** and handles the interface to the low level DOS routines. This is the first class in the
  63. ** chain of derived file classes that actually performs a useful function. With this class,
  64. ** I/O is possible. More sophisticated features, such as packed files, CD-ROM support,
  65. ** file caching, and XMS/EMS memory support, are handled by derived classes.
  66. **
  67. ** Of particular importance is the need to override the error routine if more sophisticated
  68. ** error handling is required. This is more than likely if greater functionality is derived
  69. ** from this base class.
  70. */
  71. class RawFileClass : public FileClass
  72. {
  73. typedef FileClass BASECLASS;
  74. public:
  75. /*
  76. ** This is a record of the access rights used to open the file. These rights are
  77. ** used if the file object is duplicated.
  78. */
  79. int Rights;
  80. RawFileClass(char const *filename);
  81. RawFileClass(void);
  82. RawFileClass (RawFileClass const & f);
  83. RawFileClass & operator = (RawFileClass const & f);
  84. virtual ~RawFileClass(void);
  85. virtual char const * File_Name(void) const;
  86. virtual char const * Set_Name(char const *filename);
  87. virtual int Create(void);
  88. virtual int Delete(void);
  89. virtual bool Is_Available(int forced=false);
  90. virtual bool Is_Open(void) const;
  91. virtual int Open(char const *filename, int rights=READ);
  92. virtual int Open(int rights=READ);
  93. virtual int Read(void *buffer, int size);
  94. virtual int Seek(int pos, int dir=SEEK_CUR);
  95. virtual int Size(void);
  96. virtual int Write(void const *buffer, int size);
  97. virtual void Close(void);
  98. virtual unsigned long Get_Date_Time(void);
  99. virtual bool Set_Date_Time(unsigned long datetime);
  100. virtual void Error(int error, int canretry = false, char const * filename=NULL);
  101. virtual void Bias(int start, int length=-1);
  102. virtual void * Get_File_Handle(void) { return Handle; }
  103. virtual void Attach (void *handle, int rights=READ);
  104. virtual void Detach (void);
  105. /*
  106. ** These bias values enable a sub-portion of a file to appear as if it
  107. ** were the whole file. This comes in very handy for multi-part files such as
  108. ** mixfiles.
  109. */
  110. int BiasStart;
  111. int BiasLength;
  112. protected:
  113. /*
  114. ** This function returns the largest size a low level DOS read or write may
  115. ** perform. Larger file transfers are performed in chunks of this size or less.
  116. */
  117. int Transfer_Block_Size(void);
  118. int Raw_Seek(int pos, int dir=SEEK_CUR);
  119. void Reset(void);
  120. private:
  121. /*
  122. ** This is the low level DOS handle. A -1 indicates an empty condition.
  123. */
  124. #ifdef _UNIX
  125. FILE* Handle;
  126. #else
  127. void * Handle;
  128. #endif
  129. StringClass Filename;
  130. //
  131. // file date and time are in the following formats:
  132. //
  133. // date bits 0-4 day (0-31)
  134. // bits 5-8 month (1-12)
  135. // bits 9-15 year (0-119 representing 1980-2099)
  136. //
  137. // time bits 0-4 second/2 (0-29)
  138. // bits 5-10 minutes (0-59)
  139. // bits 11-15 hours (0-23)
  140. //
  141. unsigned short Date;
  142. unsigned short Time;
  143. };
  144. /***********************************************************************************************
  145. * RawFileClass::File_Name -- Returns with the filename associate with the file object. *
  146. * *
  147. * Use this routine to determine what filename is associated with this file object. If no *
  148. * filename has yet been assigned, then this routing will return NULL. *
  149. * *
  150. * INPUT: none *
  151. * *
  152. * OUTPUT: Returns with a pointer to the file name associated with this file object or NULL *
  153. * if one doesn't exist. *
  154. * *
  155. * WARNINGS: none *
  156. * *
  157. * HISTORY: *
  158. * 10/18/1994 JLB : Created. *
  159. * 11/25/2001 Jani: Note that this is virtual function and thus can't be inlined. Is there a *
  160. * reason for it to be virtual? *
  161. *=============================================================================================*/
  162. inline char const * RawFileClass::File_Name(void) const
  163. {
  164. return(Filename);
  165. }
  166. #endif