コード例 #1
0
 public static bool Contains(string archive, string entryName)
 {
     using (var zf = new ZipFile(archive, true))
     {
         return(zf.Find(ZipEntry.NormalizeName(entryName)) != null);
     }
 }
コード例 #2
0
        public ZipEntry Add(Stream fileStream, string entryName, CompressionType compressionType)
        {
            string   name     = ZipEntry.NormalizeName(entryName);
            ZipEntry zipEntry = Find(name);

            if (zipEntry != null)
            {
                if (!AllowReplacingEntries)
                {
                    throw new Exception(string.Format("Entry {0} already exists.", entryName));
                }
                zipEntry.SetNewStream(fileStream, compressionType);
                _isChanged = true;
            }
            else
            {
                zipEntry = new ZipEntry(fileStream, name, compressionType);
                zipEntry.UseUtf8Encoding            = UseUtf8Encoding;
                zipEntry.UseDataDescriptor          = UseDataDescriptor;
                zipEntry.UseDataDescriptorSignature = UseDataDescriptorSignature;
                _entries.Add(zipEntry);
                if (_isNew && !AllowReplacingEntries)
                {
                    zipEntry.WriteEntry(_archiveStream);
                }
            }
            _isDirty = true;
            return(zipEntry);
        }
コード例 #3
0
        public void Delete(string entryName)
        {
            if (_readOnly)
            {
                throw new Exception("ZipFile is readonly, delete can not be executed");
            }
            if (_isNew)
            {
                throw new Exception("Can not delete from new archive");
            }
            ZipEntry zipEntry = Find(ZipEntry.NormalizeName(entryName));

            if (zipEntry != null)
            {
                _entries.Remove(zipEntry);
                _isChanged = true;
                _isDirty   = true;
            }
        }
コード例 #4
0
        public ZipEntry Find(string entryName)
        {
            string name = ZipEntry.NormalizeName(entryName);

            return(_entries.FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase)));
        }