unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

file.hpp
Go to the documentation of this file.
1#ifndef _RAR_FILE_
2#define _RAR_FILE_
3
4#define FILE_USE_OPEN
5
6#ifdef _WIN_ALL
7 typedef HANDLE FileHandle;
8 #define FILE_BAD_HANDLE INVALID_HANDLE_VALUE
9#elif defined(FILE_USE_OPEN)
10 typedef off_t FileHandle;
11 #define FILE_BAD_HANDLE -1
12#else
13 typedef FILE* FileHandle;
14 #define FILE_BAD_HANDLE NULL
15#endif
16
17class RAROptions;
18
20
22
24 // Request read only access to file. Default for Open.
26
27 // Request both read and write access to file. Default for Create.
29
30 // Request write only access to file.
32
33 // Open files which are already opened for write by other programs.
35
36 // Open files only if no other program is opened it even in shared mode.
38
39 // Provide read access to created file for other programs.
41
42 // Use standard NTFS names without trailing dots and spaces.
44
45 // Mode flags are not defined yet.
47};
48
50 FREM_ASK, // Propose to use the already read part, retry or abort.
51 FREM_TRUNCATE, // Use the already read part without additional prompt.
52 FREM_IGNORE // Try to skip unreadable block and read further.
53};
54
55
56class File
57{
58 private:
62
63 // If we read the user input in console prompts from stdin, we shall
64 // process the available line immediately, not waiting for rest of data.
65 // Otherwise apps piping user responses to multiple Ask() prompts can
66 // hang if no more data is available yet and pipe isn't closed.
67 // If we read RAR archive or other file data from stdin, we shall collect
68 // the entire requested block as long as pipe isn't closed, so we get
69 // complete archive headers, not split between different reads.
71
74 bool NewFile;
77#ifdef _WIN_ALL
78 bool NoSequentialRead;
79 uint CreateMode;
80#endif
83
84 int64 CurFilePos; // Used for forward seeks in stdin files.
85 protected:
86 bool OpenShared; // Set by 'Archive' class.
87 public:
89
91 public:
92 File();
93 virtual ~File();
94 void operator = (File &SrcFile);
95
96 // Several functions below are 'virtual', because they are redefined
97 // by Archive for QOpen and by MultiFile for split files in WinRAR.
98 virtual bool Open(const wchar *Name,uint Mode=FMF_READ);
99 void TOpen(const wchar *Name);
100 bool WOpen(const wchar *Name);
101 bool Create(const wchar *Name,uint Mode=FMF_UPDATE|FMF_SHAREREAD);
102 void TCreate(const wchar *Name,uint Mode=FMF_UPDATE|FMF_SHAREREAD);
103 bool WCreate(const wchar *Name,uint Mode=FMF_UPDATE|FMF_SHAREREAD);
104 virtual bool Close(); // 'virtual' for MultiFile class.
105 bool Delete();
106 bool Rename(const wchar *NewName);
107 bool Write(const void *Data,size_t Size);
108 virtual int Read(void *Data,size_t Size);
109 int DirectRead(void *Data,size_t Size);
110 virtual void Seek(int64 Offset,int Method);
111 bool RawSeek(int64 Offset,int Method);
112 virtual int64 Tell();
113 void Prealloc(int64 Size);
114 byte GetByte();
115 void PutByte(byte Byte);
116 bool Truncate();
117 void Flush();
118 void SetOpenFileTime(RarTime *ftm,RarTime *ftc=NULL,RarTime *fta=NULL);
119 void SetCloseFileTime(RarTime *ftm,RarTime *fta=NULL);
120 static void SetCloseFileTimeByName(const wchar *Name,RarTime *ftm,RarTime *fta);
121 void GetOpenFileTime(RarTime *ft);
122 virtual bool IsOpened() {return hFile!=FILE_BAD_HANDLE;} // 'virtual' for MultiFile class.
125 void SetLineInputMode(bool Mode) {LineInput=Mode;}
128 bool IsDevice();
129 static bool RemoveCreated();
131 void SetHandle(FileHandle Handle) {Close();hFile=Handle;}
133 int64 Copy(File &Dest,int64 Length=INT64NDF);
134 void SetAllowDelete(bool Allow) {AllowDelete=Allow;}
135 void SetExceptions(bool Allow) {AllowExceptions=Allow;}
136 void SetPreserveAtime(bool Preserve) {PreserveAtime=Preserve;}
138#ifdef _UNIX
139 int GetFD()
140 {
141#ifdef FILE_USE_OPEN
142 return hFile;
143#else
144 return fileno(hFile);
145#endif
146 }
147#endif
148 static size_t CopyBufferSize()
149 {
150#ifdef _WIN_ALL
151 // USB flash performance is poor with 64 KB buffer, 256+ KB resolved it.
152 // For copying from HDD to same HDD the best performance was with 256 KB
153 // buffer in XP and with 1 MB buffer in Win10.
154 return WinNT()==WNT_WXP ? 0x40000:0x100000;
155#else
156 return 0x100000;
157#endif
158 }
159};
160
161#endif
Definition: file.hpp:57
FileHandle hFile
Definition: file.hpp:59
virtual void Seek(int64 Offset, int Method)
Definition: file.cpp:514
bool Truncate()
Definition: file.cpp:640
void SetHandleType(FILE_HANDLETYPE Type)
Definition: file.hpp:124
static size_t CopyBufferSize()
Definition: file.hpp:148
virtual bool IsOpened()
Definition: file.hpp:122
bool AllowDelete
Definition: file.hpp:75
void GetOpenFileTime(RarTime *ft)
Definition: file.cpp:735
void Flush()
Definition: file.cpp:650
int64 FileLength()
Definition: file.cpp:750
void SetReadErrorMode(FILE_READ_ERROR_MODE Mode)
Definition: file.hpp:132
bool LineInput
Definition: file.hpp:70
int64 CurFilePos
Definition: file.hpp:84
void PutByte(byte Byte)
Definition: file.cpp:634
bool Create(const wchar *Name, uint Mode=FMF_UPDATE|FMF_SHAREREAD)
Definition: file.cpp:176
bool Write(const void *Data, size_t Size)
Definition: file.cpp:298
bool PreserveAtime
Definition: file.hpp:81
virtual int Read(void *Data, size_t Size)
Definition: file.cpp:374
bool AllowExceptions
Definition: file.hpp:76
bool IsTruncatedAfterReadError()
Definition: file.hpp:137
FILE_HANDLETYPE HandleType
Definition: file.hpp:61
bool IsSeekable()
Definition: file.hpp:127
void SetCloseFileTime(RarTime *ftm, RarTime *fta=NULL)
Definition: file.cpp:687
bool LastWrite
Definition: file.hpp:60
bool OpenShared
Definition: file.hpp:86
bool Rename(const wchar *NewName)
Definition: file.cpp:283
static void SetCloseFileTimeByName(const wchar *Name, RarTime *ftm, RarTime *fta)
Definition: file.cpp:701
static bool RemoveCreated()
bool IsDevice()
Definition: file.cpp:760
bool Delete()
Definition: file.cpp:271
virtual bool Open(const wchar *Name, uint Mode=FMF_READ)
Definition: file.cpp:48
void SetHandle(FileHandle Handle)
Definition: file.hpp:131
FILE_HANDLETYPE GetHandleType()
Definition: file.hpp:126
virtual int64 Tell()
Definition: file.cpp:576
void SetOpenFileTime(RarTime *ftm, RarTime *ftc=NULL, RarTime *fta=NULL)
Definition: file.cpp:663
void Prealloc(int64 Size)
Definition: file.cpp:606
byte GetByte()
Definition: file.cpp:626
bool SkipClose
Definition: file.hpp:72
void SetExceptions(bool Allow)
Definition: file.hpp:135
wchar FileName[NM]
Definition: file.hpp:88
int64 Copy(File &Dest, int64 Length=INT64NDF)
Definition: file.cpp:774
bool NewFile
Definition: file.hpp:74
virtual ~File()
Definition: file.cpp:26
void SetLineInputMode(bool Mode)
Definition: file.hpp:125
bool WCreate(const wchar *Name, uint Mode=FMF_UPDATE|FMF_SHAREREAD)
Definition: file.cpp:232
void SetAllowDelete(bool Allow)
Definition: file.hpp:134
virtual bool Close()
Definition: file.cpp:241
bool WOpen(const wchar *Name)
Definition: file.cpp:167
bool TruncatedAfterReadError
Definition: file.hpp:82
int DirectRead(void *Data, size_t Size)
Definition: file.cpp:448
bool RawSeek(int64 Offset, int Method)
Definition: file.cpp:521
File()
Definition: file.cpp:3
FileHandle GetHandle()
Definition: file.hpp:130
void SetPreserveAtime(bool Preserve)
Definition: file.hpp:136
FILE_READ_ERROR_MODE ReadErrorMode
Definition: file.hpp:73
void TOpen(const wchar *Name)
Definition: file.cpp:159
void TCreate(const wchar *Name, uint Mode=FMF_UPDATE|FMF_SHAREREAD)
Definition: file.cpp:224
void operator=(File &SrcFile)
Definition: file.cpp:36
FILE_ERRORTYPE ErrorType
Definition: file.hpp:90
FILE_HANDLETYPE
Definition: file.hpp:19
@ FILE_HANDLESTD
Definition: file.hpp:19
@ FILE_HANDLENORMAL
Definition: file.hpp:19
#define FILE_BAD_HANDLE
Definition: file.hpp:11
FILE_MODE_FLAGS
Definition: file.hpp:23
@ FMF_WRITE
Definition: file.hpp:31
@ FMF_STANDARDNAMES
Definition: file.hpp:43
@ FMF_SHAREREAD
Definition: file.hpp:40
@ FMF_UNDEFINED
Definition: file.hpp:46
@ FMF_OPENSHARED
Definition: file.hpp:34
@ FMF_OPENEXCLUSIVE
Definition: file.hpp:37
@ FMF_UPDATE
Definition: file.hpp:28
@ FMF_READ
Definition: file.hpp:25
FILE_ERRORTYPE
Definition: file.hpp:21
@ FILE_READERROR
Definition: file.hpp:21
@ FILE_NOTFOUND
Definition: file.hpp:21
@ FILE_SUCCESS
Definition: file.hpp:21
off_t FileHandle
Definition: file.hpp:10
FILE_READ_ERROR_MODE
Definition: file.hpp:49
@ FREM_IGNORE
Definition: file.hpp:52
@ FREM_TRUNCATE
Definition: file.hpp:51
@ FREM_ASK
Definition: file.hpp:50
DWORD WinNT()
Definition: isnt.cpp:3
@ WNT_WXP
Definition: isnt.hpp:6
#define INT64NDF
Definition: rartypes.hpp:30
wchar_t wchar
Definition: rartypes.hpp:13
int64_t int64
Definition: rartypes.hpp:12
unsigned int uint
Definition: rartypes.hpp:8