123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- //---------------------------------------------------------------------------
- //
- // ffile.h - This file contains the class declaration for FastFile
- //
- // This class will catch a fileOpen and try to find the file in the FastFiles
- // open before allowing the call to go through to the system
- //
- //---------------------------------------------------------------------------//
- // Copyright (C) Microsoft Corporation. All rights reserved. //
- //===========================================================================//
- #ifndef FFILE_H
- #define FFILE_H
- //---------------------------------------------------------------------------
- // Include files
- #ifndef DSTD_H
- #include <dstd.h>
- #endif
- #ifndef FILE_H
- #include <file.h>
- #endif
- #include <sys\types.h>
- #include <sys\stat.h>
- //---------------------------------------------------------------------------
- #define MAX_FILENAME_SIZE 250
- #define FASTFILE_VERSION 0xCADDECAF
- #define FASTFILE_VERSION_LZ 0xFADDECAF
- #pragma pack(1)
- typedef struct
- {
- long offset;
- long size; //LZ Compressed Size
- long realSize; //Uncompressed Size
- DWORD hash; //Hash Compare to weed out stinky files faster then StrCmp
- char name[MAX_FILENAME_SIZE];
- } FILEENTRY;
- #pragma pack()
- typedef struct
- {
- long inuse;
- long pos;
- FILEENTRY *pfe;
- } FILE_HANDLE;
- //---------------------------------------------------------------------------
- // Class FastFile
- class FastFile
- {
- protected:
- long numFiles;
- FILE_HANDLE *files;
- char *fileName;
- FILE *handle;
- unsigned long length;
- unsigned long logicalPosition;
- bool useLZCompress;
- public:
- FastFile (void);
- ~FastFile (void);
- void *operator new (size_t mySize);
- void operator delete (void *us);
- long open (char* fName);
- void close (void);
- bool isOpen (void)
- {
- return (handle != NULL);
- }
- long fileSize (void)
- {
- if (isOpen() && (length == 0))
- {
- struct _stat st;
- _stat(fileName,&st);
- length = st.st_size;
- }
- return length;
- }
- long getNumFiles (void)
- {
- return numFiles;
- }
- long openFast (DWORD hash, char *fName);
- void closeFast (long localHandle);
- long seekFast (long fastFileHandle, long off, long from = SEEK_SET);
- long readFast (long fastFileHandle, void *bfr, long size);
- long readFastRAW (long fastFileHandle, void *bfr, long size);
- long tellFast (long fastFileHandle);
- long sizeFast (long fastFileHandle);
- long lzSizeFast (long fastFileHandle);
- bool isLZCompressed (void)
- {
- return useLZCompress;
- }
- };
- //---------------------------------------------------------------------------
- extern FastFile **fastFiles;
- extern long numFastFiles;
- extern long maxFastFiles;
- //---------------------------------------------------------------------------
- #endif
|