ffile.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //---------------------------------------------------------------------------
  2. //
  3. // ffile.h - This file contains the class declaration for FastFile
  4. //
  5. // This class will catch a fileOpen and try to find the file in the FastFiles
  6. // open before allowing the call to go through to the system
  7. //
  8. //---------------------------------------------------------------------------//
  9. // Copyright (C) Microsoft Corporation. All rights reserved. //
  10. //===========================================================================//
  11. #ifndef FFILE_H
  12. #define FFILE_H
  13. //---------------------------------------------------------------------------
  14. // Include files
  15. #ifndef DSTD_H
  16. #include <dstd.h>
  17. #endif
  18. #ifndef FILE_H
  19. #include <file.h>
  20. #endif
  21. #include <sys\types.h>
  22. #include <sys\stat.h>
  23. //---------------------------------------------------------------------------
  24. #define MAX_FILENAME_SIZE 250
  25. #define FASTFILE_VERSION 0xCADDECAF
  26. #define FASTFILE_VERSION_LZ 0xFADDECAF
  27. #pragma pack(1)
  28. typedef struct
  29. {
  30. long offset;
  31. long size; //LZ Compressed Size
  32. long realSize; //Uncompressed Size
  33. DWORD hash; //Hash Compare to weed out stinky files faster then StrCmp
  34. char name[MAX_FILENAME_SIZE];
  35. } FILEENTRY;
  36. #pragma pack()
  37. typedef struct
  38. {
  39. long inuse;
  40. long pos;
  41. FILEENTRY *pfe;
  42. } FILE_HANDLE;
  43. //---------------------------------------------------------------------------
  44. // Class FastFile
  45. class FastFile
  46. {
  47. protected:
  48. long numFiles;
  49. FILE_HANDLE *files;
  50. char *fileName;
  51. FILE *handle;
  52. unsigned long length;
  53. unsigned long logicalPosition;
  54. bool useLZCompress;
  55. public:
  56. FastFile (void);
  57. ~FastFile (void);
  58. void *operator new (size_t mySize);
  59. void operator delete (void *us);
  60. long open (char* fName);
  61. void close (void);
  62. bool isOpen (void)
  63. {
  64. return (handle != NULL);
  65. }
  66. long fileSize (void)
  67. {
  68. if (isOpen() && (length == 0))
  69. {
  70. struct _stat st;
  71. _stat(fileName,&st);
  72. length = st.st_size;
  73. }
  74. return length;
  75. }
  76. long getNumFiles (void)
  77. {
  78. return numFiles;
  79. }
  80. long openFast (DWORD hash, char *fName);
  81. void closeFast (long localHandle);
  82. long seekFast (long fastFileHandle, long off, long from = SEEK_SET);
  83. long readFast (long fastFileHandle, void *bfr, long size);
  84. long readFastRAW (long fastFileHandle, void *bfr, long size);
  85. long tellFast (long fastFileHandle);
  86. long sizeFast (long fastFileHandle);
  87. long lzSizeFast (long fastFileHandle);
  88. bool isLZCompressed (void)
  89. {
  90. return useLZCompress;
  91. }
  92. };
  93. //---------------------------------------------------------------------------
  94. extern FastFile **fastFiles;
  95. extern long numFastFiles;
  96. extern long maxFastFiles;
  97. //---------------------------------------------------------------------------
  98. #endif