Example #1
0
        bool SetTimestampsFromExtendedTimeStamp(IList <ExtraField> fields, WindowsZipEntry entry)
        {
            if (fields == null || fields.Count == 0)
            {
                return(false);
            }

            DateTime modTime    = DateTime.MinValue;
            DateTime accTime    = DateTime.MinValue;
            DateTime createTime = DateTime.MinValue;

            ForEachExtraField(fields, true, (ExtraField ef) => SetExtendedTimeStampTimes(new ExtraField_ExtendedTimestamp(ef), ref modTime, ref accTime, ref createTime));

            // Central directory field only has the modification time, if at all
            if (modTime == DateTime.MinValue)
            {
                ForEachExtraField(fields, false, (ExtraField ef) => SetExtendedTimeStampTimes(new ExtraField_ExtendedTimestamp(ef), ref modTime, ref accTime, ref createTime));
            }

            // We reset the entry modification time only if we got a valid value since
            // that time is also set from the entry header in ZipEntry constructor - no
            // need to invalidate that value if we don't have anything better.
            if (modTime != DateTime.MinValue)
            {
                entry.ModificationTime = modTime;
            }

            // We don't care as much about the other times
            entry.AccessTime   = accTime;
            entry.CreationTime = createTime;

            return(true);
        }
Example #2
0
        bool SetTimestampsFromInfoZipUnixOriginal(IList <ExtraField> fields, WindowsZipEntry entry)
        {
            if (fields == null || fields.Count == 0)
            {
                return(false);
            }

            DateTime modTime = DateTime.MinValue;
            DateTime accTime = DateTime.MinValue;

            ForEachExtraField(fields, true, (ExtraField ef) => {
                var izef = new ExtraField_InfoZipUnixOriginal(ef);
                SetOriginalUnixTimeStampTimes(izef, ref modTime, ref accTime);
            });
            if (modTime == DateTime.MinValue)
            {
                ForEachExtraField(fields, false, (ExtraField ef) => SetOriginalUnixTimeStampTimes(new ExtraField_InfoZipUnixOriginal(ef), ref modTime, ref accTime));
            }

            if (modTime != DateTime.MinValue)
            {
                entry.ModificationTime = modTime;
            }

            // We ignore ID/GID here because it's less important than timestamps which may be set from other
            // fields should this one lack any of them.
            return(modTime != DateTime.MinValue || accTime != DateTime.MinValue);
        }