rlm@1: // Windows/FileIO.h
rlm@1: 
rlm@1: #ifndef __WINDOWS_FILEIO_H
rlm@1: #define __WINDOWS_FILEIO_H
rlm@1: 
rlm@1: #include "../Common/Types.h"
rlm@1: 
rlm@1: namespace NWindows {
rlm@1: namespace NFile {
rlm@1: namespace NIO {
rlm@1: 
rlm@1: struct CByHandleFileInfo
rlm@1: {
rlm@1:   DWORD    Attributes;
rlm@1:   FILETIME CTime;
rlm@1:   FILETIME ATime;
rlm@1:   FILETIME MTime;
rlm@1:   DWORD    VolumeSerialNumber;
rlm@1:   UInt64   Size;
rlm@1:   DWORD    NumberOfLinks;
rlm@1:   UInt64   FileIndex;
rlm@1: };
rlm@1: 
rlm@1: class CFileBase
rlm@1: {
rlm@1: protected:
rlm@1:   HANDLE _handle;
rlm@1:   bool Create(LPCTSTR fileName, DWORD desiredAccess,
rlm@1:       DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);
rlm@1:   #ifndef _UNICODE
rlm@1:   bool Create(LPCWSTR fileName, DWORD desiredAccess,
rlm@1:       DWORD shareMode, DWORD creationDisposition,  DWORD flagsAndAttributes);
rlm@1:   #endif
rlm@1: 
rlm@1: public:
rlm@1:   CFileBase(): _handle(INVALID_HANDLE_VALUE){};
rlm@1:   ~CFileBase();
rlm@1: 
rlm@1:   bool Close();
rlm@1: 
rlm@1:   bool GetPosition(UInt64 &position) const;
rlm@1:   bool GetLength(UInt64 &length) const;
rlm@1: 
rlm@1:   bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;
rlm@1:   bool Seek(UInt64 position, UInt64 &newPosition);
rlm@1:   bool SeekToBegin();
rlm@1:   bool SeekToEnd(UInt64 &newPosition);
rlm@1:   
rlm@1:   bool GetFileInformation(CByHandleFileInfo &fileInfo) const;
rlm@1: };
rlm@1: 
rlm@1: class CInFile: public CFileBase
rlm@1: {
rlm@1: public:
rlm@1:   bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
rlm@1:   bool OpenShared(LPCTSTR fileName, bool shareForWrite);
rlm@1:   bool Open(LPCTSTR fileName);
rlm@1:   #ifndef _UNICODE
rlm@1:   bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
rlm@1:   bool OpenShared(LPCWSTR fileName, bool shareForWrite);
rlm@1:   bool Open(LPCWSTR fileName);
rlm@1:   #endif
rlm@1:   bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);
rlm@1:   bool Read(void *data, UInt32 size, UInt32 &processedSize);
rlm@1: };
rlm@1: 
rlm@1: class COutFile: public CFileBase
rlm@1: {
rlm@1:   // DWORD m_CreationDisposition;
rlm@1: public:
rlm@1:   // COutFile(): m_CreationDisposition(CREATE_NEW){};
rlm@1:   bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
rlm@1:   bool Open(LPCTSTR fileName, DWORD creationDisposition);
rlm@1:   bool Create(LPCTSTR fileName, bool createAlways);
rlm@1: 
rlm@1:   #ifndef _UNICODE
rlm@1:   bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
rlm@1:   bool Open(LPCWSTR fileName, DWORD creationDisposition);
rlm@1:   bool Create(LPCWSTR fileName, bool createAlways);
rlm@1:   #endif
rlm@1: 
rlm@1:   /*
rlm@1:   void SetOpenCreationDisposition(DWORD creationDisposition)
rlm@1:     { m_CreationDisposition = creationDisposition; }
rlm@1:   void SetOpenCreationDispositionCreateAlways()
rlm@1:     { m_CreationDisposition = CREATE_ALWAYS; }
rlm@1:   */
rlm@1: 
rlm@1:   bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
rlm@1:   bool SetMTime(const FILETIME *mTime);
rlm@1:   bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);
rlm@1:   bool Write(const void *data, UInt32 size, UInt32 &processedSize);
rlm@1:   bool SetEndOfFile();
rlm@1:   bool SetLength(UInt64 length);
rlm@1: };
rlm@1: 
rlm@1: }}}
rlm@1: 
rlm@1: #endif