Mercurial > vba-linux
comparison src/win32/7zip/7z/CPP/7zip/Archive/Rar/RarVolumeInStream.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // RarVolumeInStream.cpp | |
2 | |
3 #include "StdAfx.h" | |
4 | |
5 #include "RarVolumeInStream.h" | |
6 | |
7 #include "Windows/Defs.h" | |
8 #include "Common/Defs.h" | |
9 | |
10 extern "C" | |
11 { | |
12 #include "../../../../C/7zCrc.h" | |
13 } | |
14 | |
15 namespace NArchive { | |
16 namespace NRar { | |
17 | |
18 void CFolderInStream::Init( | |
19 CObjectVector<CInArchive> *archives, | |
20 const CObjectVector<CItemEx> *items, | |
21 const CRefItem &refItem) | |
22 { | |
23 _archives = archives; | |
24 _items = items; | |
25 _refItem = refItem; | |
26 _curIndex = 0; | |
27 CRCs.Clear(); | |
28 _fileIsOpen = false; | |
29 } | |
30 | |
31 HRESULT CFolderInStream::OpenStream() | |
32 { | |
33 while (_curIndex < _refItem.NumItems) | |
34 { | |
35 const CItemEx &item = (*_items)[_refItem.ItemIndex + _curIndex]; | |
36 _stream.Attach((*_archives)[_refItem.VolumeIndex + _curIndex]. | |
37 CreateLimitedStream(item.GetDataPosition(), item.PackSize)); | |
38 _curIndex++; | |
39 _fileIsOpen = true; | |
40 _crc = CRC_INIT_VAL; | |
41 return S_OK; | |
42 } | |
43 return S_OK; | |
44 } | |
45 | |
46 HRESULT CFolderInStream::CloseStream() | |
47 { | |
48 CRCs.Add(CRC_GET_DIGEST(_crc)); | |
49 _stream.Release(); | |
50 _fileIsOpen = false; | |
51 return S_OK; | |
52 } | |
53 | |
54 STDMETHODIMP CFolderInStream::Read(void *data, UInt32 size, UInt32 *processedSize) | |
55 { | |
56 UInt32 realProcessedSize = 0; | |
57 while ((_curIndex < _refItem.NumItems || _fileIsOpen) && size > 0) | |
58 { | |
59 if (_fileIsOpen) | |
60 { | |
61 UInt32 localProcessedSize; | |
62 RINOK(_stream->Read( | |
63 ((Byte *)data) + realProcessedSize, size, &localProcessedSize)); | |
64 _crc = CrcUpdate(_crc, ((Byte *)data) + realProcessedSize, localProcessedSize); | |
65 if (localProcessedSize == 0) | |
66 { | |
67 RINOK(CloseStream()); | |
68 continue; | |
69 } | |
70 realProcessedSize += localProcessedSize; | |
71 size -= localProcessedSize; | |
72 break; | |
73 } | |
74 else | |
75 { | |
76 RINOK(OpenStream()); | |
77 } | |
78 } | |
79 if (processedSize != 0) | |
80 *processedSize = realProcessedSize; | |
81 return S_OK; | |
82 } | |
83 | |
84 }} |