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