1baa3858d3f5d128a5c8466b700098109edcad5f2repo sync// 7zItem.h
2baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
3baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#ifndef __7Z_ITEM_H
4baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#define __7Z_ITEM_H
5baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
6cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky#include "../../../Common/MyBuffer.h"
7baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../../Common/MyString.h"
8baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
9baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "../../Common/MethodId.h"
10baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
11baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#include "7zHeader.h"
12baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
13baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace NArchive {
14baa3858d3f5d128a5c8466b700098109edcad5f2repo syncnamespace N7z {
15baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
16baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst UInt64 k_AES = 0x06F10701;
17baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
18baa3858d3f5d128a5c8466b700098109edcad5f2repo synctypedef UInt32 CNum;
19baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst CNum kNumMax     = 0x7FFFFFFF;
20baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst CNum kNumNoIndex = 0xFFFFFFFF;
21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
22baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CCoderInfo
23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
24baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CMethodId MethodID;
25baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CByteBuffer Props;
26baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CNum NumInStreams;
27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CNum NumOutStreams;
28cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
29baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool IsSimpleCoder() const { return (NumInStreams == 1) && (NumOutStreams == 1); }
30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
31baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
32baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CBindPair
33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CNum InIndex;
35baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CNum OutIndex;
36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
37baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
38baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CFolder
39baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
40cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CObjArray2<CCoderInfo> Coders;
41cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CObjArray2<CBindPair> BindPairs;
42cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CObjArray2<CNum> PackStreams;
43baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
44baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CNum GetNumOutStreams() const
45baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CNum result = 0;
47cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    FOR_VECTOR(i, Coders)
48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      result += Coders[i].NumOutStreams;
49baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return result;
50baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int FindBindPairForInStream(CNum inStreamIndex) const
53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
54cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    FOR_VECTOR(i, BindPairs)
55baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (BindPairs[i].InIndex == inStreamIndex)
56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return i;
57baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return -1;
58baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int FindBindPairForOutStream(CNum outStreamIndex) const
60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
61cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    FOR_VECTOR(i, BindPairs)
62baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (BindPairs[i].OutIndex == outStreamIndex)
63baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return i;
64baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return -1;
65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
66baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  int FindPackStreamArrayIndex(CNum inStreamIndex) const
67baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
68cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    FOR_VECTOR(i, PackStreams)
69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (PackStreams[i] == inStreamIndex)
70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return i;
71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return -1;
72baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
73baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
74cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  int GetIndexOfMainOutStream() const
75cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  {
76cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    for (int i = (int)GetNumOutStreams() - 1; i >= 0; i--)
77cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky      if (FindBindPairForOutStream(i) < 0)
78cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky        return i;
79cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    throw 1;
80cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  }
81cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool IsEncrypted() const
83baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    for (int i = Coders.Size() - 1; i >= 0; i--)
85baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (Coders[i].MethodID == k_AES)
86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return true;
87baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return false;
88baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
89baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
90cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool CheckStructure(unsigned numUnpackSizes) const;
91cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky};
92cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
93cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckystruct CUInt32DefVector
94cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky{
95cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CBoolVector Defs;
96cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CRecordVector<UInt32> Vals;
97cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
98cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  void ClearAndSetSize(unsigned newSize)
99cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  {
100cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Defs.ClearAndSetSize(newSize);
101cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Vals.ClearAndSetSize(newSize);
102cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  }
103cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
104cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  void Clear()
105cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  {
106cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Defs.Clear();
107cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Vals.Clear();
108cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  }
109cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
110cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  void ReserveDown()
111cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  {
112cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Defs.ReserveDown();
113cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Vals.ReserveDown();
114cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  }
115cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
116cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool ValidAndDefined(unsigned i) const { return i < Defs.Size() && Defs[i]; }
117baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
118baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
119baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CUInt64DefVector
120baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
121cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CBoolVector Defs;
122cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CRecordVector<UInt64> Vals;
123baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
124baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Clear()
125baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
126cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Defs.Clear();
127cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Vals.Clear();
128baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
129baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
130baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void ReserveDown()
131baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
132cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Defs.ReserveDown();
133cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Vals.ReserveDown();
134baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
135baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
136cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool GetItem(unsigned index, UInt64 &value) const
137baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
138cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    if (index < Defs.Size() && Defs[index])
139baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
140cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky      value = Vals[index];
141baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return true;
142baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
143baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    value = 0;
144baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return false;
145baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
146baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
147cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  void SetItem(unsigned index, bool defined, UInt64 value);
148baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
149cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; }
150baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
151baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
152baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CFileItem
153baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
154baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 Size;
155baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt32 Attrib;
156baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt32 Crc;
157cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  /*
158cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  int Parent;
159cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool IsAltStream;
160cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  */
161baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool HasStream; // Test it !!! it means that there is
162baa3858d3f5d128a5c8466b700098109edcad5f2repo sync                  // stream in some folder. It can be empty stream
163baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool IsDir;
164baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool CrcDefined;
165baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool AttribDefined;
166baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
167baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CFileItem():
168cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    /*
169cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Parent(-1),
170cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    IsAltStream(false),
171cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    */
172baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    HasStream(true),
173baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    IsDir(false),
174baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CrcDefined(false),
175baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    AttribDefined(false)
176baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {}
177baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void SetAttrib(UInt32 attrib)
178baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
179baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    AttribDefined = true;
180baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    Attrib = attrib;
181baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
182baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
183baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
184baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}}
185baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
186baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
187