00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __FILE_H
00021 #define __FILE_H
00022
00023 #include <windows.h>
00024
00025 namespace extfile
00026 {
00028
00030 class FileWrapper
00031 {
00033 HANDLE hFile;
00035 char filename[1024];
00036
00037 public:
00039 enum {
00040 READ = 1,
00041 WRITE = 2
00042 };
00043
00044 public:
00046 FileWrapper()
00047 {
00048 hFile=NULL;
00049 }
00051 ~FileWrapper()
00052 {
00053 close();
00054 }
00056
00060 bool open(const char *fname, Int32 mode)
00061 {
00062 strcpy(filename,fname);
00063
00064 if(mode==WRITE)
00065 DeleteFile(fname);
00066 hFile=CreateFile(fname,((mode&READ) ? GENERIC_READ : 0) | ((mode&WRITE) ? GENERIC_WRITE : 0),0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
00067 return hFile!=INVALID_HANDLE_VALUE;
00068 }
00070 void close(bool destroy=false)
00071 {
00072 if(hFile)
00073 {
00074 CloseHandle(hFile);
00075 hFile=NULL;
00076 if(destroy)
00077 DeleteFile(filename);
00078 }
00079 }
00081
00085 bool read(void *data, Int32 len)
00086 {
00087 DWORD br;
00088 ReadFile(hFile,data,len,&br,NULL);
00089 return true;
00090 }
00092
00096 bool write(void *data, Int32 len)
00097 {
00098 DWORD br;
00099 WriteFile(hFile,data,len,&br,NULL);
00100 return true;
00101 }
00103
00106 void seek(Int64 pos)
00107 {
00108 union {
00109 struct { DWORD lp; LONG hp; };
00110 LONGLONG qp;
00111 } p;
00112 p.qp=pos;
00113 SetFilePointer(hFile,p.lp,&p.hp,FILE_BEGIN);
00114 }
00115 };
00116 }
00117
00118
00119 #endif
00120