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 synctypedef UInt32 CNum;
17baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst CNum kNumMax     = 0x7FFFFFFF;
18baa3858d3f5d128a5c8466b700098109edcad5f2repo syncconst CNum kNumNoIndex = 0xFFFFFFFF;
19baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
20baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CCoderInfo
21baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
22baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CMethodId MethodID;
23baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CByteBuffer Props;
24f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  UInt32 NumStreams;
25cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
26f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  bool IsSimpleCoder() const { return NumStreams == 1; }
27baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
28baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
29f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osakastruct CBond
30baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
31f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  UInt32 PackIndex;
32f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  UInt32 UnpackIndex;
33baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
34baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
35baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CFolder
36baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
37f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  CLASS_NO_COPY(CFolder)
38f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osakapublic:
39cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CObjArray2<CCoderInfo> Coders;
40f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  CObjArray2<CBond> Bonds;
41f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  CObjArray2<UInt32> PackStreams;
42baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
43f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  CFolder() {}
44f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka
45f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  bool IsDecodingSupported() const { return Coders.Size() <= 32; }
46baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
47f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  int Find_in_PackStreams(UInt32 packStream) const
48baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
49f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka    FOR_VECTOR(i, PackStreams)
50f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka      if (PackStreams[i] == packStream)
51baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return i;
52baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return -1;
53baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
54f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka
55f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  int FindBond_for_PackStream(UInt32 packStream) const
56baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
57f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka    FOR_VECTOR(i, Bonds)
58f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka      if (Bonds[i].PackIndex == packStream)
59baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return i;
60baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return -1;
61baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
62f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka
63f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  /*
64f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  int FindBond_for_UnpackStream(UInt32 unpackStream) const
65baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
66f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka    FOR_VECTOR(i, Bonds)
67f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka      if (Bonds[i].UnpackIndex == unpackStream)
68baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return i;
69baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return -1;
70baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
71baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
72f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  int FindOutCoder() const
73cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  {
74f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka    for (int i = (int)Coders.Size() - 1; i >= 0; i--)
75f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka      if (FindBond_for_UnpackStream(i) < 0)
76cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky        return i;
77f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka    return -1;
78cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  }
79f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka  */
80cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
81baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool IsEncrypted() const
82baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
83f955a79a9fffb09826cf7547f70d08c3798a2f50Tetsuo Osaka    FOR_VECTOR(i, Coders)
84baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      if (Coders[i].MethodID == k_AES)
85baa3858d3f5d128a5c8466b700098109edcad5f2repo sync        return true;
86baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return false;
87baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
88cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky};
89cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
90cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbeckystruct CUInt32DefVector
91cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky{
92cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CBoolVector Defs;
93cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CRecordVector<UInt32> Vals;
94cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
95cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  void ClearAndSetSize(unsigned newSize)
96cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  {
97cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Defs.ClearAndSetSize(newSize);
98cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Vals.ClearAndSetSize(newSize);
99cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  }
100cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
101cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  void Clear()
102cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  {
103cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Defs.Clear();
104cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Vals.Clear();
105cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  }
106cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
107cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  void ReserveDown()
108cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  {
109cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Defs.ReserveDown();
110cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Vals.ReserveDown();
111cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  }
112cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky
113cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool ValidAndDefined(unsigned i) const { return i < Defs.Size() && Defs[i]; }
114baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
115baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
116baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CUInt64DefVector
117baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
118cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CBoolVector Defs;
119cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  CRecordVector<UInt64> Vals;
120baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
121baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void Clear()
122baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
123cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Defs.Clear();
124cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Vals.Clear();
125baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
126baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
127baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void ReserveDown()
128baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
129cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Defs.ReserveDown();
130cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Vals.ReserveDown();
131baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
132baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
133cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool GetItem(unsigned index, UInt64 &value) const
134baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
135cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    if (index < Defs.Size() && Defs[index])
136baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    {
137cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky      value = Vals[index];
138baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      return true;
139baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    }
140baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    value = 0;
141baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    return false;
142baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
143baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
144cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  void SetItem(unsigned index, bool defined, UInt64 value);
145baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
146cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool CheckSize(unsigned size) const { return Defs.Size() == size || Defs.Size() == 0; }
147baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
148baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
149baa3858d3f5d128a5c8466b700098109edcad5f2repo syncstruct CFileItem
150baa3858d3f5d128a5c8466b700098109edcad5f2repo sync{
151baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt64 Size;
152baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt32 Attrib;
153baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  UInt32 Crc;
154cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  /*
155cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  int Parent;
156cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  bool IsAltStream;
157cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky  */
158baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool HasStream; // Test it !!! it means that there is
159baa3858d3f5d128a5c8466b700098109edcad5f2repo sync                  // stream in some folder. It can be empty stream
160baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool IsDir;
161baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool CrcDefined;
162baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  bool AttribDefined;
163baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
164baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  CFileItem():
165cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    /*
166cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    Parent(-1),
167cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    IsAltStream(false),
168cd66d540cead3f8200b0c73bad9c276d67896c3dDavid Srbecky    */
169baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    HasStream(true),
170baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    IsDir(false),
171baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    CrcDefined(false),
172baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    AttribDefined(false)
173baa3858d3f5d128a5c8466b700098109edcad5f2repo sync      {}
174baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  void SetAttrib(UInt32 attrib)
175baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  {
176baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    AttribDefined = true;
177baa3858d3f5d128a5c8466b700098109edcad5f2repo sync    Attrib = attrib;
178baa3858d3f5d128a5c8466b700098109edcad5f2repo sync  }
179baa3858d3f5d128a5c8466b700098109edcad5f2repo sync};
180baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
181baa3858d3f5d128a5c8466b700098109edcad5f2repo sync}}
182baa3858d3f5d128a5c8466b700098109edcad5f2repo sync
183baa3858d3f5d128a5c8466b700098109edcad5f2repo sync#endif
184