1// FileStreams.h
2
3#ifndef __FILESTREAMS_H
4#define __FILESTREAMS_H
5
6#ifdef _WIN32
7#define USE_WIN_FILE
8#endif
9
10#ifdef USE_WIN_FILE
11#include "../../Windows/FileIO.h"
12#else
13#include "../../Common/C_FileIO.h"
14#endif
15
16#include "../../Common/MyCom.h"
17
18#include "../IStream.h"
19
20class CInFileStream:
21  public IInStream,
22  public IStreamGetSize,
23  public CMyUnknownImp
24{
25public:
26  #ifdef USE_WIN_FILE
27  NWindows::NFile::NIO::CInFile File;
28  #ifdef SUPPORT_DEVICE_FILE
29  UInt64 VirtPos;
30  UInt64 PhyPos;
31  UInt64 BufferStartPos;
32  Byte *Buffer;
33  UInt32 BufferSize;
34  #endif
35  #else
36  NC::NFile::NIO::CInFile File;
37  #endif
38  virtual ~CInFileStream();
39
40  #ifdef SUPPORT_DEVICE_FILE
41  CInFileStream();
42  #endif
43
44  bool Open(LPCTSTR fileName);
45  #ifdef USE_WIN_FILE
46  #ifndef _UNICODE
47  bool Open(LPCWSTR fileName);
48  #endif
49  #endif
50
51  bool OpenShared(LPCTSTR fileName, bool shareForWrite);
52  #ifdef USE_WIN_FILE
53  #ifndef _UNICODE
54  bool OpenShared(LPCWSTR fileName, bool shareForWrite);
55  #endif
56  #endif
57
58  MY_UNKNOWN_IMP2(IInStream, IStreamGetSize)
59
60  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
61  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
62
63  STDMETHOD(GetSize)(UInt64 *size);
64};
65
66class CStdInFileStream:
67  public ISequentialInStream,
68  public CMyUnknownImp
69{
70public:
71  MY_UNKNOWN_IMP
72
73  virtual ~CStdInFileStream() {}
74  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
75};
76
77class COutFileStream:
78  public IOutStream,
79  public CMyUnknownImp
80{
81  #ifdef USE_WIN_FILE
82  NWindows::NFile::NIO::COutFile File;
83  #else
84  NC::NFile::NIO::COutFile File;
85  #endif
86public:
87  virtual ~COutFileStream() {}
88  bool Create(LPCTSTR fileName, bool createAlways)
89  {
90    ProcessedSize = 0;
91    return File.Create(fileName, createAlways);
92  }
93  bool Open(LPCTSTR fileName, DWORD creationDisposition)
94  {
95    ProcessedSize = 0;
96    return File.Open(fileName, creationDisposition);
97  }
98  #ifdef USE_WIN_FILE
99  #ifndef _UNICODE
100  bool Create(LPCWSTR fileName, bool createAlways)
101  {
102    ProcessedSize = 0;
103    return File.Create(fileName, createAlways);
104  }
105  bool Open(LPCWSTR fileName, DWORD creationDisposition)
106  {
107    ProcessedSize = 0;
108    return File.Open(fileName, creationDisposition);
109  }
110  #endif
111  #endif
112
113  HRESULT Close();
114
115  UInt64 ProcessedSize;
116
117  #ifdef USE_WIN_FILE
118  bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)
119  {
120    return File.SetTime(cTime, aTime, mTime);
121  }
122  bool SetMTime(const FILETIME *mTime) {  return File.SetMTime(mTime); }
123  #endif
124
125
126  MY_UNKNOWN_IMP1(IOutStream)
127
128  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
129  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
130  STDMETHOD(SetSize)(UInt64 newSize);
131};
132
133class CStdOutFileStream:
134  public ISequentialOutStream,
135  public CMyUnknownImp
136{
137public:
138  MY_UNKNOWN_IMP
139
140  virtual ~CStdOutFileStream() {}
141  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
142};
143
144#endif
145