Mercurial > vba-clojure
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/7zip/7z/CPP/7zip/Archive/Lzh/LzhItem.h Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,172 @@ 1.4 +// Archive/LzhItem.h 1.5 + 1.6 +#ifndef __ARCHIVE_LZH_ITEM_H 1.7 +#define __ARCHIVE_LZH_ITEM_H 1.8 + 1.9 +#include "Common/Types.h" 1.10 +#include "Common/MyString.h" 1.11 +#include "Common/Buffer.h" 1.12 +#include "LzhHeader.h" 1.13 + 1.14 +namespace NArchive { 1.15 +namespace NLzh { 1.16 + 1.17 +struct CExtension 1.18 +{ 1.19 + Byte Type; 1.20 + CByteBuffer Data; 1.21 + AString GetString() const 1.22 + { 1.23 + AString s; 1.24 + for (size_t i = 0; i < Data.GetCapacity(); i++) 1.25 + { 1.26 + char c = (char)Data[i]; 1.27 + if (c == 0) 1.28 + break; 1.29 + s += c; 1.30 + } 1.31 + return s; 1.32 + } 1.33 +}; 1.34 + 1.35 +struct CItem 1.36 +{ 1.37 +public: 1.38 + AString Name; 1.39 + Byte Method[kMethodIdSize]; 1.40 + UInt32 PackSize; 1.41 + UInt32 Size; 1.42 + UInt32 ModifiedTime; 1.43 + Byte Attributes; 1.44 + Byte Level; 1.45 + UInt16 CRC; 1.46 + Byte OsId; 1.47 + CObjectVector<CExtension> Extensions; 1.48 + 1.49 + bool IsValidMethod() const { return (Method[0] == '-' && Method[1] == 'l' && Method[4] == '-'); } 1.50 + bool IsLhMethod() const {return (IsValidMethod() && Method[2] == 'h'); } 1.51 + bool IsDir() const {return (IsLhMethod() && Method[3] == 'd'); } 1.52 + 1.53 + bool IsCopyMethod() const 1.54 + { 1.55 + return (IsLhMethod() && Method[3] == '0') || 1.56 + (IsValidMethod() && Method[2] == 'z' && Method[3] == '4'); 1.57 + } 1.58 + 1.59 + bool IsLh1GroupMethod() const 1.60 + { 1.61 + if (!IsLhMethod()) 1.62 + return false; 1.63 + switch(Method[3]) 1.64 + { 1.65 + case '1': 1.66 + return true; 1.67 + } 1.68 + return false; 1.69 + } 1.70 + 1.71 + bool IsLh4GroupMethod() const 1.72 + { 1.73 + if (!IsLhMethod()) 1.74 + return false; 1.75 + switch(Method[3]) 1.76 + { 1.77 + case '4': 1.78 + case '5': 1.79 + case '6': 1.80 + case '7': 1.81 + return true; 1.82 + } 1.83 + return false; 1.84 + } 1.85 + 1.86 + int GetNumDictBits() const 1.87 + { 1.88 + if (!IsLhMethod()) 1.89 + return 0; 1.90 + switch(Method[3]) 1.91 + { 1.92 + case '1': 1.93 + return 12; 1.94 + case '2': 1.95 + return 13; 1.96 + case '3': 1.97 + return 13; 1.98 + case '4': 1.99 + return 12; 1.100 + case '5': 1.101 + return 13; 1.102 + case '6': 1.103 + return 15; 1.104 + case '7': 1.105 + return 16; 1.106 + } 1.107 + return 0; 1.108 + } 1.109 + 1.110 + int FindExt(Byte type) const 1.111 + { 1.112 + for (int i = 0; i < Extensions.Size(); i++) 1.113 + if (Extensions[i].Type == type) 1.114 + return i; 1.115 + return -1; 1.116 + } 1.117 + bool GetUnixTime(UInt32 &value) const 1.118 + { 1.119 + int index = FindExt(kExtIdUnixTime); 1.120 + if (index < 0) 1.121 + { 1.122 + if (Level == 2) 1.123 + { 1.124 + value = ModifiedTime; 1.125 + return true; 1.126 + } 1.127 + return false; 1.128 + } 1.129 + const Byte *data = (const Byte *)(Extensions[index].Data); 1.130 + value = data[0] | 1.131 + ((UInt32)data[1] << 8) | 1.132 + ((UInt32)data[2] << 16) | 1.133 + ((UInt32)data[3] << 24); 1.134 + return true; 1.135 + } 1.136 + 1.137 + AString GetDirName() const 1.138 + { 1.139 + int index = FindExt(kExtIdDirName); 1.140 + if (index < 0) 1.141 + return AString(); 1.142 + return Extensions[index].GetString(); 1.143 + } 1.144 + 1.145 + AString GetFileName() const 1.146 + { 1.147 + int index = FindExt(kExtIdFileName); 1.148 + if (index < 0) 1.149 + return Name; 1.150 + return Extensions[index].GetString(); 1.151 + } 1.152 + 1.153 + AString GetName() const 1.154 + { 1.155 + AString dirName = GetDirName(); 1.156 + dirName.Replace((char)(unsigned char)0xFF, '\\'); 1.157 + if (!dirName.IsEmpty()) 1.158 + { 1.159 + char c = dirName[dirName.Length() - 1]; 1.160 + if (c != '\\') 1.161 + dirName += '\\'; 1.162 + } 1.163 + return dirName + GetFileName(); 1.164 + } 1.165 +}; 1.166 + 1.167 +class CItemEx: public CItem 1.168 +{ 1.169 +public: 1.170 + UInt64 DataPosition; 1.171 +}; 1.172 + 1.173 +}} 1.174 + 1.175 +#endif