michael@0: // Windows/FileIO.h michael@0: michael@0: #ifndef __WINDOWS_FILEIO_H michael@0: #define __WINDOWS_FILEIO_H michael@0: michael@0: #include "../Common/Types.h" michael@0: michael@0: namespace NWindows { michael@0: namespace NFile { michael@0: namespace NIO { michael@0: michael@0: struct CByHandleFileInfo michael@0: { michael@0: DWORD Attributes; michael@0: FILETIME CreationTime; michael@0: FILETIME LastAccessTime; michael@0: FILETIME LastWriteTime; michael@0: DWORD VolumeSerialNumber; michael@0: UInt64 Size; michael@0: DWORD NumberOfLinks; michael@0: UInt64 FileIndex; michael@0: }; michael@0: michael@0: class CFileBase michael@0: { michael@0: protected: michael@0: bool _fileIsOpen; michael@0: HANDLE _handle; michael@0: bool Create(LPCTSTR fileName, DWORD desiredAccess, michael@0: DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes); michael@0: #ifndef _UNICODE michael@0: bool Create(LPCWSTR fileName, DWORD desiredAccess, michael@0: DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes); michael@0: #endif michael@0: michael@0: public: michael@0: CFileBase(): _fileIsOpen(false){}; michael@0: virtual ~CFileBase(); michael@0: michael@0: virtual bool Close(); michael@0: michael@0: bool GetPosition(UInt64 &position) const; michael@0: bool GetLength(UInt64 &length) const; michael@0: michael@0: bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const; michael@0: bool Seek(UInt64 position, UInt64 &newPosition); michael@0: bool SeekToBegin(); michael@0: bool SeekToEnd(UInt64 &newPosition); michael@0: michael@0: bool GetFileInformation(CByHandleFileInfo &fileInfo) const; michael@0: }; michael@0: michael@0: class CInFile: public CFileBase michael@0: { michael@0: public: michael@0: bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes); michael@0: bool Open(LPCTSTR fileName); michael@0: #ifndef _UNICODE michael@0: bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes); michael@0: bool Open(LPCWSTR fileName); michael@0: #endif michael@0: bool ReadPart(void *data, UInt32 size, UInt32 &processedSize); michael@0: bool Read(void *data, UInt32 size, UInt32 &processedSize); michael@0: }; michael@0: michael@0: class COutFile: public CFileBase michael@0: { michael@0: // DWORD m_CreationDisposition; michael@0: public: michael@0: // COutFile(): m_CreationDisposition(CREATE_NEW){}; michael@0: bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes); michael@0: bool Open(LPCTSTR fileName, DWORD creationDisposition); michael@0: bool Create(LPCTSTR fileName, bool createAlways); michael@0: michael@0: #ifndef _UNICODE michael@0: bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes); michael@0: bool Open(LPCWSTR fileName, DWORD creationDisposition); michael@0: bool Create(LPCWSTR fileName, bool createAlways); michael@0: #endif michael@0: michael@0: /* michael@0: void SetOpenCreationDisposition(DWORD creationDisposition) michael@0: { m_CreationDisposition = creationDisposition; } michael@0: void SetOpenCreationDispositionCreateAlways() michael@0: { m_CreationDisposition = CREATE_ALWAYS; } michael@0: */ michael@0: michael@0: bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime); michael@0: bool SetLastWriteTime(const FILETIME *lastWriteTime); michael@0: bool WritePart(const void *data, UInt32 size, UInt32 &processedSize); michael@0: bool Write(const void *data, UInt32 size, UInt32 &processedSize); michael@0: bool SetEndOfFile(); michael@0: bool SetLength(UInt64 length); michael@0: }; michael@0: michael@0: }}} michael@0: michael@0: #endif