Class representing extended unix date time values.
Inheritance: ITaggedData
Ejemplo n.º 1
0
        private DateTime GetDateTime(ZipExtraData extraData)
        {
            // Check for NT timestamp
            // NOTE: Disable by default to match behavior of InfoZIP
#if RESPECT_NT_TIMESTAMP
            NTTaggedData ntData = extraData.GetData <NTTaggedData>();
            if (ntData != null)
            {
                return(ntData.LastModificationTime);
            }
#endif

            // Check for Unix timestamp
            ExtendedUnixData unixData = extraData.GetData <ExtendedUnixData>();
            if (unixData != null &&
                // Only apply modification time, but require all other values to be present
                // This is done to match InfoZIP's behaviour
                ((unixData.Include & ExtendedUnixData.Flags.ModificationTime) != 0) &&
                ((unixData.Include & ExtendedUnixData.Flags.AccessTime) != 0) &&
                ((unixData.Include & ExtendedUnixData.Flags.CreateTime) != 0))
            {
                return(unixData.ModificationTime);
            }

            // Fall back to DOS time
            uint sec  = Math.Min(59, 2 * (dosTime & 0x1f));
            uint min  = Math.Min(59, (dosTime >> 5) & 0x3f);
            uint hrs  = Math.Min(23, (dosTime >> 11) & 0x1f);
            uint mon  = Math.Max(1, Math.Min(12, ((dosTime >> 21) & 0xf)));
            uint year = ((dosTime >> 25) & 0x7f) + 1980;
            int  day  = Math.Max(1, Math.Min(DateTime.DaysInMonth((int)year, (int)mon), (int)((dosTime >> 16) & 0x1f)));
            return(new DateTime((int)year, (int)mon, day, (int)hrs, (int)min, (int)sec, DateTimeKind.Utc));
        }
Ejemplo n.º 2
0
        private DateTime GetDateTime(ZipExtraData extraData)
        {
            ExtendedUnixData data = extraData.GetData <ExtendedUnixData>();

            if (data != null && (byte)(data.Include & ExtendedUnixData.Flags.ModificationTime) != 0 && (byte)(data.Include & ExtendedUnixData.Flags.AccessTime) != 0 && (byte)(data.Include & ExtendedUnixData.Flags.CreateTime) != 0)
            {
                return(data.ModificationTime);
            }
            uint second = Math.Min(59u, 2u * (this.dosTime & 31u));
            uint minute = Math.Min(59u, this.dosTime >> 5 & 63u);
            uint hour   = Math.Min(23u, this.dosTime >> 11 & 31u);
            uint month  = Math.Max(1u, Math.Min(12u, this.dosTime >> 21 & 15u));
            uint year   = (this.dosTime >> 25 & 127u) + 1980u;
            int  day    = Math.Max(1, Math.Min(DateTime.DaysInMonth((int)year, (int)month), (int)(this.dosTime >> 16 & 31u)));

            return(new DateTime((int)year, (int)month, day, (int)hour, (int)minute, (int)second, DateTimeKind.Utc));
        }
Ejemplo n.º 3
0
        private DateTime GetDateTime(ZipExtraData extraData)
        {
            ExtendedUnixData data = extraData.GetData <ExtendedUnixData>();

            if (data != null && (data.Include & ExtendedUnixData.Flags.ModificationTime) != 0 && (data.Include & ExtendedUnixData.Flags.AccessTime) != 0 && (data.Include & ExtendedUnixData.Flags.CreateTime) != 0)
            {
                return(data.ModificationTime);
            }
            uint second = Math.Min(59u, 2 * (dosTime & 0x1F));
            uint minute = Math.Min(59u, (dosTime >> 5) & 0x3F);
            uint hour   = Math.Min(23u, (dosTime >> 11) & 0x1F);
            uint month  = Math.Max(1u, Math.Min(12u, (dosTime >> 21) & 0xF));
            uint year   = ((dosTime >> 25) & 0x7F) + 1980;
            int  day    = Math.Max(1, Math.Min(DateTime.DaysInMonth((int)year, (int)month), (int)((dosTime >> 16) & 0x1F)));

            return(new DateTime((int)year, (int)month, day, (int)hour, (int)minute, (int)second, DateTimeKind.Utc));
        }
Ejemplo n.º 4
0
        private static ITaggedData Create(short tag, byte[] data, int offset, int count)
        {
            ITaggedData result = null;

            switch (tag)
            {
            case 0x000A:
                result = new NTTaggedData();
                break;

            case 0x5455:
                result = new ExtendedUnixData();
                break;

            default:
                result = new RawTaggedData(tag);
                break;
            }
            result.SetData(data, offset, count);
            return(result);
        }
Ejemplo n.º 5
0
        private static ITaggedData Create(short tag, byte[] data, int offset, int count)
        {
            ITaggedData taggedData = null;

            switch (tag)
            {
            case 10:
                taggedData = new NTTaggedData();
                break;

            case 21589:
                taggedData = new ExtendedUnixData();
                break;

            default:
                taggedData = new RawTaggedData(tag);
                break;
            }
            taggedData.SetData(data, offset, count);
            return(taggedData);
        }
Ejemplo n.º 6
0
        private static ITaggedData Create(short tag, byte[] data, int offset, int count)
        {
            ITaggedData data2 = null;

            switch (tag)
            {
            case 10:
                data2 = new NTTaggedData();
                break;

            case 0x5455:
                data2 = new ExtendedUnixData();
                break;

            default:
                data2 = new RawTaggedData(tag);
                break;
            }
            data2.SetData(data, offset, count);
            return(data2);
        }
Ejemplo n.º 7
0
        private static DateTime?GetDateTime(ZipExtraData extraData)
        {
            // Check for NT timestamp
            // NOTE: Disable by default to match behavior of InfoZIP
#if RESPECT_NT_TIMESTAMP
            NTTaggedData ntData = extraData.GetData <NTTaggedData>();
            if (ntData != null)
            {
                return(ntData.LastModificationTime);
            }
#endif

            // Check for Unix timestamp
            ExtendedUnixData unixData = extraData.GetData <ExtendedUnixData>();
            if (unixData != null && unixData.Include.HasFlag(ExtendedUnixData.Flags.ModificationTime))
            {
                return(unixData.ModificationTime);
            }

            return(null);
        }
Ejemplo n.º 8
0
        private ITaggedData Create(short tag, byte[] data, int offset, int count)
        {
            ITaggedData data2 = null;

            switch (tag)
            {
            case 10:
                data2 = new NTTaggedData();
                break;

            case 0x5455:
                data2 = new ExtendedUnixData();
                break;

            default:
                data2 = new RawTaggedData(tag);
                break;
            }
            data2.SetData(this.data_, this.readValueStart_, this.readValueLength_);
            return(data2);
        }
Ejemplo n.º 9
0
        private static ITaggedData Create(short tag, byte[] data, int offset, int count)
        {
            ITaggedData taggedData;

            if (tag != 10)
            {
                if (tag != 21589)
                {
                    taggedData = new RawTaggedData(tag);
                }
                else
                {
                    taggedData = new ExtendedUnixData();
                }
            }
            else
            {
                taggedData = new NTTaggedData();
            }
            taggedData.SetData(data, offset, count);
            return(taggedData);
        }
Ejemplo n.º 10
0
		static ITaggedData Create(short tag, byte[] data, int offset, int count)
		{
			ITaggedData result = null;
			switch ( tag )
			{
				case 0x000A:
					result = new NTTaggedData();
					break;
				case 0x5455:
					result = new ExtendedUnixData();
					break;
				default:
					result = new RawTaggedData(tag);
					break;
			}
			result.SetData(data, offset, count);
			return result;
		}
Ejemplo n.º 11
0
        public void TaggedDataHandling()
        {
            NTTaggedData tagData = new NTTaggedData();
            DateTime modTime = tagData.LastModificationTime;
            byte[] rawData = tagData.GetData();
            tagData.LastModificationTime = tagData.LastModificationTime + TimeSpan.FromSeconds(40);
            Assert.AreNotEqual(tagData.LastModificationTime, modTime);
            tagData.SetData(rawData, 0, rawData.Length);
            Assert.AreEqual(10, tagData.TagID, "TagID mismatch");
            Assert.AreEqual(modTime, tagData.LastModificationTime, "NT Mod time incorrect");

            tagData.CreateTime=DateTime.FromFileTimeUtc(0);
            tagData.LastAccessTime=new DateTime(9999, 12, 31, 23, 59, 59);
            rawData=tagData.GetData();

            ExtendedUnixData unixData = new ExtendedUnixData();
            modTime = unixData.ModificationTime;
            unixData.ModificationTime=modTime; // Ensure flag is set.

            rawData = unixData.GetData();
            unixData.ModificationTime += TimeSpan.FromSeconds(100);
            Assert.AreNotEqual(unixData.ModificationTime, modTime);
            unixData.SetData(rawData, 0, rawData.Length);
            Assert.AreEqual(0x5455, unixData.TagID, "TagID mismatch");
            Assert.AreEqual(modTime, unixData.ModificationTime, "Unix mod time incorrect");
        }
Ejemplo n.º 12
0
 private static ITaggedData Create(short tag, byte[] data, int offset, int count)
 {
     ITaggedData taggedData;
     if (tag != 10)
     {
         if (tag != 21589)
         {
             taggedData = new RawTaggedData(tag);
         }
         else
         {
             taggedData = new ExtendedUnixData();
         }
     }
     else
     {
         taggedData = new NTTaggedData();
     }
     taggedData.SetData(data, offset, count);
     return taggedData;
 }