1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// MultiStream.h
2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef __MULTI_STREAM_H
4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define __MULTI_STREAM_H
5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
6baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../../Common/MyCom.h"
7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../../Common/MyVector.h"
8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../IStream.h"
10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
11baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass CMultiStream:
12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  public IInStream,
13baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  public CMyUnknownImp
14baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 _pos;
16baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 _totalLength;
17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int _streamIndex;
18baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic:
19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  struct CSubStreamInfo
20baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CMyComPtr<IInStream> Stream;
22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UInt64 Size;
23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UInt64 GlobalOffset;
24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UInt64 LocalPos;
25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  };
26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CObjectVector<CSubStreamInfo> Streams;
27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  HRESULT Init()
29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UInt64 total = 0;
31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int i = 0; i < Streams.Size(); i++)
32baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      CSubStreamInfo &s = Streams[i];
34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      s.GlobalOffset = total;
35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      total += Streams[i].Size;
36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      RINOK(s.Stream->Seek(0, STREAM_SEEK_CUR, &s.LocalPos));
37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
38baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _totalLength = total;
39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _pos = 0;
40baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _streamIndex = 0;
41baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return S_OK;
42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  MY_UNKNOWN_IMP1(IInStream)
45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
47baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
49baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync/*
51baa3858d3f5d128a5c8466b700098109edcad5f2repo syncclass COutMultiStream:
52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  public IOutStream,
53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  public CMyUnknownImp
54baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int _streamIndex; // required stream
56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 _offsetPos; // offset from start of _streamIndex index
57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 _absPos;
58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 _length;
59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  struct CSubStreamInfo
61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CMyComPtr<ISequentialOutStream> Stream;
63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UInt64 Size;
64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    UInt64 Pos;
65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync };
66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CObjectVector<CSubStreamInfo> Streams;
67baa3858d3f5d128a5c8466b700098109edcad5f2repo syncpublic:
68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CMyComPtr<IArchiveUpdateCallback2> VolumeCallback;
69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Init()
70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _streamIndex = 0;
72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _offsetPos = 0;
73baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _absPos = 0;
74baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    _length = 0;
75baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
76baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
77baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  MY_UNKNOWN_IMP1(IOutStream)
78baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
79baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
80baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition);
81baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync*/
83baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
85