OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fgas/crt/fgas_stream.h" | 7 #include "xfa/fgas/crt/fgas_stream.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
11 #include "xfa/fgas/crt/fgas_codepage.h" | 11 #include "xfa/fgas/crt/fgas_codepage.h" |
12 #include "xfa/fgas/crt/fgas_system.h" | 12 #include "xfa/fgas/crt/fgas_system.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 class CFX_StreamImp { | 16 class CFX_StreamImp { |
17 public: | 17 public: |
18 virtual void Release() { delete this; } | 18 virtual void Release() { delete this; } |
19 virtual FX_DWORD GetAccessModes() const { return m_dwAccess; } | 19 virtual uint32_t GetAccessModes() const { return m_dwAccess; } |
20 virtual int32_t GetLength() const = 0; | 20 virtual int32_t GetLength() const = 0; |
21 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; | 21 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset) = 0; |
22 virtual int32_t GetPosition() = 0; | 22 virtual int32_t GetPosition() = 0; |
23 virtual FX_BOOL IsEOF() const = 0; | 23 virtual FX_BOOL IsEOF() const = 0; |
24 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; | 24 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) = 0; |
25 virtual int32_t ReadString(FX_WCHAR* pStr, | 25 virtual int32_t ReadString(FX_WCHAR* pStr, |
26 int32_t iMaxLength, | 26 int32_t iMaxLength, |
27 FX_BOOL& bEOS) = 0; | 27 FX_BOOL& bEOS) = 0; |
28 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; | 28 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) = 0; |
29 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; | 29 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) = 0; |
30 virtual void Flush() = 0; | 30 virtual void Flush() = 0; |
31 virtual FX_BOOL SetLength(int32_t iLength) = 0; | 31 virtual FX_BOOL SetLength(int32_t iLength) = 0; |
32 | 32 |
33 protected: | 33 protected: |
34 CFX_StreamImp(); | 34 CFX_StreamImp(); |
35 virtual ~CFX_StreamImp() {} | 35 virtual ~CFX_StreamImp() {} |
36 FX_DWORD m_dwAccess; | 36 uint32_t m_dwAccess; |
37 }; | 37 }; |
38 | 38 |
39 class CFX_FileStreamImp : public CFX_StreamImp { | 39 class CFX_FileStreamImp : public CFX_StreamImp { |
40 public: | 40 public: |
41 CFX_FileStreamImp(); | 41 CFX_FileStreamImp(); |
42 virtual ~CFX_FileStreamImp(); | 42 virtual ~CFX_FileStreamImp(); |
43 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, FX_DWORD dwAccess); | 43 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); |
44 virtual int32_t GetLength() const; | 44 virtual int32_t GetLength() const; |
45 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 45 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); |
46 virtual int32_t GetPosition(); | 46 virtual int32_t GetPosition(); |
47 virtual FX_BOOL IsEOF() const; | 47 virtual FX_BOOL IsEOF() const; |
48 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 48 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); |
49 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); | 49 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); |
50 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 50 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); |
51 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 51 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); |
52 virtual void Flush(); | 52 virtual void Flush(); |
53 virtual FX_BOOL SetLength(int32_t iLength); | 53 virtual FX_BOOL SetLength(int32_t iLength); |
54 | 54 |
55 protected: | 55 protected: |
56 FXSYS_FILE* m_hFile; | 56 FXSYS_FILE* m_hFile; |
57 int32_t m_iLength; | 57 int32_t m_iLength; |
58 }; | 58 }; |
59 | 59 |
60 class CFX_BufferStreamImp : public CFX_StreamImp { | 60 class CFX_BufferStreamImp : public CFX_StreamImp { |
61 public: | 61 public: |
62 CFX_BufferStreamImp(); | 62 CFX_BufferStreamImp(); |
63 virtual ~CFX_BufferStreamImp() {} | 63 virtual ~CFX_BufferStreamImp() {} |
64 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, FX_DWORD dwAccess); | 64 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); |
65 virtual int32_t GetLength() const; | 65 virtual int32_t GetLength() const; |
66 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 66 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); |
67 virtual int32_t GetPosition(); | 67 virtual int32_t GetPosition(); |
68 virtual FX_BOOL IsEOF() const; | 68 virtual FX_BOOL IsEOF() const; |
69 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 69 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); |
70 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); | 70 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); |
71 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 71 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); |
72 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 72 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); |
73 virtual void Flush() {} | 73 virtual void Flush() {} |
74 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } | 74 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } |
75 | 75 |
76 protected: | 76 protected: |
77 uint8_t* m_pData; | 77 uint8_t* m_pData; |
78 int32_t m_iTotalSize; | 78 int32_t m_iTotalSize; |
79 int32_t m_iPosition; | 79 int32_t m_iPosition; |
80 int32_t m_iLength; | 80 int32_t m_iLength; |
81 }; | 81 }; |
82 | 82 |
83 class CFX_FileReadStreamImp : public CFX_StreamImp { | 83 class CFX_FileReadStreamImp : public CFX_StreamImp { |
84 public: | 84 public: |
85 CFX_FileReadStreamImp(); | 85 CFX_FileReadStreamImp(); |
86 virtual ~CFX_FileReadStreamImp() {} | 86 virtual ~CFX_FileReadStreamImp() {} |
87 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, FX_DWORD dwAccess); | 87 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess); |
88 virtual int32_t GetLength() const; | 88 virtual int32_t GetLength() const; |
89 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 89 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); |
90 virtual int32_t GetPosition() { return m_iPosition; } | 90 virtual int32_t GetPosition() { return m_iPosition; } |
91 virtual FX_BOOL IsEOF() const; | 91 virtual FX_BOOL IsEOF() const; |
92 | 92 |
93 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 93 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); |
94 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); | 94 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); |
95 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { | 95 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { |
96 return 0; | 96 return 0; |
97 } | 97 } |
98 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) { | 98 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) { |
99 return 0; | 99 return 0; |
100 } | 100 } |
101 virtual void Flush() {} | 101 virtual void Flush() {} |
102 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } | 102 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } |
103 | 103 |
104 protected: | 104 protected: |
105 IFX_FileRead* m_pFileRead; | 105 IFX_FileRead* m_pFileRead; |
106 int32_t m_iPosition; | 106 int32_t m_iPosition; |
107 int32_t m_iLength; | 107 int32_t m_iLength; |
108 }; | 108 }; |
109 | 109 |
110 class CFX_BufferReadStreamImp : public CFX_StreamImp { | 110 class CFX_BufferReadStreamImp : public CFX_StreamImp { |
111 public: | 111 public: |
112 CFX_BufferReadStreamImp(); | 112 CFX_BufferReadStreamImp(); |
113 ~CFX_BufferReadStreamImp(); | 113 ~CFX_BufferReadStreamImp(); |
114 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, | 114 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, |
115 int32_t iFileSize, | 115 int32_t iFileSize, |
116 FX_DWORD dwAccess, | 116 uint32_t dwAccess, |
117 FX_BOOL bReleaseBufferRead); | 117 FX_BOOL bReleaseBufferRead); |
118 | 118 |
119 virtual int32_t GetLength() const; | 119 virtual int32_t GetLength() const; |
120 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 120 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); |
121 virtual int32_t GetPosition() { return m_iPosition; } | 121 virtual int32_t GetPosition() { return m_iPosition; } |
122 virtual FX_BOOL IsEOF() const; | 122 virtual FX_BOOL IsEOF() const; |
123 | 123 |
124 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 124 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); |
125 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); | 125 virtual int32_t ReadString(FX_WCHAR* pStr, int32_t iMaxLength, FX_BOOL& bEOS); |
126 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { | 126 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { |
127 return 0; | 127 return 0; |
128 } | 128 } |
129 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) { | 129 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength) { |
130 return 0; | 130 return 0; |
131 } | 131 } |
132 virtual void Flush() {} | 132 virtual void Flush() {} |
133 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } | 133 virtual FX_BOOL SetLength(int32_t iLength) { return FALSE; } |
134 | 134 |
135 private: | 135 private: |
136 IFX_BufferRead* m_pBufferRead; | 136 IFX_BufferRead* m_pBufferRead; |
137 FX_BOOL m_bReleaseBufferRead; | 137 FX_BOOL m_bReleaseBufferRead; |
138 int32_t m_iPosition; | 138 int32_t m_iPosition; |
139 int32_t m_iBufferSize; | 139 int32_t m_iBufferSize; |
140 }; | 140 }; |
141 | 141 |
142 class CFX_FileWriteStreamImp : public CFX_StreamImp { | 142 class CFX_FileWriteStreamImp : public CFX_StreamImp { |
143 public: | 143 public: |
144 CFX_FileWriteStreamImp(); | 144 CFX_FileWriteStreamImp(); |
145 virtual ~CFX_FileWriteStreamImp() {} | 145 virtual ~CFX_FileWriteStreamImp() {} |
146 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, FX_DWORD dwAccess); | 146 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess); |
147 virtual int32_t GetLength() const; | 147 virtual int32_t GetLength() const; |
148 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 148 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); |
149 virtual int32_t GetPosition() { return m_iPosition; } | 149 virtual int32_t GetPosition() { return m_iPosition; } |
150 virtual FX_BOOL IsEOF() const; | 150 virtual FX_BOOL IsEOF() const; |
151 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) { return 0; } | 151 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize) { return 0; } |
152 virtual int32_t ReadString(FX_WCHAR* pStr, | 152 virtual int32_t ReadString(FX_WCHAR* pStr, |
153 int32_t iMaxLength, | 153 int32_t iMaxLength, |
154 FX_BOOL& bEOS) { | 154 FX_BOOL& bEOS) { |
155 return 0; | 155 return 0; |
156 } | 156 } |
(...skipping 12 matching lines...) Expand all Loading... |
169 FX_STREAMTYPE_File, | 169 FX_STREAMTYPE_File, |
170 FX_STREAMTYPE_Buffer, | 170 FX_STREAMTYPE_Buffer, |
171 FX_STREAMTYPE_Stream, | 171 FX_STREAMTYPE_Stream, |
172 FX_STREAMTYPE_BufferRead, | 172 FX_STREAMTYPE_BufferRead, |
173 }; | 173 }; |
174 | 174 |
175 class CFX_Stream : public IFX_Stream { | 175 class CFX_Stream : public IFX_Stream { |
176 public: | 176 public: |
177 CFX_Stream(); | 177 CFX_Stream(); |
178 ~CFX_Stream(); | 178 ~CFX_Stream(); |
179 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, FX_DWORD dwAccess); | 179 FX_BOOL LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); |
180 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, FX_DWORD dwAccess); | 180 FX_BOOL LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); |
181 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, FX_DWORD dwAccess); | 181 FX_BOOL LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess); |
182 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, FX_DWORD dwAccess); | 182 FX_BOOL LoadFileWrite(IFX_FileWrite* pFileWrite, uint32_t dwAccess); |
183 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, | 183 FX_BOOL LoadBufferRead(IFX_BufferRead* pBufferRead, |
184 int32_t iFileSize, | 184 int32_t iFileSize, |
185 FX_DWORD dwAccess, | 185 uint32_t dwAccess, |
186 FX_BOOL bReleaseBufferRead); | 186 FX_BOOL bReleaseBufferRead); |
187 virtual void Release(); | 187 virtual void Release(); |
188 virtual IFX_Stream* Retain(); | 188 virtual IFX_Stream* Retain(); |
189 virtual FX_DWORD GetAccessModes() const { return m_dwAccess; } | 189 virtual uint32_t GetAccessModes() const { return m_dwAccess; } |
190 virtual int32_t GetLength() const; | 190 virtual int32_t GetLength() const; |
191 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 191 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); |
192 virtual int32_t GetPosition(); | 192 virtual int32_t GetPosition(); |
193 virtual FX_BOOL IsEOF() const; | 193 virtual FX_BOOL IsEOF() const; |
194 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 194 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); |
195 virtual int32_t ReadString(FX_WCHAR* pStr, | 195 virtual int32_t ReadString(FX_WCHAR* pStr, |
196 int32_t iMaxLength, | 196 int32_t iMaxLength, |
197 FX_BOOL& bEOS, | 197 FX_BOOL& bEOS, |
198 int32_t const* pByteSize = NULL); | 198 int32_t const* pByteSize = NULL); |
199 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 199 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); |
200 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 200 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); |
201 virtual void Flush(); | 201 virtual void Flush(); |
202 virtual FX_BOOL SetLength(int32_t iLength); | 202 virtual FX_BOOL SetLength(int32_t iLength); |
203 virtual int32_t GetBOM(uint8_t bom[4]) const; | 203 virtual int32_t GetBOM(uint8_t bom[4]) const; |
204 virtual uint16_t GetCodePage() const; | 204 virtual uint16_t GetCodePage() const; |
205 virtual uint16_t SetCodePage(uint16_t wCodePage); | 205 virtual uint16_t SetCodePage(uint16_t wCodePage); |
206 virtual IFX_Stream* CreateSharedStream(FX_DWORD dwAccess, | 206 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, |
207 int32_t iOffset, | 207 int32_t iOffset, |
208 int32_t iLength); | 208 int32_t iLength); |
209 | 209 |
210 protected: | 210 protected: |
211 FX_STREAMTYPE m_eStreamType; | 211 FX_STREAMTYPE m_eStreamType; |
212 CFX_StreamImp* m_pStreamImp; | 212 CFX_StreamImp* m_pStreamImp; |
213 FX_DWORD m_dwAccess; | 213 uint32_t m_dwAccess; |
214 int32_t m_iTotalSize; | 214 int32_t m_iTotalSize; |
215 int32_t m_iPosition; | 215 int32_t m_iPosition; |
216 int32_t m_iStart; | 216 int32_t m_iStart; |
217 int32_t m_iLength; | 217 int32_t m_iLength; |
218 int32_t m_iRefCount; | 218 int32_t m_iRefCount; |
219 }; | 219 }; |
220 | 220 |
221 class CFX_TextStream : public IFX_Stream { | 221 class CFX_TextStream : public IFX_Stream { |
222 public: | 222 public: |
223 CFX_TextStream(IFX_Stream* pStream, FX_BOOL bDelStream); | 223 CFX_TextStream(IFX_Stream* pStream, FX_BOOL bDelStream); |
224 ~CFX_TextStream(); | 224 ~CFX_TextStream(); |
225 virtual void Release(); | 225 virtual void Release(); |
226 virtual IFX_Stream* Retain(); | 226 virtual IFX_Stream* Retain(); |
227 | 227 |
228 virtual FX_DWORD GetAccessModes() const; | 228 virtual uint32_t GetAccessModes() const; |
229 virtual int32_t GetLength() const; | 229 virtual int32_t GetLength() const; |
230 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); | 230 virtual int32_t Seek(FX_STREAMSEEK eSeek, int32_t iOffset); |
231 virtual int32_t GetPosition(); | 231 virtual int32_t GetPosition(); |
232 virtual FX_BOOL IsEOF() const; | 232 virtual FX_BOOL IsEOF() const; |
233 | 233 |
234 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); | 234 virtual int32_t ReadData(uint8_t* pBuffer, int32_t iBufferSize); |
235 virtual int32_t ReadString(FX_WCHAR* pStr, | 235 virtual int32_t ReadString(FX_WCHAR* pStr, |
236 int32_t iMaxLength, | 236 int32_t iMaxLength, |
237 FX_BOOL& bEOS, | 237 FX_BOOL& bEOS, |
238 int32_t const* pByteSize = NULL); | 238 int32_t const* pByteSize = NULL); |
239 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); | 239 virtual int32_t WriteData(const uint8_t* pBuffer, int32_t iBufferSize); |
240 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); | 240 virtual int32_t WriteString(const FX_WCHAR* pStr, int32_t iLength); |
241 virtual void Flush(); | 241 virtual void Flush(); |
242 virtual FX_BOOL SetLength(int32_t iLength); | 242 virtual FX_BOOL SetLength(int32_t iLength); |
243 | 243 |
244 virtual int32_t GetBOM(uint8_t bom[4]) const; | 244 virtual int32_t GetBOM(uint8_t bom[4]) const; |
245 virtual uint16_t GetCodePage() const; | 245 virtual uint16_t GetCodePage() const; |
246 virtual uint16_t SetCodePage(uint16_t wCodePage); | 246 virtual uint16_t SetCodePage(uint16_t wCodePage); |
247 | 247 |
248 virtual IFX_Stream* CreateSharedStream(FX_DWORD dwAccess, | 248 virtual IFX_Stream* CreateSharedStream(uint32_t dwAccess, |
249 int32_t iOffset, | 249 int32_t iOffset, |
250 int32_t iLength); | 250 int32_t iLength); |
251 | 251 |
252 protected: | 252 protected: |
253 uint16_t m_wCodePage; | 253 uint16_t m_wCodePage; |
254 int32_t m_wBOMLength; | 254 int32_t m_wBOMLength; |
255 FX_DWORD m_dwBOM; | 255 uint32_t m_dwBOM; |
256 uint8_t* m_pBuf; | 256 uint8_t* m_pBuf; |
257 int32_t m_iBufSize; | 257 int32_t m_iBufSize; |
258 FX_BOOL m_bDelStream; | 258 FX_BOOL m_bDelStream; |
259 IFX_Stream* m_pStreamImp; | 259 IFX_Stream* m_pStreamImp; |
260 int32_t m_iRefCount; | 260 int32_t m_iRefCount; |
261 void InitStream(); | 261 void InitStream(); |
262 }; | 262 }; |
263 | 263 |
264 class CFGAS_FileRead : public IFX_FileRead { | 264 class CFGAS_FileRead : public IFX_FileRead { |
265 public: | 265 public: |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 size_t size); | 303 size_t size); |
304 | 304 |
305 protected: | 305 protected: |
306 IFX_Stream* m_pStream; | 306 IFX_Stream* m_pStream; |
307 FX_BOOL m_bReleaseStream; | 307 FX_BOOL m_bReleaseStream; |
308 }; | 308 }; |
309 | 309 |
310 } // namespace | 310 } // namespace |
311 | 311 |
312 IFX_Stream* IFX_Stream::CreateStream(IFX_BufferRead* pBufferRead, | 312 IFX_Stream* IFX_Stream::CreateStream(IFX_BufferRead* pBufferRead, |
313 FX_DWORD dwAccess, | 313 uint32_t dwAccess, |
314 int32_t iFileSize, | 314 int32_t iFileSize, |
315 FX_BOOL bReleaseBufferRead) { | 315 FX_BOOL bReleaseBufferRead) { |
316 CFX_Stream* pSR = new CFX_Stream; | 316 CFX_Stream* pSR = new CFX_Stream; |
317 if (!pSR->LoadBufferRead(pBufferRead, iFileSize, dwAccess, | 317 if (!pSR->LoadBufferRead(pBufferRead, iFileSize, dwAccess, |
318 bReleaseBufferRead)) { | 318 bReleaseBufferRead)) { |
319 pSR->Release(); | 319 pSR->Release(); |
320 return NULL; | 320 return NULL; |
321 } | 321 } |
322 if (dwAccess & FX_STREAMACCESS_Text) { | 322 if (dwAccess & FX_STREAMACCESS_Text) { |
323 return new CFX_TextStream(pSR, TRUE); | 323 return new CFX_TextStream(pSR, TRUE); |
324 } | 324 } |
325 return pSR; | 325 return pSR; |
326 } | 326 } |
327 IFX_Stream* IFX_Stream::CreateStream(IFX_FileRead* pFileRead, | 327 IFX_Stream* IFX_Stream::CreateStream(IFX_FileRead* pFileRead, |
328 FX_DWORD dwAccess) { | 328 uint32_t dwAccess) { |
329 CFX_Stream* pSR = new CFX_Stream; | 329 CFX_Stream* pSR = new CFX_Stream; |
330 if (!pSR->LoadFileRead(pFileRead, dwAccess)) { | 330 if (!pSR->LoadFileRead(pFileRead, dwAccess)) { |
331 pSR->Release(); | 331 pSR->Release(); |
332 return NULL; | 332 return NULL; |
333 } | 333 } |
334 if (dwAccess & FX_STREAMACCESS_Text) { | 334 if (dwAccess & FX_STREAMACCESS_Text) { |
335 return new CFX_TextStream(pSR, TRUE); | 335 return new CFX_TextStream(pSR, TRUE); |
336 } | 336 } |
337 return pSR; | 337 return pSR; |
338 } | 338 } |
339 IFX_Stream* IFX_Stream::CreateStream(IFX_FileWrite* pFileWrite, | 339 IFX_Stream* IFX_Stream::CreateStream(IFX_FileWrite* pFileWrite, |
340 FX_DWORD dwAccess) { | 340 uint32_t dwAccess) { |
341 CFX_Stream* pSR = new CFX_Stream; | 341 CFX_Stream* pSR = new CFX_Stream; |
342 if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { | 342 if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { |
343 pSR->Release(); | 343 pSR->Release(); |
344 return NULL; | 344 return NULL; |
345 } | 345 } |
346 if (dwAccess & FX_STREAMACCESS_Text) { | 346 if (dwAccess & FX_STREAMACCESS_Text) { |
347 return new CFX_TextStream(pSR, TRUE); | 347 return new CFX_TextStream(pSR, TRUE); |
348 } | 348 } |
349 return pSR; | 349 return pSR; |
350 } | 350 } |
351 IFX_Stream* IFX_Stream::CreateStream(const FX_WCHAR* pszFileName, | 351 IFX_Stream* IFX_Stream::CreateStream(const FX_WCHAR* pszFileName, |
352 FX_DWORD dwAccess) { | 352 uint32_t dwAccess) { |
353 CFX_Stream* pSR = new CFX_Stream; | 353 CFX_Stream* pSR = new CFX_Stream; |
354 if (!pSR->LoadFile(pszFileName, dwAccess)) { | 354 if (!pSR->LoadFile(pszFileName, dwAccess)) { |
355 pSR->Release(); | 355 pSR->Release(); |
356 return NULL; | 356 return NULL; |
357 } | 357 } |
358 if (dwAccess & FX_STREAMACCESS_Text) { | 358 if (dwAccess & FX_STREAMACCESS_Text) { |
359 return new CFX_TextStream(pSR, TRUE); | 359 return new CFX_TextStream(pSR, TRUE); |
360 } | 360 } |
361 return pSR; | 361 return pSR; |
362 } | 362 } |
363 IFX_Stream* IFX_Stream::CreateStream(uint8_t* pData, | 363 IFX_Stream* IFX_Stream::CreateStream(uint8_t* pData, |
364 int32_t length, | 364 int32_t length, |
365 FX_DWORD dwAccess) { | 365 uint32_t dwAccess) { |
366 CFX_Stream* pSR = new CFX_Stream; | 366 CFX_Stream* pSR = new CFX_Stream; |
367 if (!pSR->LoadBuffer(pData, length, dwAccess)) { | 367 if (!pSR->LoadBuffer(pData, length, dwAccess)) { |
368 pSR->Release(); | 368 pSR->Release(); |
369 return NULL; | 369 return NULL; |
370 } | 370 } |
371 if (dwAccess & FX_STREAMACCESS_Text) { | 371 if (dwAccess & FX_STREAMACCESS_Text) { |
372 return new CFX_TextStream(pSR, TRUE); | 372 return new CFX_TextStream(pSR, TRUE); |
373 } | 373 } |
374 return pSR; | 374 return pSR; |
375 } | 375 } |
376 | 376 |
377 CFX_StreamImp::CFX_StreamImp() : m_dwAccess(0) {} | 377 CFX_StreamImp::CFX_StreamImp() : m_dwAccess(0) {} |
378 CFX_FileStreamImp::CFX_FileStreamImp() | 378 CFX_FileStreamImp::CFX_FileStreamImp() |
379 : CFX_StreamImp(), m_hFile(NULL), m_iLength(0) {} | 379 : CFX_StreamImp(), m_hFile(NULL), m_iLength(0) {} |
380 CFX_FileStreamImp::~CFX_FileStreamImp() { | 380 CFX_FileStreamImp::~CFX_FileStreamImp() { |
381 if (m_hFile != NULL) { | 381 if (m_hFile != NULL) { |
382 FXSYS_fclose(m_hFile); | 382 FXSYS_fclose(m_hFile); |
383 } | 383 } |
384 } | 384 } |
385 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, | 385 FX_BOOL CFX_FileStreamImp::LoadFile(const FX_WCHAR* pszSrcFileName, |
386 FX_DWORD dwAccess) { | 386 uint32_t dwAccess) { |
387 FXSYS_assert(m_hFile == NULL); | 387 FXSYS_assert(m_hFile == NULL); |
388 FXSYS_assert(pszSrcFileName != NULL && FXSYS_wcslen(pszSrcFileName) > 0); | 388 FXSYS_assert(pszSrcFileName != NULL && FXSYS_wcslen(pszSrcFileName) > 0); |
389 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ | 389 #if _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \ |
390 _FX_OS_ == _FX_WIN64_ | 390 _FX_OS_ == _FX_WIN64_ |
391 CFX_WideString wsMode; | 391 CFX_WideString wsMode; |
392 if (dwAccess & FX_STREAMACCESS_Write) { | 392 if (dwAccess & FX_STREAMACCESS_Write) { |
393 if (dwAccess & FX_STREAMACCESS_Append) { | 393 if (dwAccess & FX_STREAMACCESS_Append) { |
394 wsMode = L"a+b"; | 394 wsMode = L"a+b"; |
395 } else if (dwAccess & FX_STREAMACCESS_Truncate) { | 395 } else if (dwAccess & FX_STREAMACCESS_Truncate) { |
396 wsMode = L"w+b"; | 396 wsMode = L"w+b"; |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 } | 540 } |
541 FX_BOOL CFX_FileStreamImp::SetLength(int32_t iLength) { | 541 FX_BOOL CFX_FileStreamImp::SetLength(int32_t iLength) { |
542 FXSYS_assert(m_hFile != NULL && (m_dwAccess & FX_STREAMACCESS_Write) != 0); | 542 FXSYS_assert(m_hFile != NULL && (m_dwAccess & FX_STREAMACCESS_Write) != 0); |
543 FX_BOOL bRet = FX_fsetsize(m_hFile, iLength); | 543 FX_BOOL bRet = FX_fsetsize(m_hFile, iLength); |
544 m_iLength = FX_filelength(m_hFile); | 544 m_iLength = FX_filelength(m_hFile); |
545 return bRet; | 545 return bRet; |
546 } | 546 } |
547 CFX_FileReadStreamImp::CFX_FileReadStreamImp() | 547 CFX_FileReadStreamImp::CFX_FileReadStreamImp() |
548 : m_pFileRead(NULL), m_iPosition(0), m_iLength(0) {} | 548 : m_pFileRead(NULL), m_iPosition(0), m_iLength(0) {} |
549 FX_BOOL CFX_FileReadStreamImp::LoadFileRead(IFX_FileRead* pFileRead, | 549 FX_BOOL CFX_FileReadStreamImp::LoadFileRead(IFX_FileRead* pFileRead, |
550 FX_DWORD dwAccess) { | 550 uint32_t dwAccess) { |
551 FXSYS_assert(m_pFileRead == NULL && pFileRead != NULL); | 551 FXSYS_assert(m_pFileRead == NULL && pFileRead != NULL); |
552 if (dwAccess & FX_STREAMACCESS_Write) { | 552 if (dwAccess & FX_STREAMACCESS_Write) { |
553 return FALSE; | 553 return FALSE; |
554 } | 554 } |
555 m_pFileRead = pFileRead; | 555 m_pFileRead = pFileRead; |
556 m_iLength = m_pFileRead->GetSize(); | 556 m_iLength = m_pFileRead->GetSize(); |
557 return TRUE; | 557 return TRUE; |
558 } | 558 } |
559 int32_t CFX_FileReadStreamImp::GetLength() const { | 559 int32_t CFX_FileReadStreamImp::GetLength() const { |
560 return m_iLength; | 560 return m_iLength; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 m_bReleaseBufferRead(FALSE), | 614 m_bReleaseBufferRead(FALSE), |
615 m_iPosition(0), | 615 m_iPosition(0), |
616 m_iBufferSize(0) {} | 616 m_iBufferSize(0) {} |
617 CFX_BufferReadStreamImp::~CFX_BufferReadStreamImp() { | 617 CFX_BufferReadStreamImp::~CFX_BufferReadStreamImp() { |
618 if (m_bReleaseBufferRead && m_pBufferRead != NULL) { | 618 if (m_bReleaseBufferRead && m_pBufferRead != NULL) { |
619 m_pBufferRead->Release(); | 619 m_pBufferRead->Release(); |
620 } | 620 } |
621 } | 621 } |
622 FX_BOOL CFX_BufferReadStreamImp::LoadBufferRead(IFX_BufferRead* pBufferRead, | 622 FX_BOOL CFX_BufferReadStreamImp::LoadBufferRead(IFX_BufferRead* pBufferRead, |
623 int32_t iFileSize, | 623 int32_t iFileSize, |
624 FX_DWORD dwAccess, | 624 uint32_t dwAccess, |
625 FX_BOOL bReleaseBufferRead) { | 625 FX_BOOL bReleaseBufferRead) { |
626 FXSYS_assert(m_pBufferRead == NULL && pBufferRead != NULL); | 626 FXSYS_assert(m_pBufferRead == NULL && pBufferRead != NULL); |
627 if (dwAccess & FX_STREAMACCESS_Write) { | 627 if (dwAccess & FX_STREAMACCESS_Write) { |
628 return FALSE; | 628 return FALSE; |
629 } | 629 } |
630 m_bReleaseBufferRead = bReleaseBufferRead; | 630 m_bReleaseBufferRead = bReleaseBufferRead; |
631 m_pBufferRead = pBufferRead; | 631 m_pBufferRead = pBufferRead; |
632 m_iBufferSize = iFileSize; | 632 m_iBufferSize = iFileSize; |
633 if (m_iBufferSize >= 0) { | 633 if (m_iBufferSize >= 0) { |
634 return TRUE; | 634 return TRUE; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 int32_t iBufferSize) { | 673 int32_t iBufferSize) { |
674 FXSYS_assert(m_pBufferRead != NULL); | 674 FXSYS_assert(m_pBufferRead != NULL); |
675 FXSYS_assert(pBuffer != NULL && iBufferSize > 0); | 675 FXSYS_assert(pBuffer != NULL && iBufferSize > 0); |
676 int32_t iLength = GetLength(); | 676 int32_t iLength = GetLength(); |
677 if (m_iPosition >= iLength) { | 677 if (m_iPosition >= iLength) { |
678 return 0; | 678 return 0; |
679 } | 679 } |
680 if (iBufferSize > iLength - m_iPosition) { | 680 if (iBufferSize > iLength - m_iPosition) { |
681 iBufferSize = iLength - m_iPosition; | 681 iBufferSize = iLength - m_iPosition; |
682 } | 682 } |
683 FX_DWORD dwBlockOffset = m_pBufferRead->GetBlockOffset(); | 683 uint32_t dwBlockOffset = m_pBufferRead->GetBlockOffset(); |
684 FX_DWORD dwBlockSize = m_pBufferRead->GetBlockSize(); | 684 uint32_t dwBlockSize = m_pBufferRead->GetBlockSize(); |
685 if (m_iPosition < (int32_t)dwBlockOffset) { | 685 if (m_iPosition < (int32_t)dwBlockOffset) { |
686 if (!m_pBufferRead->ReadNextBlock(TRUE)) { | 686 if (!m_pBufferRead->ReadNextBlock(TRUE)) { |
687 return 0; | 687 return 0; |
688 } | 688 } |
689 dwBlockOffset = m_pBufferRead->GetBlockOffset(); | 689 dwBlockOffset = m_pBufferRead->GetBlockOffset(); |
690 dwBlockSize = m_pBufferRead->GetBlockSize(); | 690 dwBlockSize = m_pBufferRead->GetBlockSize(); |
691 } | 691 } |
692 while (m_iPosition < (int32_t)dwBlockOffset || | 692 while (m_iPosition < (int32_t)dwBlockOffset || |
693 m_iPosition >= (int32_t)(dwBlockOffset + dwBlockSize)) { | 693 m_iPosition >= (int32_t)(dwBlockOffset + dwBlockSize)) { |
694 if (m_pBufferRead->IsEOF() || !m_pBufferRead->ReadNextBlock(FALSE)) { | 694 if (m_pBufferRead->IsEOF() || !m_pBufferRead->ReadNextBlock(FALSE)) { |
695 break; | 695 break; |
696 } | 696 } |
697 dwBlockOffset = m_pBufferRead->GetBlockOffset(); | 697 dwBlockOffset = m_pBufferRead->GetBlockOffset(); |
698 dwBlockSize = m_pBufferRead->GetBlockSize(); | 698 dwBlockSize = m_pBufferRead->GetBlockSize(); |
699 } | 699 } |
700 if (m_iPosition < (int32_t)dwBlockOffset || | 700 if (m_iPosition < (int32_t)dwBlockOffset || |
701 m_iPosition >= (int32_t)(dwBlockOffset + dwBlockSize)) { | 701 m_iPosition >= (int32_t)(dwBlockOffset + dwBlockSize)) { |
702 return 0; | 702 return 0; |
703 } | 703 } |
704 const uint8_t* pBufferTmp = m_pBufferRead->GetBlockBuffer(); | 704 const uint8_t* pBufferTmp = m_pBufferRead->GetBlockBuffer(); |
705 FX_DWORD dwOffsetTmp = m_iPosition - dwBlockOffset; | 705 uint32_t dwOffsetTmp = m_iPosition - dwBlockOffset; |
706 FX_DWORD dwCopySize = | 706 uint32_t dwCopySize = |
707 std::min(iBufferSize, (int32_t)(dwBlockSize - dwOffsetTmp)); | 707 std::min(iBufferSize, (int32_t)(dwBlockSize - dwOffsetTmp)); |
708 FXSYS_memcpy(pBuffer, pBufferTmp + dwOffsetTmp, dwCopySize); | 708 FXSYS_memcpy(pBuffer, pBufferTmp + dwOffsetTmp, dwCopySize); |
709 dwOffsetTmp = dwCopySize; | 709 dwOffsetTmp = dwCopySize; |
710 iBufferSize -= dwCopySize; | 710 iBufferSize -= dwCopySize; |
711 while (iBufferSize > 0) { | 711 while (iBufferSize > 0) { |
712 if (!m_pBufferRead->ReadNextBlock(FALSE)) { | 712 if (!m_pBufferRead->ReadNextBlock(FALSE)) { |
713 break; | 713 break; |
714 } | 714 } |
715 dwBlockOffset = m_pBufferRead->GetBlockOffset(); | 715 dwBlockOffset = m_pBufferRead->GetBlockOffset(); |
716 dwBlockSize = m_pBufferRead->GetBlockSize(); | 716 dwBlockSize = m_pBufferRead->GetBlockSize(); |
717 pBufferTmp = m_pBufferRead->GetBlockBuffer(); | 717 pBufferTmp = m_pBufferRead->GetBlockBuffer(); |
718 dwCopySize = std::min((FX_DWORD)iBufferSize, dwBlockSize); | 718 dwCopySize = std::min((uint32_t)iBufferSize, dwBlockSize); |
719 FXSYS_memcpy(pBuffer + dwOffsetTmp, pBufferTmp, dwCopySize); | 719 FXSYS_memcpy(pBuffer + dwOffsetTmp, pBufferTmp, dwCopySize); |
720 dwOffsetTmp += dwCopySize; | 720 dwOffsetTmp += dwCopySize; |
721 iBufferSize -= dwCopySize; | 721 iBufferSize -= dwCopySize; |
722 } | 722 } |
723 m_iPosition += dwOffsetTmp; | 723 m_iPosition += dwOffsetTmp; |
724 return dwOffsetTmp; | 724 return dwOffsetTmp; |
725 } | 725 } |
726 int32_t CFX_BufferReadStreamImp::ReadString(FX_WCHAR* pStr, | 726 int32_t CFX_BufferReadStreamImp::ReadString(FX_WCHAR* pStr, |
727 int32_t iMaxLength, | 727 int32_t iMaxLength, |
728 FX_BOOL& bEOS) { | 728 FX_BOOL& bEOS) { |
729 FXSYS_assert(m_pBufferRead != NULL); | 729 FXSYS_assert(m_pBufferRead != NULL); |
730 FXSYS_assert(pStr != NULL && iMaxLength > 0); | 730 FXSYS_assert(pStr != NULL && iMaxLength > 0); |
731 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; | 731 iMaxLength = ReadData((uint8_t*)pStr, iMaxLength * 2) / 2; |
732 if (iMaxLength <= 0) { | 732 if (iMaxLength <= 0) { |
733 return 0; | 733 return 0; |
734 } | 734 } |
735 int32_t i = 0; | 735 int32_t i = 0; |
736 while (i < iMaxLength && pStr[i] != L'\0') { | 736 while (i < iMaxLength && pStr[i] != L'\0') { |
737 ++i; | 737 ++i; |
738 } | 738 } |
739 bEOS = (m_iPosition >= GetLength()) || pStr[i] == L'\0'; | 739 bEOS = (m_iPosition >= GetLength()) || pStr[i] == L'\0'; |
740 return i; | 740 return i; |
741 } | 741 } |
742 CFX_FileWriteStreamImp::CFX_FileWriteStreamImp() | 742 CFX_FileWriteStreamImp::CFX_FileWriteStreamImp() |
743 : m_pFileWrite(NULL), m_iPosition(0) {} | 743 : m_pFileWrite(NULL), m_iPosition(0) {} |
744 FX_BOOL CFX_FileWriteStreamImp::LoadFileWrite(IFX_FileWrite* pFileWrite, | 744 FX_BOOL CFX_FileWriteStreamImp::LoadFileWrite(IFX_FileWrite* pFileWrite, |
745 FX_DWORD dwAccess) { | 745 uint32_t dwAccess) { |
746 FXSYS_assert(m_pFileWrite == NULL && pFileWrite != NULL); | 746 FXSYS_assert(m_pFileWrite == NULL && pFileWrite != NULL); |
747 if (dwAccess & FX_STREAMACCESS_Read) { | 747 if (dwAccess & FX_STREAMACCESS_Read) { |
748 return FALSE; | 748 return FALSE; |
749 } | 749 } |
750 if (dwAccess & FX_STREAMACCESS_Append) { | 750 if (dwAccess & FX_STREAMACCESS_Append) { |
751 m_iPosition = pFileWrite->GetSize(); | 751 m_iPosition = pFileWrite->GetSize(); |
752 } | 752 } |
753 m_pFileWrite = pFileWrite; | 753 m_pFileWrite = pFileWrite; |
754 return TRUE; | 754 return TRUE; |
755 } | 755 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 } | 802 } |
803 } | 803 } |
804 CFX_BufferStreamImp::CFX_BufferStreamImp() | 804 CFX_BufferStreamImp::CFX_BufferStreamImp() |
805 : CFX_StreamImp(), | 805 : CFX_StreamImp(), |
806 m_pData(NULL), | 806 m_pData(NULL), |
807 m_iTotalSize(0), | 807 m_iTotalSize(0), |
808 m_iPosition(0), | 808 m_iPosition(0), |
809 m_iLength(0) {} | 809 m_iLength(0) {} |
810 FX_BOOL CFX_BufferStreamImp::LoadBuffer(uint8_t* pData, | 810 FX_BOOL CFX_BufferStreamImp::LoadBuffer(uint8_t* pData, |
811 int32_t iTotalSize, | 811 int32_t iTotalSize, |
812 FX_DWORD dwAccess) { | 812 uint32_t dwAccess) { |
813 FXSYS_assert(m_pData == NULL); | 813 FXSYS_assert(m_pData == NULL); |
814 FXSYS_assert(pData != NULL && iTotalSize > 0); | 814 FXSYS_assert(pData != NULL && iTotalSize > 0); |
815 m_dwAccess = dwAccess; | 815 m_dwAccess = dwAccess; |
816 m_pData = pData; | 816 m_pData = pData; |
817 m_iTotalSize = iTotalSize; | 817 m_iTotalSize = iTotalSize; |
818 m_iPosition = 0; | 818 m_iPosition = 0; |
819 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; | 819 m_iLength = (dwAccess & FX_STREAMACCESS_Write) != 0 ? 0 : iTotalSize; |
820 return TRUE; | 820 return TRUE; |
821 } | 821 } |
822 int32_t CFX_BufferStreamImp::GetLength() const { | 822 int32_t CFX_BufferStreamImp::GetLength() const { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 } | 981 } |
982 void CFX_TextStream::Release() { | 982 void CFX_TextStream::Release() { |
983 if (--m_iRefCount < 1) { | 983 if (--m_iRefCount < 1) { |
984 delete this; | 984 delete this; |
985 } | 985 } |
986 } | 986 } |
987 IFX_Stream* CFX_TextStream::Retain() { | 987 IFX_Stream* CFX_TextStream::Retain() { |
988 m_iRefCount++; | 988 m_iRefCount++; |
989 return this; | 989 return this; |
990 } | 990 } |
991 FX_DWORD CFX_TextStream::GetAccessModes() const { | 991 uint32_t CFX_TextStream::GetAccessModes() const { |
992 return m_pStreamImp->GetAccessModes() | FX_STREAMACCESS_Text; | 992 return m_pStreamImp->GetAccessModes() | FX_STREAMACCESS_Text; |
993 } | 993 } |
994 int32_t CFX_TextStream::GetLength() const { | 994 int32_t CFX_TextStream::GetLength() const { |
995 return m_pStreamImp->GetLength(); | 995 return m_pStreamImp->GetLength(); |
996 } | 996 } |
997 int32_t CFX_TextStream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { | 997 int32_t CFX_TextStream::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { |
998 return m_pStreamImp->Seek(eSeek, iOffset); | 998 return m_pStreamImp->Seek(eSeek, iOffset); |
999 } | 999 } |
1000 int32_t CFX_TextStream::GetPosition() { | 1000 int32_t CFX_TextStream::GetPosition() { |
1001 return m_pStreamImp->GetPosition(); | 1001 return m_pStreamImp->GetPosition(); |
1002 } | 1002 } |
1003 FX_BOOL CFX_TextStream::IsEOF() const { | 1003 FX_BOOL CFX_TextStream::IsEOF() const { |
1004 return m_pStreamImp->IsEOF(); | 1004 return m_pStreamImp->IsEOF(); |
1005 } | 1005 } |
1006 int32_t CFX_TextStream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { | 1006 int32_t CFX_TextStream::ReadData(uint8_t* pBuffer, int32_t iBufferSize) { |
1007 return m_pStreamImp->ReadData(pBuffer, iBufferSize); | 1007 return m_pStreamImp->ReadData(pBuffer, iBufferSize); |
1008 } | 1008 } |
1009 int32_t CFX_TextStream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { | 1009 int32_t CFX_TextStream::WriteData(const uint8_t* pBuffer, int32_t iBufferSize) { |
1010 return m_pStreamImp->WriteData(pBuffer, iBufferSize); | 1010 return m_pStreamImp->WriteData(pBuffer, iBufferSize); |
1011 } | 1011 } |
1012 void CFX_TextStream::Flush() { | 1012 void CFX_TextStream::Flush() { |
1013 m_pStreamImp->Flush(); | 1013 m_pStreamImp->Flush(); |
1014 } | 1014 } |
1015 FX_BOOL CFX_TextStream::SetLength(int32_t iLength) { | 1015 FX_BOOL CFX_TextStream::SetLength(int32_t iLength) { |
1016 return m_pStreamImp->SetLength(iLength); | 1016 return m_pStreamImp->SetLength(iLength); |
1017 } | 1017 } |
1018 uint16_t CFX_TextStream::GetCodePage() const { | 1018 uint16_t CFX_TextStream::GetCodePage() const { |
1019 return m_wCodePage; | 1019 return m_wCodePage; |
1020 } | 1020 } |
1021 IFX_Stream* CFX_TextStream::CreateSharedStream(FX_DWORD dwAccess, | 1021 IFX_Stream* CFX_TextStream::CreateSharedStream(uint32_t dwAccess, |
1022 int32_t iOffset, | 1022 int32_t iOffset, |
1023 int32_t iLength) { | 1023 int32_t iLength) { |
1024 IFX_Stream* pSR = | 1024 IFX_Stream* pSR = |
1025 m_pStreamImp->CreateSharedStream(dwAccess, iOffset, iLength); | 1025 m_pStreamImp->CreateSharedStream(dwAccess, iOffset, iLength); |
1026 if (pSR == NULL) { | 1026 if (pSR == NULL) { |
1027 return NULL; | 1027 return NULL; |
1028 } | 1028 } |
1029 if (dwAccess & FX_STREAMACCESS_Text) { | 1029 if (dwAccess & FX_STREAMACCESS_Text) { |
1030 return new CFX_TextStream(pSR, TRUE); | 1030 return new CFX_TextStream(pSR, TRUE); |
1031 } | 1031 } |
1032 return pSR; | 1032 return pSR; |
1033 } | 1033 } |
1034 int32_t CFX_TextStream::GetBOM(uint8_t bom[4]) const { | 1034 int32_t CFX_TextStream::GetBOM(uint8_t bom[4]) const { |
1035 if (m_wBOMLength < 1) { | 1035 if (m_wBOMLength < 1) { |
1036 return 0; | 1036 return 0; |
1037 } | 1037 } |
1038 *(FX_DWORD*)bom = m_dwBOM; | 1038 *(uint32_t*)bom = m_dwBOM; |
1039 return m_wBOMLength; | 1039 return m_wBOMLength; |
1040 } | 1040 } |
1041 uint16_t CFX_TextStream::SetCodePage(uint16_t wCodePage) { | 1041 uint16_t CFX_TextStream::SetCodePage(uint16_t wCodePage) { |
1042 if (m_wBOMLength > 0) { | 1042 if (m_wBOMLength > 0) { |
1043 return m_wCodePage; | 1043 return m_wCodePage; |
1044 } | 1044 } |
1045 uint16_t v = m_wCodePage; | 1045 uint16_t v = m_wCodePage; |
1046 m_wCodePage = wCodePage; | 1046 m_wCodePage = wCodePage; |
1047 return v; | 1047 return v; |
1048 } | 1048 } |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 m_iPosition(0), | 1124 m_iPosition(0), |
1125 m_iStart(0), | 1125 m_iStart(0), |
1126 m_iLength(0), | 1126 m_iLength(0), |
1127 m_iRefCount(1) {} | 1127 m_iRefCount(1) {} |
1128 CFX_Stream::~CFX_Stream() { | 1128 CFX_Stream::~CFX_Stream() { |
1129 if (m_eStreamType != FX_STREAMTYPE_Stream && m_pStreamImp != NULL) { | 1129 if (m_eStreamType != FX_STREAMTYPE_Stream && m_pStreamImp != NULL) { |
1130 m_pStreamImp->Release(); | 1130 m_pStreamImp->Release(); |
1131 } | 1131 } |
1132 } | 1132 } |
1133 FX_BOOL CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, | 1133 FX_BOOL CFX_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, |
1134 FX_DWORD dwAccess) { | 1134 uint32_t dwAccess) { |
1135 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { | 1135 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { |
1136 return FALSE; | 1136 return FALSE; |
1137 } | 1137 } |
1138 if (pszSrcFileName == NULL || FXSYS_wcslen(pszSrcFileName) < 1) { | 1138 if (pszSrcFileName == NULL || FXSYS_wcslen(pszSrcFileName) < 1) { |
1139 return FALSE; | 1139 return FALSE; |
1140 } | 1140 } |
1141 m_pStreamImp = new CFX_FileStreamImp(); | 1141 m_pStreamImp = new CFX_FileStreamImp(); |
1142 FX_BOOL bRet = | 1142 FX_BOOL bRet = |
1143 ((CFX_FileStreamImp*)m_pStreamImp)->LoadFile(pszSrcFileName, dwAccess); | 1143 ((CFX_FileStreamImp*)m_pStreamImp)->LoadFile(pszSrcFileName, dwAccess); |
1144 if (!bRet) { | 1144 if (!bRet) { |
1145 m_pStreamImp->Release(); | 1145 m_pStreamImp->Release(); |
1146 m_pStreamImp = NULL; | 1146 m_pStreamImp = NULL; |
1147 } else { | 1147 } else { |
1148 m_eStreamType = FX_STREAMTYPE_File; | 1148 m_eStreamType = FX_STREAMTYPE_File; |
1149 m_dwAccess = dwAccess; | 1149 m_dwAccess = dwAccess; |
1150 m_iLength = m_pStreamImp->GetLength(); | 1150 m_iLength = m_pStreamImp->GetLength(); |
1151 } | 1151 } |
1152 return bRet; | 1152 return bRet; |
1153 } | 1153 } |
1154 FX_BOOL CFX_Stream::LoadFileRead(IFX_FileRead* pFileRead, FX_DWORD dwAccess) { | 1154 FX_BOOL CFX_Stream::LoadFileRead(IFX_FileRead* pFileRead, uint32_t dwAccess) { |
1155 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { | 1155 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { |
1156 return FALSE; | 1156 return FALSE; |
1157 } | 1157 } |
1158 if (pFileRead == NULL) { | 1158 if (pFileRead == NULL) { |
1159 return FALSE; | 1159 return FALSE; |
1160 } | 1160 } |
1161 m_pStreamImp = new CFX_FileReadStreamImp(); | 1161 m_pStreamImp = new CFX_FileReadStreamImp(); |
1162 FX_BOOL bRet = | 1162 FX_BOOL bRet = |
1163 ((CFX_FileReadStreamImp*)m_pStreamImp)->LoadFileRead(pFileRead, dwAccess); | 1163 ((CFX_FileReadStreamImp*)m_pStreamImp)->LoadFileRead(pFileRead, dwAccess); |
1164 if (!bRet) { | 1164 if (!bRet) { |
1165 m_pStreamImp->Release(); | 1165 m_pStreamImp->Release(); |
1166 m_pStreamImp = NULL; | 1166 m_pStreamImp = NULL; |
1167 } else { | 1167 } else { |
1168 m_eStreamType = FX_STREAMTYPE_File; | 1168 m_eStreamType = FX_STREAMTYPE_File; |
1169 m_dwAccess = dwAccess; | 1169 m_dwAccess = dwAccess; |
1170 m_iLength = m_pStreamImp->GetLength(); | 1170 m_iLength = m_pStreamImp->GetLength(); |
1171 } | 1171 } |
1172 return bRet; | 1172 return bRet; |
1173 } | 1173 } |
1174 FX_BOOL CFX_Stream::LoadFileWrite(IFX_FileWrite* pFileWrite, | 1174 FX_BOOL CFX_Stream::LoadFileWrite(IFX_FileWrite* pFileWrite, |
1175 FX_DWORD dwAccess) { | 1175 uint32_t dwAccess) { |
1176 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { | 1176 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { |
1177 return FALSE; | 1177 return FALSE; |
1178 } | 1178 } |
1179 if (pFileWrite == NULL) { | 1179 if (pFileWrite == NULL) { |
1180 return FALSE; | 1180 return FALSE; |
1181 } | 1181 } |
1182 m_pStreamImp = new CFX_FileWriteStreamImp(); | 1182 m_pStreamImp = new CFX_FileWriteStreamImp(); |
1183 FX_BOOL bRet = ((CFX_FileWriteStreamImp*)m_pStreamImp) | 1183 FX_BOOL bRet = ((CFX_FileWriteStreamImp*)m_pStreamImp) |
1184 ->LoadFileWrite(pFileWrite, dwAccess); | 1184 ->LoadFileWrite(pFileWrite, dwAccess); |
1185 if (!bRet) { | 1185 if (!bRet) { |
1186 m_pStreamImp->Release(); | 1186 m_pStreamImp->Release(); |
1187 m_pStreamImp = NULL; | 1187 m_pStreamImp = NULL; |
1188 } else { | 1188 } else { |
1189 m_eStreamType = FX_STREAMTYPE_File; | 1189 m_eStreamType = FX_STREAMTYPE_File; |
1190 m_dwAccess = dwAccess; | 1190 m_dwAccess = dwAccess; |
1191 m_iLength = m_pStreamImp->GetLength(); | 1191 m_iLength = m_pStreamImp->GetLength(); |
1192 } | 1192 } |
1193 return bRet; | 1193 return bRet; |
1194 } | 1194 } |
1195 FX_BOOL CFX_Stream::LoadBuffer(uint8_t* pData, | 1195 FX_BOOL CFX_Stream::LoadBuffer(uint8_t* pData, |
1196 int32_t iTotalSize, | 1196 int32_t iTotalSize, |
1197 FX_DWORD dwAccess) { | 1197 uint32_t dwAccess) { |
1198 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { | 1198 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { |
1199 return FALSE; | 1199 return FALSE; |
1200 } | 1200 } |
1201 if (pData == NULL || iTotalSize < 1) { | 1201 if (pData == NULL || iTotalSize < 1) { |
1202 return FALSE; | 1202 return FALSE; |
1203 } | 1203 } |
1204 m_pStreamImp = new CFX_BufferStreamImp(); | 1204 m_pStreamImp = new CFX_BufferStreamImp(); |
1205 FX_BOOL bRet = ((CFX_BufferStreamImp*)m_pStreamImp) | 1205 FX_BOOL bRet = ((CFX_BufferStreamImp*)m_pStreamImp) |
1206 ->LoadBuffer(pData, iTotalSize, dwAccess); | 1206 ->LoadBuffer(pData, iTotalSize, dwAccess); |
1207 if (!bRet) { | 1207 if (!bRet) { |
1208 m_pStreamImp->Release(); | 1208 m_pStreamImp->Release(); |
1209 m_pStreamImp = NULL; | 1209 m_pStreamImp = NULL; |
1210 } else { | 1210 } else { |
1211 m_eStreamType = FX_STREAMTYPE_Buffer; | 1211 m_eStreamType = FX_STREAMTYPE_Buffer; |
1212 m_dwAccess = dwAccess; | 1212 m_dwAccess = dwAccess; |
1213 m_iLength = m_pStreamImp->GetLength(); | 1213 m_iLength = m_pStreamImp->GetLength(); |
1214 } | 1214 } |
1215 return bRet; | 1215 return bRet; |
1216 } | 1216 } |
1217 FX_BOOL CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead, | 1217 FX_BOOL CFX_Stream::LoadBufferRead(IFX_BufferRead* pBufferRead, |
1218 int32_t iFileSize, | 1218 int32_t iFileSize, |
1219 FX_DWORD dwAccess, | 1219 uint32_t dwAccess, |
1220 FX_BOOL bReleaseBufferRead) { | 1220 FX_BOOL bReleaseBufferRead) { |
1221 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { | 1221 if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp != NULL) { |
1222 return FALSE; | 1222 return FALSE; |
1223 } | 1223 } |
1224 if (!pBufferRead) { | 1224 if (!pBufferRead) { |
1225 return FALSE; | 1225 return FALSE; |
1226 } | 1226 } |
1227 m_pStreamImp = new CFX_BufferReadStreamImp; | 1227 m_pStreamImp = new CFX_BufferReadStreamImp; |
1228 FX_BOOL bRet = ((CFX_BufferReadStreamImp*)m_pStreamImp) | 1228 FX_BOOL bRet = ((CFX_BufferReadStreamImp*)m_pStreamImp) |
1229 ->LoadBufferRead(pBufferRead, iFileSize, dwAccess, | 1229 ->LoadBufferRead(pBufferRead, iFileSize, dwAccess, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1428 return FX_CODEPAGE_UTF16BE; | 1428 return FX_CODEPAGE_UTF16BE; |
1429 #endif | 1429 #endif |
1430 } | 1430 } |
1431 uint16_t CFX_Stream::SetCodePage(uint16_t wCodePage) { | 1431 uint16_t CFX_Stream::SetCodePage(uint16_t wCodePage) { |
1432 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ | 1432 #if _FX_ENDIAN_ == _FX_LITTLE_ENDIAN_ |
1433 return FX_CODEPAGE_UTF16LE; | 1433 return FX_CODEPAGE_UTF16LE; |
1434 #else | 1434 #else |
1435 return FX_CODEPAGE_UTF16BE; | 1435 return FX_CODEPAGE_UTF16BE; |
1436 #endif | 1436 #endif |
1437 } | 1437 } |
1438 IFX_Stream* CFX_Stream::CreateSharedStream(FX_DWORD dwAccess, | 1438 IFX_Stream* CFX_Stream::CreateSharedStream(uint32_t dwAccess, |
1439 int32_t iOffset, | 1439 int32_t iOffset, |
1440 int32_t iLength) { | 1440 int32_t iLength) { |
1441 FXSYS_assert(iLength > 0); | 1441 FXSYS_assert(iLength > 0); |
1442 if (m_pStreamImp == NULL) { | 1442 if (m_pStreamImp == NULL) { |
1443 return NULL; | 1443 return NULL; |
1444 } | 1444 } |
1445 if ((m_dwAccess & FX_STREAMACCESS_Text) != 0 && | 1445 if ((m_dwAccess & FX_STREAMACCESS_Text) != 0 && |
1446 (dwAccess & FX_STREAMACCESS_Text) == 0) { | 1446 (dwAccess & FX_STREAMACCESS_Text) == 0) { |
1447 return NULL; | 1447 return NULL; |
1448 } | 1448 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1617 return m_pStream->WriteData((const uint8_t*)pData, (int32_t)size) == | 1617 return m_pStream->WriteData((const uint8_t*)pData, (int32_t)size) == |
1618 (int32_t)size; | 1618 (int32_t)size; |
1619 } | 1619 } |
1620 FX_BOOL CFGAS_FileWrite::WriteBlock(const void* pData, | 1620 FX_BOOL CFGAS_FileWrite::WriteBlock(const void* pData, |
1621 FX_FILESIZE offset, | 1621 FX_FILESIZE offset, |
1622 size_t size) { | 1622 size_t size) { |
1623 m_pStream->Seek(FX_STREAMSEEK_Begin, offset); | 1623 m_pStream->Seek(FX_STREAMSEEK_Begin, offset); |
1624 int32_t iLen = m_pStream->WriteData((uint8_t*)pData, (int32_t)size); | 1624 int32_t iLen = m_pStream->WriteData((uint8_t*)pData, (int32_t)size); |
1625 return iLen == (int32_t)size; | 1625 return iLen == (int32_t)size; |
1626 } | 1626 } |
OLD | NEW |