file.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef _RAR_FILE_
  2. #define _RAR_FILE_
  3. #ifdef _WIN_ALL
  4. typedef HANDLE FileHandle;
  5. #define BAD_HANDLE INVALID_HANDLE_VALUE
  6. #else
  7. typedef FILE* FileHandle;
  8. #define BAD_HANDLE NULL
  9. #endif
  10. class RAROptions;
  11. enum FILE_HANDLETYPE {FILE_HANDLENORMAL,FILE_HANDLESTD,FILE_HANDLEERR};
  12. enum FILE_ERRORTYPE {FILE_SUCCESS,FILE_NOTFOUND,FILE_READERROR};
  13. struct FileStat
  14. {
  15. uint FileAttr;
  16. uint FileTime;
  17. int64 FileSize;
  18. bool IsDir;
  19. };
  20. class File
  21. {
  22. private:
  23. void AddFileToList(FileHandle hFile);
  24. FileHandle hFile;
  25. bool LastWrite;
  26. FILE_HANDLETYPE HandleType;
  27. bool SkipClose;
  28. bool IgnoreReadErrors;
  29. bool NewFile;
  30. bool AllowDelete;
  31. bool AllowExceptions;
  32. #ifdef _WIN_ALL
  33. bool NoSequentialRead;
  34. #endif
  35. protected:
  36. bool OpenShared;
  37. public:
  38. char FileName[NM];
  39. wchar FileNameW[NM];
  40. FILE_ERRORTYPE ErrorType;
  41. uint CloseCount;
  42. public:
  43. File();
  44. virtual ~File();
  45. void operator = (File &SrcFile);
  46. bool Open(const char *Name,const wchar *NameW=NULL,bool OpenShared=false,bool Update=false);
  47. void TOpen(const char *Name,const wchar *NameW=NULL);
  48. bool WOpen(const char *Name,const wchar *NameW=NULL);
  49. bool Create(const char *Name,const wchar *NameW=NULL,bool ShareRead=true);
  50. void TCreate(const char *Name,const wchar *NameW=NULL,bool ShareRead=true);
  51. bool WCreate(const char *Name,const wchar *NameW=NULL,bool ShareRead=true);
  52. bool Close();
  53. void Flush();
  54. bool Delete();
  55. bool Rename(const char *NewName,const wchar *NewNameW=NULL);
  56. void Write(const void *Data,size_t Size);
  57. int Read(void *Data,size_t Size);
  58. int DirectRead(void *Data,size_t Size);
  59. void Seek(int64 Offset,int Method);
  60. bool RawSeek(int64 Offset,int Method);
  61. int64 Tell();
  62. void Prealloc(int64 Size);
  63. byte GetByte();
  64. void PutByte(byte Byte);
  65. bool Truncate();
  66. void SetOpenFileTime(RarTime *ftm,RarTime *ftc=NULL,RarTime *fta=NULL);
  67. void SetCloseFileTime(RarTime *ftm,RarTime *fta=NULL);
  68. static void SetCloseFileTimeByName(const char *Name,RarTime *ftm,RarTime *fta);
  69. void GetOpenFileTime(RarTime *ft);
  70. bool IsOpened() {return(hFile!=BAD_HANDLE);};
  71. int64 FileLength();
  72. void SetHandleType(FILE_HANDLETYPE Type);
  73. FILE_HANDLETYPE GetHandleType() {return(HandleType);};
  74. bool IsDevice();
  75. void fprintf(const char *fmt,...);
  76. static bool RemoveCreated();
  77. FileHandle GetHandle() {return(hFile);};
  78. void SetIgnoreReadErrors(bool Mode) {IgnoreReadErrors=Mode;};
  79. char *GetName() {return(FileName);}
  80. int64 Copy(File &Dest,int64 Length=INT64NDF);
  81. void SetAllowDelete(bool Allow) {AllowDelete=Allow;}
  82. void SetExceptions(bool Allow) {AllowExceptions=Allow;}
  83. #ifdef _WIN_ALL
  84. void RemoveSequentialFlag() {NoSequentialRead=true;}
  85. #endif
  86. };
  87. #endif