file.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. //---------------------------------------------------------------------------
  2. //
  3. // file.h - This file contains the class declaration for File
  4. //
  5. // The File class simply calls the Windows 32bit file functions.
  6. // It is purely a wrapper.
  7. //
  8. // The mmFile Class is a wrapper for the Win32 Memory Mapped
  9. // file functionality. It is used exactly the same as above class.
  10. //
  11. //---------------------------------------------------------------------------//
  12. // Copyright (C) Microsoft Corporation. All rights reserved. //
  13. //===========================================================================//
  14. #ifndef FILE_H
  15. #define FILE_H
  16. //---------------------------------------------------------------------------
  17. // Include files
  18. #ifndef DSTD_H
  19. #include "dstd.h"
  20. #endif
  21. #ifndef DFILE_H
  22. #include "dfile.h"
  23. #endif
  24. #ifndef DFFILE_H
  25. #include "dffile.h"
  26. #endif
  27. #ifndef HEAP_H
  28. #include "heap.h"
  29. #endif
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <fcntl.h>
  33. //---------------------------------------------------------------------------
  34. // Enums
  35. enum FileMode
  36. {
  37. NOMODE = 0,
  38. READ,
  39. CREATE,
  40. MC2_APPEND,
  41. WRITE,
  42. RDWRITE
  43. };
  44. enum FileClass
  45. {
  46. BASEFILE = 0,
  47. INIFILE,
  48. PACKETFILE,
  49. CSVFILE
  50. };
  51. //---------------------------------------------------------------------------
  52. // Function Declarations
  53. //Returns 1 if file is on HardDrive and 2 if file is in FastFile
  54. long fileExists(char *fName);
  55. long fileExistsOnCD(char *fName);
  56. bool file1OlderThan2(char *file1, char* file2);
  57. //---------------------------------------------------------------------------
  58. // Macro Definitions
  59. #ifndef NO_ERR
  60. #define NO_ERR 0x00000000
  61. #endif
  62. #define DISK_FULL_ERR 0xBADF0001
  63. #define SHARE_ERR 0xBADF0002
  64. #define FILE_NOT_FOUND_ERR 0xBADF0003
  65. #define PACKET_OUT_OF_RANGE 0xBADF0004
  66. #define PACKET_WRONG_SIZE 0xBADF0005
  67. #define READ_ONLY_ERR 0xBADF0006
  68. #define TOO_MANY_FILES_ERR 0xBADF0007
  69. #define READ_PAST_EOF_ERR 0xBADF0008
  70. #define INVALID_SEEK_ERR 0xBADF0009
  71. #define BAD_WRITE_ERR 0xBADF000A
  72. #define BAD_PACKET_VERSION 0xBADF000B
  73. #define NO_RAM_FOR_SEEK_TABLE 0xBADF000C
  74. #define NO_RAM_FOR_FILENAME 0xBADF000D
  75. #define PARENT_NULL 0xBADF000E
  76. #define TOO_MANY_CHILDREN 0xBADF000F
  77. #define FILE_NOT_OPEN 0xBADF0010
  78. #define CANT_WRITE_TO_CHILD 0xBADF0011
  79. #define NO_RAM_FOR_CHILD_LIST 0xBADF0012
  80. #define MAPPED_WRITE_NOT_SUPPORTED 0xBADF0013
  81. #define COULD_NOT_MAP_FILE 0xBADF0014
  82. //---------------------------------------------------------------------------
  83. // File
  84. //---------------------------------------------------------------------------
  85. class File
  86. {
  87. // Data Members
  88. //--------------
  89. protected:
  90. char *fileName;
  91. FileMode fileMode;
  92. long handle;
  93. FastFilePtr fastFile;
  94. long fastFileHandle;
  95. unsigned long length;
  96. unsigned long logicalPosition;
  97. unsigned long bufferResult;
  98. FilePtr *childList;
  99. unsigned long numChildren;
  100. unsigned long maxChildren;
  101. FilePtr parent;
  102. unsigned long parentOffset;
  103. unsigned long physicalLength;
  104. bool inRAM;
  105. MemoryPtr fileImage;
  106. public:
  107. static bool logFileTraffic;
  108. static unsigned long lastError;
  109. // Member Functions
  110. //------------------
  111. protected:
  112. void setup (void);
  113. public:
  114. void *operator new (size_t mySize);
  115. void operator delete (void *us);
  116. File (void);
  117. ~File (void);
  118. bool eof (void);
  119. virtual long open ( const char* fName, FileMode _mode = READ, long numChildren = 50);
  120. virtual long open( const char* buffer, int bufferLength ); // for streaming from memory
  121. virtual long create (const char* fName);
  122. virtual long createWithCase( char* fName ); // don't strlwr for me please!
  123. virtual void close (void);
  124. virtual long open (File *_parent, unsigned long fileSize, long numChildren = 50);
  125. void deleteFile (void);
  126. long seek (long pos, long from = SEEK_SET);
  127. void seekEnd (void);
  128. void skip (long bytesToSkip);
  129. long read (unsigned long pos, MemoryPtr buffer, long length);
  130. long read (MemoryPtr buffer, long length);
  131. //Used to dig the LZ data directly out of the fastfiles.
  132. // For textures.
  133. long readRAW (unsigned long * &buffer, UserHeapPtr heap);
  134. unsigned char readByte (void);
  135. short readWord (void);
  136. short readShort (void);
  137. long readLong (void);
  138. float readFloat( void );
  139. long readString (MemoryPtr buffer);
  140. long readLine (MemoryPtr buffer, long maxLength);
  141. long readLineEx (MemoryPtr buffer, long maxLength);
  142. long write (unsigned long pos, MemoryPtr buffer, long bytes);
  143. long write (MemoryPtr buffer, long bytes);
  144. long writeByte (unsigned char value);
  145. long writeWord (short value);
  146. long writeShort (short value);
  147. long writeLong (long value);
  148. long writeFloat (float value);
  149. long writeString (char *buffer);
  150. long writeLine (char *buffer);
  151. bool isOpen (void);
  152. virtual FileClass getFileClass (void)
  153. {
  154. return BASEFILE;
  155. }
  156. char* getFilename (void);
  157. unsigned long getLength (void);
  158. unsigned long fileSize (void);
  159. unsigned long getNumLines (void);
  160. unsigned long getLastError (void) {
  161. return(lastError);
  162. }
  163. unsigned long getLogicalPosition (void)
  164. {
  165. return logicalPosition;
  166. }
  167. FilePtr getParent (void)
  168. {
  169. return parent;
  170. }
  171. FileMode getFileMode (void)
  172. {
  173. return(fileMode);
  174. }
  175. long getFileHandle (void)
  176. {
  177. return(handle);
  178. }
  179. time_t getFileMTime (void);
  180. long addChild (FilePtr child);
  181. void removeChild (FilePtr child);
  182. };
  183. //---------------------------------------------------------------------------
  184. //---------------------------------------------------------------------------
  185. #endif
  186. //---------------------------------------------------------------------------
  187. //
  188. // Edit Log
  189. //
  190. //
  191. //---------------------------------------------------------------------------