Welcome to mirror list, hosted at ThFree Co, Russian Federation.

LzhItem.h « Lzh « Archive « 7zip « CPP - github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 66d4ed75be7464d7014c89be291c3e65e033fa96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Archive/LzhItem.h

#ifndef __ARCHIVE_LZH_ITEM_H
#define __ARCHIVE_LZH_ITEM_H

#include "Common/Types.h"
#include "Common/String.h"
#include "Common/Buffer.h"
#include "LzhHeader.h"

namespace NArchive {
namespace NLzh {

struct CExtension
{
  Byte Type;
  CByteBuffer Data;
  AString GetString() const
  {
    AString s;
    for (size_t i = 0; i < Data.GetCapacity(); i++)
    {
      char c = (char)Data[i];
      if (c == 0)
        break;
      s += c;
    }
    return s;
  }
};

struct CItem
{
public:
  AString Name;
  Byte Method[kMethodIdSize];
  UInt32 PackSize;
  UInt32 Size;
  UInt32 ModifiedTime;
  Byte Attributes;
  Byte Level;
  UInt16 CRC;
  Byte OsId;
  CObjectVector<CExtension> Extensions;

  bool IsValidMethod() const  { return (Method[0] == '-' && Method[1] == 'l' && Method[4] == '-'); }
  bool IsLhMethod() const  {return (IsValidMethod() && Method[2] == 'h'); }
  bool IsDirectory() const {return (IsLhMethod() && Method[3] == 'd'); }

  bool IsCopyMethod() const 
  {
    return (IsLhMethod() && Method[3] == '0') || 
      (IsValidMethod() && Method[2] == 'z' && Method[3] == '4');
  }
  
  bool IsLh1GroupMethod() const 
  {
    if (!IsLhMethod())
      return false;
    switch(Method[3])
    {
      case '1':
        return true;
    }
    return false;
  }
  
  bool IsLh4GroupMethod() const 
  {
    if (!IsLhMethod())
      return false;
    switch(Method[3])
    {
      case '4':
      case '5':
      case '6':
      case '7':
        return true;
    }
    return false;
  }
  
  int GetNumDictBits() const 
  {
    if (!IsLhMethod())
      return 0;
    switch(Method[3])
    {
      case '1':
        return 12;
      case '2':
        return 13;
      case '3':
        return 13;
      case '4':
        return 12;
      case '5':
        return 13;
      case '6':
        return 15;
      case '7':
        return 16;
    }
    return 0;
  }

  int FindExt(Byte type) const
  {
    for (int i = 0; i < Extensions.Size(); i++)
      if (Extensions[i].Type == type)
        return i;
    return -1;
  }
  bool GetUnixTime(UInt32 &value) const
  {
    int index = FindExt(kExtIdUnixTime);
    if (index < 0)
    {
      if (Level == 2)
      {
        value = ModifiedTime;
        return true;
      }
      return false;
    }
    const Byte *data = (const Byte *)(Extensions[index].Data);
    value = data[0] | 
        ((UInt32)data[1] << 8) | 
        ((UInt32)data[2] << 16) | 
        ((UInt32)data[3] << 24);
    return true;
  }

  AString GetDirName() const
  {
    int index = FindExt(kExtIdDirName);
    if (index < 0)
      return AString();
    return Extensions[index].GetString();
  }

  AString GetFileName() const
  {
    int index = FindExt(kExtIdFileName);
    if (index < 0)
      return Name;
    return Extensions[index].GetString();
  }

  AString GetName() const
  {
    AString dirName = GetDirName();
    dirName.Replace((char)(unsigned char)0xFF, '\\');
    if (!dirName.IsEmpty())
    {
      char c = dirName[dirName.Length() - 1];
      if (c != '\\')
        dirName += '\\';
    }
    return dirName + GetFileName();
  }
};

class CItemEx: public CItem
{
public:
  UInt64 DataPosition;
};

}}

#endif