view src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhItem.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line source
1 // Archive/LzhItem.h
3 #ifndef __ARCHIVE_LZH_ITEM_H
4 #define __ARCHIVE_LZH_ITEM_H
6 #include "Common/Types.h"
7 #include "Common/MyString.h"
8 #include "Common/Buffer.h"
9 #include "LzhHeader.h"
11 namespace NArchive {
12 namespace NLzh {
14 struct CExtension
15 {
16 Byte Type;
17 CByteBuffer Data;
18 AString GetString() const
19 {
20 AString s;
21 for (size_t i = 0; i < Data.GetCapacity(); i++)
22 {
23 char c = (char)Data[i];
24 if (c == 0)
25 break;
26 s += c;
27 }
28 return s;
29 }
30 };
32 struct CItem
33 {
34 public:
35 AString Name;
36 Byte Method[kMethodIdSize];
37 UInt32 PackSize;
38 UInt32 Size;
39 UInt32 ModifiedTime;
40 Byte Attributes;
41 Byte Level;
42 UInt16 CRC;
43 Byte OsId;
44 CObjectVector<CExtension> Extensions;
46 bool IsValidMethod() const { return (Method[0] == '-' && Method[1] == 'l' && Method[4] == '-'); }
47 bool IsLhMethod() const {return (IsValidMethod() && Method[2] == 'h'); }
48 bool IsDir() const {return (IsLhMethod() && Method[3] == 'd'); }
50 bool IsCopyMethod() const
51 {
52 return (IsLhMethod() && Method[3] == '0') ||
53 (IsValidMethod() && Method[2] == 'z' && Method[3] == '4');
54 }
56 bool IsLh1GroupMethod() const
57 {
58 if (!IsLhMethod())
59 return false;
60 switch(Method[3])
61 {
62 case '1':
63 return true;
64 }
65 return false;
66 }
68 bool IsLh4GroupMethod() const
69 {
70 if (!IsLhMethod())
71 return false;
72 switch(Method[3])
73 {
74 case '4':
75 case '5':
76 case '6':
77 case '7':
78 return true;
79 }
80 return false;
81 }
83 int GetNumDictBits() const
84 {
85 if (!IsLhMethod())
86 return 0;
87 switch(Method[3])
88 {
89 case '1':
90 return 12;
91 case '2':
92 return 13;
93 case '3':
94 return 13;
95 case '4':
96 return 12;
97 case '5':
98 return 13;
99 case '6':
100 return 15;
101 case '7':
102 return 16;
103 }
104 return 0;
105 }
107 int FindExt(Byte type) const
108 {
109 for (int i = 0; i < Extensions.Size(); i++)
110 if (Extensions[i].Type == type)
111 return i;
112 return -1;
113 }
114 bool GetUnixTime(UInt32 &value) const
115 {
116 int index = FindExt(kExtIdUnixTime);
117 if (index < 0)
118 {
119 if (Level == 2)
120 {
121 value = ModifiedTime;
122 return true;
123 }
124 return false;
125 }
126 const Byte *data = (const Byte *)(Extensions[index].Data);
127 value = data[0] |
128 ((UInt32)data[1] << 8) |
129 ((UInt32)data[2] << 16) |
130 ((UInt32)data[3] << 24);
131 return true;
132 }
134 AString GetDirName() const
135 {
136 int index = FindExt(kExtIdDirName);
137 if (index < 0)
138 return AString();
139 return Extensions[index].GetString();
140 }
142 AString GetFileName() const
143 {
144 int index = FindExt(kExtIdFileName);
145 if (index < 0)
146 return Name;
147 return Extensions[index].GetString();
148 }
150 AString GetName() const
151 {
152 AString dirName = GetDirName();
153 dirName.Replace((char)(unsigned char)0xFF, '\\');
154 if (!dirName.IsEmpty())
155 {
156 char c = dirName[dirName.Length() - 1];
157 if (c != '\\')
158 dirName += '\\';
159 }
160 return dirName + GetFileName();
161 }
162 };
164 class CItemEx: public CItem
165 {
166 public:
167 UInt64 DataPosition;
168 };
170 }}
172 #endif