Fix build_init vcxproj to correctly detect changes in config.h.
[mono.git] / mcs / class / System.IO.Compression / SharpCompress / Common / Zip / Headers / ZipFileEntry..cs
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Text;
5
6 namespace SharpCompress.Common.Zip.Headers
7 {
8     internal abstract class ZipFileEntry : ZipHeader
9     {
10         protected ZipFileEntry(ZipHeaderType type)
11             : base(type)
12         {
13             Extra = new List<ExtraData>();
14         }
15
16
17         internal bool IsDirectory
18         {
19             get { return Name.EndsWith("/"); }
20         }
21
22         protected string DecodeString(byte[] str)
23         {
24             if (FlagUtility.HasFlag(Flags, HeaderFlags.UTF8))
25             {
26                 return Encoding.UTF8.GetString(str, 0, str.Length);
27             }
28             return ArchiveEncoding.Default.GetString(str, 0, str.Length);
29         }
30
31         protected byte[] EncodeString(string str)
32         {
33             if (FlagUtility.HasFlag(Flags, HeaderFlags.UTF8))
34             {
35                 return Encoding.UTF8.GetBytes(str);
36             }
37             return ArchiveEncoding.Default.GetBytes(str);
38         }
39
40         internal Stream PackedStream { get; set; }
41
42         internal string Name { get; set; }
43
44         internal HeaderFlags Flags { get; set; }
45
46         internal ZipCompressionMethod CompressionMethod { get; set; }
47
48         internal uint CompressedSize { get; set; }
49
50         internal long? DataStartPosition { get; set; }
51
52         internal uint UncompressedSize { get; set; }
53
54         internal List<ExtraData> Extra { get; set; }
55
56         internal PkwareTraditionalEncryptionData PkwareTraditionalEncryptionData { get; set; }
57 #if !PORTABLE && !NETFX_CORE
58         internal WinzipAesEncryptionData WinzipAesEncryptionData { get; set; }
59 #endif
60
61         internal ushort LastModifiedDate { get; set; }
62
63         internal ushort LastModifiedTime { get; set; }
64
65         internal uint Crc { get; set; }
66
67         protected void LoadExtra(byte[] extra)
68         {
69             if (extra.Length % 2 != 0)
70                 return;
71                         
72             for (int i = 0; i < extra.Length;)
73             {
74                 ExtraDataType type = (ExtraDataType) BitConverter.ToUInt16(extra, i);
75                 if (!Enum.IsDefined(typeof (ExtraDataType), type))
76                 {
77                     return;
78                 }
79                 ushort length = BitConverter.ToUInt16(extra, i + 2);
80                 byte[] data = new byte[length];
81                 Buffer.BlockCopy(extra, i + 4, data, 0, length);
82                 Extra.Add(new ExtraData
83                               {
84                                   Type = type,
85                                   Length = length,
86                                   DataBytes = data
87                               });
88                 i += length + 4;
89             }
90         }
91
92         internal ZipFilePart Part { get; set; }
93     }
94 }