diff options
Diffstat (limited to 'CPP/7zip/Archive/IhexHandler.cpp')
-rw-r--r-- | CPP/7zip/Archive/IhexHandler.cpp | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/CPP/7zip/Archive/IhexHandler.cpp b/CPP/7zip/Archive/IhexHandler.cpp index 05453ee..badb559 100644 --- a/CPP/7zip/Archive/IhexHandler.cpp +++ b/CPP/7zip/Archive/IhexHandler.cpp | |||
@@ -27,10 +27,9 @@ struct CBlock | |||
27 | UInt32 Offset; | 27 | UInt32 Offset; |
28 | }; | 28 | }; |
29 | 29 | ||
30 | class CHandler: | 30 | |
31 | public IInArchive, | 31 | Z7_CLASS_IMP_CHandler_IInArchive_0 |
32 | public CMyUnknownImp | 32 | |
33 | { | ||
34 | bool _isArc; | 33 | bool _isArc; |
35 | bool _needMoreInput; | 34 | bool _needMoreInput; |
36 | bool _dataError; | 35 | bool _dataError; |
@@ -38,9 +37,6 @@ class CHandler: | |||
38 | UInt64 _phySize; | 37 | UInt64 _phySize; |
39 | 38 | ||
40 | CObjectVector<CBlock> _blocks; | 39 | CObjectVector<CBlock> _blocks; |
41 | public: | ||
42 | MY_UNKNOWN_IMP1(IInArchive) | ||
43 | INTERFACE_IInArchive(;) | ||
44 | }; | 40 | }; |
45 | 41 | ||
46 | static const Byte kProps[] = | 42 | static const Byte kProps[] = |
@@ -53,13 +49,13 @@ static const Byte kProps[] = | |||
53 | IMP_IInArchive_Props | 49 | IMP_IInArchive_Props |
54 | IMP_IInArchive_ArcProps_NO_Table | 50 | IMP_IInArchive_ArcProps_NO_Table |
55 | 51 | ||
56 | STDMETHODIMP CHandler::GetNumberOfItems(UInt32 *numItems) | 52 | Z7_COM7F_IMF(CHandler::GetNumberOfItems(UInt32 *numItems)) |
57 | { | 53 | { |
58 | *numItems = _blocks.Size(); | 54 | *numItems = _blocks.Size(); |
59 | return S_OK; | 55 | return S_OK; |
60 | } | 56 | } |
61 | 57 | ||
62 | STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) | 58 | Z7_COM7F_IMF(CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value)) |
63 | { | 59 | { |
64 | NWindows::NCOM::CPropVariant prop; | 60 | NWindows::NCOM::CPropVariant prop; |
65 | switch (propID) | 61 | switch (propID) |
@@ -68,7 +64,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) | |||
68 | case kpidErrorFlags: | 64 | case kpidErrorFlags: |
69 | { | 65 | { |
70 | UInt32 v = 0; | 66 | UInt32 v = 0; |
71 | if (!_isArc) v |= kpv_ErrorFlags_IsNotArc;; | 67 | if (!_isArc) v |= kpv_ErrorFlags_IsNotArc; |
72 | if (_needMoreInput) v |= kpv_ErrorFlags_UnexpectedEnd; | 68 | if (_needMoreInput) v |= kpv_ErrorFlags_UnexpectedEnd; |
73 | if (_dataError) v |= kpv_ErrorFlags_DataError; | 69 | if (_dataError) v |= kpv_ErrorFlags_DataError; |
74 | prop = v; | 70 | prop = v; |
@@ -78,7 +74,7 @@ STDMETHODIMP CHandler::GetArchiveProperty(PROPID propID, PROPVARIANT *value) | |||
78 | return S_OK; | 74 | return S_OK; |
79 | } | 75 | } |
80 | 76 | ||
81 | STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value) | 77 | Z7_COM7F_IMF(CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)) |
82 | { | 78 | { |
83 | COM_TRY_BEGIN | 79 | COM_TRY_BEGIN |
84 | NWindows::NCOM::CPropVariant prop; | 80 | NWindows::NCOM::CPropVariant prop; |
@@ -105,16 +101,16 @@ STDMETHODIMP CHandler::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *val | |||
105 | 101 | ||
106 | static inline int HexToByte(unsigned c) | 102 | static inline int HexToByte(unsigned c) |
107 | { | 103 | { |
108 | if (c >= '0' && c <= '9') return c - '0'; | 104 | if (c >= '0' && c <= '9') return (int)(c - '0'); |
109 | if (c >= 'A' && c <= 'F') return c - 'A' + 10; | 105 | if (c >= 'A' && c <= 'F') return (int)(c - 'A' + 10); |
110 | if (c >= 'a' && c <= 'f') return c - 'a' + 10; | 106 | if (c >= 'a' && c <= 'f') return (int)(c - 'a' + 10); |
111 | return -1; | 107 | return -1; |
112 | } | 108 | } |
113 | 109 | ||
114 | static int Parse(const Byte *p) | 110 | static int Parse(const Byte *p) |
115 | { | 111 | { |
116 | int c1 = HexToByte(p[0]); if (c1 < 0) return -1; | 112 | const int c1 = HexToByte(p[0]); if (c1 < 0) return -1; |
117 | int c2 = HexToByte(p[1]); if (c2 < 0) return -1; | 113 | const int c2 = HexToByte(p[1]); if (c2 < 0) return -1; |
118 | return (c1 << 4) | c2; | 114 | return (c1 << 4) | c2; |
119 | } | 115 | } |
120 | 116 | ||
@@ -207,7 +203,7 @@ API_FUNC_static_IsArc IsArc_Ihex(const Byte *p, size_t size) | |||
207 | { | 203 | { |
208 | if (size == 0) | 204 | if (size == 0) |
209 | return k_IsArc_Res_NEED_MORE; | 205 | return k_IsArc_Res_NEED_MORE; |
210 | char b = *p++; | 206 | const Byte b = *p++; |
211 | size--; | 207 | size--; |
212 | if (IS_LINE_DELIMITER(b)) | 208 | if (IS_LINE_DELIMITER(b)) |
213 | continue; | 209 | continue; |
@@ -221,7 +217,7 @@ API_FUNC_static_IsArc IsArc_Ihex(const Byte *p, size_t size) | |||
221 | } | 217 | } |
222 | } | 218 | } |
223 | 219 | ||
224 | STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *) | 220 | Z7_COM7F_IMF(CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallback *)) |
225 | { | 221 | { |
226 | COM_TRY_BEGIN | 222 | COM_TRY_BEGIN |
227 | { | 223 | { |
@@ -232,7 +228,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallb | |||
232 | Byte temp[kStartSize]; | 228 | Byte temp[kStartSize]; |
233 | { | 229 | { |
234 | size_t size = kStartSize; | 230 | size_t size = kStartSize; |
235 | RINOK(ReadStream(stream, temp, &size)); | 231 | RINOK(ReadStream(stream, temp, &size)) |
236 | UInt32 isArcRes = IsArc_Ihex(temp, size); | 232 | UInt32 isArcRes = IsArc_Ihex(temp, size); |
237 | if (isArcRes == k_IsArc_Res_NO) | 233 | if (isArcRes == k_IsArc_Res_NO) |
238 | return S_FALSE; | 234 | return S_FALSE; |
@@ -241,7 +237,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallb | |||
241 | } | 237 | } |
242 | _isArc = true; | 238 | _isArc = true; |
243 | 239 | ||
244 | RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL)); | 240 | RINOK(InStream_SeekToBegin(stream)) |
245 | CInBuffer s; | 241 | CInBuffer s; |
246 | if (!s.Create(1 << 15)) | 242 | if (!s.Create(1 << 15)) |
247 | return E_OUTOFMEMORY; | 243 | return E_OUTOFMEMORY; |
@@ -271,7 +267,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallb | |||
271 | _needMoreInput = true; | 267 | _needMoreInput = true; |
272 | return S_FALSE; | 268 | return S_FALSE; |
273 | } | 269 | } |
274 | int num = Parse(temp); | 270 | const int num = Parse(temp); |
275 | if (num < 0) | 271 | if (num < 0) |
276 | { | 272 | { |
277 | _dataError = true; | 273 | _dataError = true; |
@@ -287,17 +283,17 @@ STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallb | |||
287 | return S_FALSE; | 283 | return S_FALSE; |
288 | } | 284 | } |
289 | 285 | ||
290 | unsigned sum = num; | 286 | unsigned sum = (unsigned)num; |
291 | for (size_t i = 0; i < numPairs; i++) | 287 | for (size_t i = 0; i < numPairs; i++) |
292 | { | 288 | { |
293 | int a = Parse(temp + i * 2); | 289 | const int a = Parse(temp + i * 2); |
294 | if (a < 0) | 290 | if (a < 0) |
295 | { | 291 | { |
296 | _dataError = true; | 292 | _dataError = true; |
297 | return S_FALSE; | 293 | return S_FALSE; |
298 | } | 294 | } |
299 | temp[i] = (Byte)a; | 295 | temp[i] = (Byte)a; |
300 | sum += a; | 296 | sum += (unsigned)a; |
301 | } | 297 | } |
302 | if ((sum & 0xFF) != 0) | 298 | if ((sum & 0xFF) != 0) |
303 | { | 299 | { |
@@ -413,7 +409,7 @@ STDMETHODIMP CHandler::Open(IInStream *stream, const UInt64 *, IArchiveOpenCallb | |||
413 | COM_TRY_END | 409 | COM_TRY_END |
414 | } | 410 | } |
415 | 411 | ||
416 | STDMETHODIMP CHandler::Close() | 412 | Z7_COM7F_IMF(CHandler::Close()) |
417 | { | 413 | { |
418 | _phySize = 0; | 414 | _phySize = 0; |
419 | 415 | ||
@@ -426,11 +422,11 @@ STDMETHODIMP CHandler::Close() | |||
426 | } | 422 | } |
427 | 423 | ||
428 | 424 | ||
429 | STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, | 425 | Z7_COM7F_IMF(CHandler::Extract(const UInt32 *indices, UInt32 numItems, |
430 | Int32 testMode, IArchiveExtractCallback *extractCallback) | 426 | Int32 testMode, IArchiveExtractCallback *extractCallback)) |
431 | { | 427 | { |
432 | COM_TRY_BEGIN | 428 | COM_TRY_BEGIN |
433 | bool allFilesMode = (numItems == (UInt32)(Int32)-1); | 429 | const bool allFilesMode = (numItems == (UInt32)(Int32)-1); |
434 | if (allFilesMode) | 430 | if (allFilesMode) |
435 | numItems = _blocks.Size(); | 431 | numItems = _blocks.Size(); |
436 | if (numItems == 0) | 432 | if (numItems == 0) |
@@ -453,18 +449,18 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, | |||
453 | { | 449 | { |
454 | currentItemSize = 0; | 450 | currentItemSize = 0; |
455 | lps->InSize = lps->OutSize = currentTotalSize; | 451 | lps->InSize = lps->OutSize = currentTotalSize; |
456 | RINOK(lps->SetCur()); | 452 | RINOK(lps->SetCur()) |
457 | 453 | ||
458 | UInt32 index = allFilesMode ? i : indices[i]; | 454 | const UInt32 index = allFilesMode ? i : indices[i]; |
459 | const CByteDynamicBuffer &data = _blocks[index].Data; | 455 | const CByteDynamicBuffer &data = _blocks[index].Data; |
460 | currentItemSize = data.GetPos(); | 456 | currentItemSize = data.GetPos(); |
461 | 457 | ||
462 | CMyComPtr<ISequentialOutStream> realOutStream; | 458 | CMyComPtr<ISequentialOutStream> realOutStream; |
463 | Int32 askMode = testMode ? | 459 | const Int32 askMode = testMode ? |
464 | NExtract::NAskMode::kTest : | 460 | NExtract::NAskMode::kTest : |
465 | NExtract::NAskMode::kExtract; | 461 | NExtract::NAskMode::kExtract; |
466 | 462 | ||
467 | RINOK(extractCallback->GetStream(index, &realOutStream, askMode)); | 463 | RINOK(extractCallback->GetStream(index, &realOutStream, askMode)) |
468 | 464 | ||
469 | if (!testMode && !realOutStream) | 465 | if (!testMode && !realOutStream) |
470 | continue; | 466 | continue; |
@@ -473,11 +469,11 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, | |||
473 | 469 | ||
474 | if (realOutStream) | 470 | if (realOutStream) |
475 | { | 471 | { |
476 | RINOK(WriteStream(realOutStream, (const Byte *)data, data.GetPos())); | 472 | RINOK(WriteStream(realOutStream, (const Byte *)data, data.GetPos())) |
477 | } | 473 | } |
478 | 474 | ||
479 | realOutStream.Release(); | 475 | realOutStream.Release(); |
480 | RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK)); | 476 | RINOK(extractCallback->SetOperationResult(NExtract::NOperationResult::kOK)) |
481 | } | 477 | } |
482 | 478 | ||
483 | lps->InSize = lps->OutSize = currentTotalSize; | 479 | lps->InSize = lps->OutSize = currentTotalSize; |
@@ -489,7 +485,7 @@ STDMETHODIMP CHandler::Extract(const UInt32 *indices, UInt32 numItems, | |||
489 | // k_Signature: { ':', '1' } | 485 | // k_Signature: { ':', '1' } |
490 | 486 | ||
491 | REGISTER_ARC_I_NO_SIG( | 487 | REGISTER_ARC_I_NO_SIG( |
492 | "IHex", "ihex", 0, 0xCD, | 488 | "IHex", "ihex", NULL, 0xCD, |
493 | 0, | 489 | 0, |
494 | NArcInfoFlags::kStartOpen, | 490 | NArcInfoFlags::kStartOpen, |
495 | IsArc_Ihex) | 491 | IsArc_Ihex) |