Ejemplo n.º 1
0
        private static void ZipSetp(string strDirectory, ZipOutputStream s, string parentPath, string unEncryptKey)
        {
            if (strDirectory[strDirectory.Length - 1] != '/')
            {
                strDirectory += "/";
            }
            //Crc32 crc = new Crc32();

            string[] filenames = FEPath.GetFileSystemEntries(strDirectory);

            foreach (string file in filenames) // 遍历所有的文件和目录
            {
                if (FEPath.Exists(file))       // 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
                {
                    string pPath = parentPath;
                    pPath += file.Substring(file.LastIndexOf("/") + 1);
                    pPath += "/";
                    ZipSetp(file, s, pPath, unEncryptKey);
                }
                else // 否则直接压缩文件
                {
                    string exten = FEPath.GetExtension(file);

                    if (unEncryptKey == "" || exten == "" || !unEncryptKey.Contains(exten))
                    {
                        //打开压缩文件
                        using (FileStream fs = File.OpenRead(file))
                        {
                            byte[] buffer = new byte[fs.Length];
                            fs.Read(buffer, 0, buffer.Length);
                            string   fileName = parentPath + file.Substring(file.LastIndexOf("/") + 1);
                            ZipEntry entry    = new ZipEntry(fileName);
                            entry.DateTime = DateTime.Now;
                            entry.Size     = fs.Length;
                            fs.Close();
                            //crc.Reset();
                            //crc.Update(buffer);
                            //entry.Crc = crc.Value;
                            s.PutNextEntry(entry);
                            s.Write(buffer, 0, buffer.Length);
                        }

                        if (unEncryptKey.Contains(".delete"))
                        {
                            File.Delete(file);
                        }
                    }
                }
            }
        }