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