other-licenses/7zstub/src/Windows/FileIO.h

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

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

mercurial