123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- #ifndef _RAR_FILE_
- #define _RAR_FILE_
- #define FILE_USE_OPEN
- #ifdef _WIN_ALL
- typedef HANDLE FileHandle;
- #define FILE_BAD_HANDLE INVALID_HANDLE_VALUE
- #elif defined(FILE_USE_OPEN)
- typedef off_t FileHandle;
- #define FILE_BAD_HANDLE -1
- #else
- typedef FILE* FileHandle;
- #define FILE_BAD_HANDLE NULL
- #endif
- class RAROptions;
- enum FILE_HANDLETYPE {FILE_HANDLENORMAL,FILE_HANDLESTD};
- enum FILE_ERRORTYPE {FILE_SUCCESS,FILE_NOTFOUND,FILE_READERROR};
- enum FILE_MODE_FLAGS {
-
- FMF_READ=0,
-
- FMF_UPDATE=1,
-
- FMF_WRITE=2,
-
- FMF_OPENSHARED=4,
-
- FMF_OPENEXCLUSIVE=8,
-
- FMF_SHAREREAD=16,
-
- FMF_STANDARDNAMES=32,
-
- FMF_UNDEFINED=256
- };
- enum FILE_READ_ERROR_MODE {
- FREM_ASK,
- FREM_TRUNCATE,
- FREM_IGNORE
- };
- class File
- {
- private:
- FileHandle hFile;
- bool LastWrite;
- FILE_HANDLETYPE HandleType;
-
-
-
-
-
-
-
-
- bool LineInput;
- bool SkipClose;
- FILE_READ_ERROR_MODE ReadErrorMode;
- bool NewFile;
- bool AllowDelete;
- bool AllowExceptions;
- #ifdef _WIN_ALL
- bool NoSequentialRead;
- uint CreateMode;
- #endif
- bool PreserveAtime;
- bool TruncatedAfterReadError;
- int64 CurFilePos;
- protected:
- bool OpenShared;
- public:
- wchar FileName[NM];
- FILE_ERRORTYPE ErrorType;
- public:
- File();
- virtual ~File();
- void operator = (File &SrcFile);
-
-
- virtual bool Open(const wchar *Name,uint Mode=FMF_READ);
- void TOpen(const wchar *Name);
- bool WOpen(const wchar *Name);
- bool Create(const wchar *Name,uint Mode=FMF_UPDATE|FMF_SHAREREAD);
- void TCreate(const wchar *Name,uint Mode=FMF_UPDATE|FMF_SHAREREAD);
- bool WCreate(const wchar *Name,uint Mode=FMF_UPDATE|FMF_SHAREREAD);
- virtual bool Close();
- bool Delete();
- bool Rename(const wchar *NewName);
- bool Write(const void *Data,size_t Size);
- virtual int Read(void *Data,size_t Size);
- int DirectRead(void *Data,size_t Size);
- virtual void Seek(int64 Offset,int Method);
- bool RawSeek(int64 Offset,int Method);
- virtual int64 Tell();
- void Prealloc(int64 Size);
- byte GetByte();
- void PutByte(byte Byte);
- bool Truncate();
- void Flush();
- void SetOpenFileTime(RarTime *ftm,RarTime *ftc=NULL,RarTime *fta=NULL);
- void SetCloseFileTime(RarTime *ftm,RarTime *fta=NULL);
- static void SetCloseFileTimeByName(const wchar *Name,RarTime *ftm,RarTime *fta);
- void GetOpenFileTime(RarTime *ft);
- virtual bool IsOpened() {return hFile!=FILE_BAD_HANDLE;}
- int64 FileLength();
- void SetHandleType(FILE_HANDLETYPE Type) {HandleType=Type;}
- void SetLineInputMode(bool Mode) {LineInput=Mode;}
- FILE_HANDLETYPE GetHandleType() {return HandleType;}
- bool IsSeekable() {return HandleType!=FILE_HANDLESTD;}
- bool IsDevice();
- static bool RemoveCreated();
- FileHandle GetHandle() {return hFile;}
- void SetHandle(FileHandle Handle) {Close();hFile=Handle;}
- void SetReadErrorMode(FILE_READ_ERROR_MODE Mode) {ReadErrorMode=Mode;}
- int64 Copy(File &Dest,int64 Length=INT64NDF);
- void SetAllowDelete(bool Allow) {AllowDelete=Allow;}
- void SetExceptions(bool Allow) {AllowExceptions=Allow;}
- void SetPreserveAtime(bool Preserve) {PreserveAtime=Preserve;}
- bool IsTruncatedAfterReadError() {return TruncatedAfterReadError;}
- #ifdef _UNIX
- int GetFD()
- {
- #ifdef FILE_USE_OPEN
- return hFile;
- #else
- return fileno(hFile);
- #endif
- }
- #endif
- static size_t CopyBufferSize()
- {
- #ifdef _WIN_ALL
-
-
-
- return WinNT()==WNT_WXP ? 0x40000:0x100000;
- #else
- return 0x100000;
- #endif
- }
- };
- #endif
|