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