rlm@1
|
1 // Windows/FileIO.h
|
rlm@1
|
2
|
rlm@1
|
3 #ifndef __WINDOWS_FILEIO_H
|
rlm@1
|
4 #define __WINDOWS_FILEIO_H
|
rlm@1
|
5
|
rlm@1
|
6 #include "../Common/Types.h"
|
rlm@1
|
7
|
rlm@1
|
8 namespace NWindows {
|
rlm@1
|
9 namespace NFile {
|
rlm@1
|
10 namespace NIO {
|
rlm@1
|
11
|
rlm@1
|
12 struct CByHandleFileInfo
|
rlm@1
|
13 {
|
rlm@1
|
14 DWORD Attributes;
|
rlm@1
|
15 FILETIME CTime;
|
rlm@1
|
16 FILETIME ATime;
|
rlm@1
|
17 FILETIME MTime;
|
rlm@1
|
18 DWORD VolumeSerialNumber;
|
rlm@1
|
19 UInt64 Size;
|
rlm@1
|
20 DWORD NumberOfLinks;
|
rlm@1
|
21 UInt64 FileIndex;
|
rlm@1
|
22 };
|
rlm@1
|
23
|
rlm@1
|
24 class CFileBase
|
rlm@1
|
25 {
|
rlm@1
|
26 protected:
|
rlm@1
|
27 HANDLE _handle;
|
rlm@1
|
28 bool Create(LPCTSTR fileName, DWORD desiredAccess,
|
rlm@1
|
29 DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
rlm@1
|
30 #ifndef _UNICODE
|
rlm@1
|
31 bool Create(LPCWSTR fileName, DWORD desiredAccess,
|
rlm@1
|
32 DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
rlm@1
|
33 #endif
|
rlm@1
|
34
|
rlm@1
|
35 public:
|
rlm@1
|
36 CFileBase(): _handle(INVALID_HANDLE_VALUE){};
|
rlm@1
|
37 ~CFileBase();
|
rlm@1
|
38
|
rlm@1
|
39 bool Close();
|
rlm@1
|
40
|
rlm@1
|
41 bool GetPosition(UInt64 &position) const;
|
rlm@1
|
42 bool GetLength(UInt64 &length) const;
|
rlm@1
|
43
|
rlm@1
|
44 bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;
|
rlm@1
|
45 bool Seek(UInt64 position, UInt64 &newPosition);
|
rlm@1
|
46 bool SeekToBegin();
|
rlm@1
|
47 bool SeekToEnd(UInt64 &newPosition);
|
rlm@1
|
48
|
rlm@1
|
49 bool GetFileInformation(CByHandleFileInfo &fileInfo) const;
|
rlm@1
|
50 };
|
rlm@1
|
51
|
rlm@1
|
52 class CInFile: public CFileBase
|
rlm@1
|
53 {
|
rlm@1
|
54 public:
|
rlm@1
|
55 bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
rlm@1
|
56 bool OpenShared(LPCTSTR fileName, bool shareForWrite);
|
rlm@1
|
57 bool Open(LPCTSTR fileName);
|
rlm@1
|
58 #ifndef _UNICODE
|
rlm@1
|
59 bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
rlm@1
|
60 bool OpenShared(LPCWSTR fileName, bool shareForWrite);
|
rlm@1
|
61 bool Open(LPCWSTR fileName);
|
rlm@1
|
62 #endif
|
rlm@1
|
63 bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);
|
rlm@1
|
64 bool Read(void *data, UInt32 size, UInt32 &processedSize);
|
rlm@1
|
65 };
|
rlm@1
|
66
|
rlm@1
|
67 class COutFile: public CFileBase
|
rlm@1
|
68 {
|
rlm@1
|
69 // DWORD m_CreationDisposition;
|
rlm@1
|
70 public:
|
rlm@1
|
71 // COutFile(): m_CreationDisposition(CREATE_NEW){};
|
rlm@1
|
72 bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
rlm@1
|
73 bool Open(LPCTSTR fileName, DWORD creationDisposition);
|
rlm@1
|
74 bool Create(LPCTSTR fileName, bool createAlways);
|
rlm@1
|
75
|
rlm@1
|
76 #ifndef _UNICODE
|
rlm@1
|
77 bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
rlm@1
|
78 bool Open(LPCWSTR fileName, DWORD creationDisposition);
|
rlm@1
|
79 bool Create(LPCWSTR fileName, bool createAlways);
|
rlm@1
|
80 #endif
|
rlm@1
|
81
|
rlm@1
|
82 /*
|
rlm@1
|
83 void SetOpenCreationDisposition(DWORD creationDisposition)
|
rlm@1
|
84 { m_CreationDisposition = creationDisposition; }
|
rlm@1
|
85 void SetOpenCreationDispositionCreateAlways()
|
rlm@1
|
86 { m_CreationDisposition = CREATE_ALWAYS; }
|
rlm@1
|
87 */
|
rlm@1
|
88
|
rlm@1
|
89 bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
|
rlm@1
|
90 bool SetMTime(const FILETIME *mTime);
|
rlm@1
|
91 bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);
|
rlm@1
|
92 bool Write(const void *data, UInt32 size, UInt32 &processedSize);
|
rlm@1
|
93 bool SetEndOfFile();
|
rlm@1
|
94 bool SetLength(UInt64 length);
|
rlm@1
|
95 };
|
rlm@1
|
96
|
rlm@1
|
97 }}}
|
rlm@1
|
98
|
rlm@1
|
99 #endif
|