当前位置: 首页>>代码示例>>C#>>正文


C# ZipOutputStream.SetComment方法代码示例

本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipOutputStream.SetComment方法的典型用法代码示例。如果您正苦于以下问题:C# ZipOutputStream.SetComment方法的具体用法?C# ZipOutputStream.SetComment怎么用?C# ZipOutputStream.SetComment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.SharpZipLib.Zip.ZipOutputStream的用法示例。


在下文中一共展示了ZipOutputStream.SetComment方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MakeZipFile

 protected void MakeZipFile(Stream storage, bool isOwner,
     string entryNamePrefix, int entries, int size, string comment)
 {
     using (ZipOutputStream zOut = new ZipOutputStream(storage)) {
         zOut.IsStreamOwner = isOwner;
         zOut.SetComment(comment);
         for (int i = 0; i < entries; ++i) {
             zOut.PutNextEntry(new ZipEntry(entryNamePrefix + (i + 1).ToString()));
             AddKnownDataToEntry(zOut, size);
         }
     }
 }
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:12,代码来源:ZipTests.cs

示例2: WriteResources

		private void WriteResources()
		{
			Tracer.Info(Tracer.Compiler, "CompilerClassLoader adding resources...");

			// BUG we need to call GetTypeWrapperFactory() to make sure that the assemblyBuilder is created (when building an empty target)
			ModuleBuilder moduleBuilder = this.GetTypeWrapperFactory().ModuleBuilder;

			for (int i = 0; i < options.jars.Count; i++)
			{
				bool hasEntries = false;
				MemoryStream mem = new MemoryStream();
				using (ZipOutputStream zip = new ZipOutputStream(mem))
				{
					if (!string.IsNullOrEmpty(options.jars[i].Comment))
					{
						zip.SetComment(options.jars[i].Comment);
					}
					zip.SetLevel(9);
					List<string> stubs = new List<string>();
					foreach (Jar.Item item in options.jars[i])
					{
						if (item.IsStub)
						{
							// we don't want stub class pseudo resources for classes loaded from the file system
							if (i != options.classesJar)
							{
								stubs.Add(item.Name);
							}
							continue;
						}
						ZipEntry zipEntry = item.ZipEntry;
						if (options.compressedResources || zipEntry.CompressionMethod != CompressionMethod.Stored)
						{
							zipEntry.CompressionMethod = CompressionMethod.Deflated;
						}
						zip.PutNextEntry(zipEntry);
						byte[] data = item.GetData();
						zip.Write(data, 0, data.Length);
						zip.CloseEntry();
						hasEntries = true;
					}
					if (stubs.Count != 0)
					{
						// generate the --ikvm-classes-- file in the jar
						ZipEntry zipEntry = new ZipEntry(JVM.JarClassList);
						zipEntry.CompressionMethod = CompressionMethod.Deflated;
						zip.PutNextEntry(zipEntry);
						BinaryWriter bw = new BinaryWriter(zip);
						bw.Write(stubs.Count);
						foreach (string classFile in stubs)
						{
							bw.Write(classFile);
						}
						bw.Flush();
						zip.CloseEntry();
						hasEntries = true;
					}
				}
				// don't include empty classes.jar
				if (i != options.classesJar || hasEntries)
				{
					mem = new MemoryStream(mem.ToArray());
					string name = options.jars[i].Name;
					if (options.targetIsModule)
					{
						name = Path.GetFileNameWithoutExtension(name) + "-" + moduleBuilder.ModuleVersionId.ToString("N") + Path.GetExtension(name);
					}
					jarList.Add(name);
					moduleBuilder.DefineManifestResource(name, mem, ResourceAttributes.Public);
				}
			}
		}
开发者ID:Semogj,项目名称:ikvm-fork,代码行数:72,代码来源:CompilerClassLoader.cs

示例3: SetCommentOversize

        public void SetCommentOversize()
        {
            var ms = new MemoryStream();
            var s = new ZipOutputStream(ms);
            //s.SetComment(new String('A', 65536));

            Assert.That(() => s.SetComment(new String('A', 65536)),
                Throws.TypeOf<ArgumentOutOfRangeException>());
        }
开发者ID:icsharpcode,项目名称:SharpZipLib,代码行数:9,代码来源:ZipTests.cs

示例4: GetArchiveFilename

        public string GetArchiveFilename(string path, string newline, out string referenceName)
        {
            var commit = GetCommitByPath(ref path, out referenceName);
            if (commit == null)
                return null;

            if (referenceName == null)
                referenceName = commit.Sha;

            var key = "archive";
            if (newline != null)
                key += newline.GetHashCode().ToString("x");
            bool exist;
            var filename = GitCache.GetCacheFilename(commit.Sha, key, out exist, true);
            if (exist)
                return filename;

            using (var zipOutputStream = new ZipOutputStream(new FileStream(filename, FileMode.Create)))
            {
                var stack = new Stack<Tree>();

                stack.Push(commit.Tree);
                while (stack.Count != 0)
                {
                    var tree = stack.Pop();
                    foreach (var entry in tree)
                    {
                        byte[] bytes;
                        switch (entry.TargetType)
                        {
                            case TreeEntryTargetType.Blob:
                                zipOutputStream.PutNextEntry(new ZipEntry(entry.Path));
                                var blob = (Blob)entry.Target;
                                bytes = blob.GetContentStream().ToBytes();
                                if (newline == null)
                                    zipOutputStream.Write(bytes, 0, bytes.Length);
                                else
                                {
                                    var encoding = FileHelper.DetectEncoding(bytes, CpToEncoding(commit.Encoding), _i18n.Value);
                                    if (encoding == null)
                                        zipOutputStream.Write(bytes, 0, bytes.Length);
                                    else
                                    {
                                        bytes = FileHelper.ReplaceNewline(bytes, encoding, newline);
                                        zipOutputStream.Write(bytes, 0, bytes.Length);
                                    }
                                }
                                break;
                            case TreeEntryTargetType.Tree:
                                stack.Push((Tree)entry.Target);
                                break;
                            case TreeEntryTargetType.GitLink:
                                zipOutputStream.PutNextEntry(new ZipEntry(entry.Path + "/.gitsubmodule"));
                                bytes = Encoding.ASCII.GetBytes(entry.Target.Sha);
                                zipOutputStream.Write(bytes, 0, bytes.Length);
                                break;
                        }
                    }
                }
                zipOutputStream.SetComment(commit.Sha);
            }

            return filename;
        }
开发者ID:supuy-ruby,项目名称:GitCandy,代码行数:64,代码来源:GitService.cs

示例5: ExecuteTask

        /// <summary>
        /// Creates the zip file.
        /// </summary>
        protected override void ExecuteTask() {
            ZipOutputStream zOutstream = null;
            
            Log(Level.Info, "Zipping {0} files to '{1}'.", 
                ZipFileSets.FileCount, ZipFile.FullName);
                
            try {
                if (!Directory.Exists(ZipFile.DirectoryName)) {
                    Directory.CreateDirectory(ZipFile.DirectoryName);
                }
            
                // set encoding to use for filenames and comment
                ZipConstants.DefaultCodePage = Encoding.CodePage;

                zOutstream = new ZipOutputStream(ZipFile.Create());

                // set compression level
                zOutstream.SetLevel(ZipLevel);

                // set comment
                if (!String.IsNullOrEmpty(Comment)) {
                    zOutstream.SetComment(Comment);
                }

                foreach (ZipFileSet fileset in ZipFileSets) {
                    string basePath = fileset.BaseDirectory.FullName;
                    if (Path.GetPathRoot(basePath) != basePath) {
                        basePath = Path.GetDirectoryName(basePath + Path.DirectorySeparatorChar);
                    }

                    // add files to zip
                    foreach (string file in fileset.FileNames) {
                        // ensure file exists (in case "asis" was used)
                        if (!File.Exists(file)) {
                            throw new BuildException(string.Format(CultureInfo.InvariantCulture,
                                "File '{0}' does not exist.", file), Location);
                        }

                        // the name of the zip entry
                        string entryName;

                        // determine name of the zip entry
                        if (!Flatten && file.StartsWith(basePath)) {
                            entryName = file.Substring(basePath.Length);
                            if (entryName.Length > 0 && entryName[0] == Path.DirectorySeparatorChar) {
                                entryName = entryName.Substring(1);
                            }

                            // remember that directory was added to zip file, so
                            // that we won't add it again later
                            string dir = Path.GetDirectoryName(file);
                            if (_addedDirs[dir] == null) {
                                _addedDirs[dir] = dir;
                            }
                        } else {
                            // flatten directory structure
                            entryName = Path.GetFileName(file);
                        }

                        // add prefix if specified
                        if (fileset.Prefix != null) {
                            entryName = fileset.Prefix + entryName;
                        }

                        // ensure directory separators are understood on linux
                        if (Path.DirectorySeparatorChar == '\\') {
                            entryName = entryName.Replace(@"\", "/");
                        }

                        // perform duplicate checking
                        if (_fileEntries.ContainsKey(entryName)) {
                            switch (DuplicateHandling) {
                                case DuplicateHandling.Add:
                                    break;
                                case DuplicateHandling.Fail:
                                    throw new BuildException(string.Format(
                                        CultureInfo.InvariantCulture, 
                                        "Duplicate file '{0}' was found.", 
                                        entryName), Location.UnknownLocation);
                                case DuplicateHandling.Preserve:
                                    // skip current entry
                                    continue;
                                default:
                                    throw new BuildException(string.Format(
                                        CultureInfo.InvariantCulture, 
                                        "Duplicate value '{0}' is not supported.", 
                                        DuplicateHandling.ToString()), 
                                        Location.UnknownLocation);
                            }
                        }

                        // create zip entry
                        ZipEntry entry = new ZipEntry(entryName);

                        // store entry (to allow for duplicate checking)
                        _fileEntries[entryName] = null;

//.........这里部分代码省略.........
开发者ID:RoastBoy,项目名称:nant,代码行数:101,代码来源:ZipTask.cs

示例6: MakeZipFile

 protected void MakeZipFile(string name, string[] names, int size, string comment)
 {
     using (var store = IsolatedStorageFile.GetUserStoreForApplication())
     {
         using (IsolatedStorageFileStream fs = store.CreateFile(name))
         {
             using (ZipOutputStream zOut = new ZipOutputStream(fs))
             {
                 zOut.SetComment(comment);
                 for (int i = 0; i < names.Length; ++i)
                 {
                     zOut.PutNextEntry(new ZipEntry(names[i]));
                     AddKnownDataToEntry(zOut, size);
                 }
                 zOut.Close();
             }
             fs.Close();
         }
     }
 }
开发者ID:rollingthunder,项目名称:slsharpziplib,代码行数:20,代码来源:ZipBase.cs

示例7: ZipDirectory

        private void ZipDirectory(string zipfile, string folder, string comment, List<KeyValuePair<string, string>> filemap)
        {
            ICSharpCode.SharpZipLib.Zip.ZipConstants.DefaultCodePage = System.Text.Encoding.UTF8.CodePage;
            ICSharpCode.SharpZipLib.Checksums.Crc32 crc = new ICSharpCode.SharpZipLib.Checksums.Crc32();
            using (System.IO.FileStream ofs = new System.IO.FileStream(zipfile, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
            using (ICSharpCode.SharpZipLib.Zip.ZipOutputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(ofs))
            {
                try
                {
                    zip.SetLevel(9);
                    if (!string.IsNullOrEmpty(comment))
                        zip.SetComment(comment);

                    int i = 0;

                    foreach (KeyValuePair<string, string> f in filemap)
                    {
                        if (Progress != null)
                            Progress(ProgressType.Compressing, f.Key, filemap.Count, i);

                        System.IO.FileInfo fi = new System.IO.FileInfo(f.Value);
                        ICSharpCode.SharpZipLib.Zip.ZipEntry ze = new ICSharpCode.SharpZipLib.Zip.ZipEntry(RelativeName(f.Key, folder).Replace('\\', '/'));
                        ze.DateTime = fi.LastWriteTime;
                        ze.Size = fi.Length;
                        zip.PutNextEntry(ze);
                        using (System.IO.FileStream fs = new System.IO.FileStream(fi.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.None))
                            Utility.CopyStream(fs, zip);

                        if (Progress != null)
                            Progress(ProgressType.Compressing, f.Key, filemap.Count, i++);
                    }

                    zip.Finish();
                }
                finally
                {
                    try { zip.Close(); }
                    catch { }
                }
            }
        }
开发者ID:kanbang,项目名称:Colt,代码行数:41,代码来源:PackageBuilder.cs

示例8: CommentTooLong

 public void CommentTooLong()
 {
     MemoryStream ms = new MemoryStream();
     ZipOutputStream s = new ZipOutputStream(ms);
     s.SetComment(new String('A', 65536));
 }
开发者ID:BackupTheBerlios,项目名称:storm-ircd-svn,代码行数:6,代码来源:ZipTests.cs

示例9: createZip

        private object createZip(Stream fileStream, string sourceDirectory, IStringFilter nf, IStringFilter df)
        {
            ZipEntryFactory entryFactory;
            switch (ZipTime)
            {
                default:
                case ZipTime.Now:
                    entryFactory = new ZipEntryFactory(DateTime.Now);
                    break;
                case ZipTime.UtcNow:
                    entryFactory = new ZipEntryFactory(DateTime.UtcNow);
                    break;
                case ZipTime.FileTime:
                    entryFactory = new ZipEntryFactory(ZipEntryFactory.TimeSetting.LastWriteTime);
                    break;
                case ZipTime.UtcFileTime:
                    entryFactory = new ZipEntryFactory(ZipEntryFactory.TimeSetting.LastWriteTimeUtc);
                    break;
            }
            entryFactory.NameTransform = new ZipNameTransform(sourceDirectory);
            entryFactory.IsUnicodeText = Unicode;

            ProgressHandler progress = delegate(object x, ProgressEventArgs y) { Context.OnProgress(1, y.Name); };
            using (ZipOutputStream zip = new ZipOutputStream(fileStream))
            {
                if (Comment!=null)
                    zip.SetComment(Context.TransformStr(Password, Transform));
                if (Password != null)
                    zip.Password = Context.TransformStr(Password, Transform);
                zip.SetLevel(Level);

                return scanDir(sourceDirectory, new scanDirParams(zip, sourceDirectory, entryFactory, progress, nf, df));
            }
        }
开发者ID:xsharper,项目名称:xsharper,代码行数:34,代码来源:Zip.cs

示例10: SignPackage

        public static void SignPackage(Stream input, X509Certificate2 certificate, Stream output, bool signWholeFile)
        {
            JarFile inputJar = null;
            ZipOutputStream outputJar = null;

            // Assume the certificate is valid for at least an hour.
            DateTime timestamp = DateTime.Parse(certificate.GetEffectiveDateString()).AddHours(1);

            inputJar = new JarFile(input);  // Don't verify.

            Stream outputStream = null;
            if (signWholeFile)
            {
                outputStream = new MemoryStream();
            }
            else
            {
                outputStream = output;
            }
            outputJar = new ZipOutputStream(outputStream);
            outputJar.SetComment(null);
            outputJar.SetLevel(9);

            JarEntry je;

            Manifest manifest = addDigestsToManifest(inputJar);

            // Everything else
            copyFiles(manifest, inputJar, outputJar, timestamp);

            // otacert
            if (signWholeFile)
            {
                addOtacert(outputJar, certificate, timestamp, manifest);
            }

            var buffer = new MemoryStream();

            // MANIFEST.MF
            je = new JarEntry(JarFile.MANIFEST_NAME);
            je.DateTime = timestamp;
            manifest.Write(buffer);
            je.Size = buffer.Length;
            outputJar.PutNextEntry(je);
            buffer.WriteTo(outputJar);

            // CERT.SF
            var signature = new MemoryStream();
            je = new JarEntry(CERT_SF_NAME);
            je.DateTime = timestamp;
            buffer.SetLength(0);
            writeSignatureFile(manifest, signature);
            signature.WriteTo(buffer);
            je.Size = buffer.Length;
            outputJar.PutNextEntry(je);
            buffer.WriteTo(outputJar);

            // CERT.RSA
            je = new JarEntry(CERT_RSA_NAME);
            je.DateTime = timestamp;
            buffer.SetLength(0);
            writeSignatureBlock(signature, certificate, buffer);
            je.Size = buffer.Length;
            outputJar.PutNextEntry(je);
            buffer.WriteTo(outputJar);

            outputJar.Close();
            outputJar = null;

            if (signWholeFile)
            {
                signWholeOutputFile(((MemoryStream)outputStream).ToArray(),
                                    output, certificate);
            }
        }
开发者ID:sebmarkbage,项目名称:signapk,代码行数:75,代码来源:SignApk.cs

示例11: SaveBackground_DoWork

    private void SaveBackground_DoWork(object sender, DoWorkEventArgs e)
    {
        try
        {
            string tmpdirectorypath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "tmp") + System.IO.Path.DirectorySeparatorChar;

            using (FileStream tempFileStream = new FileStream(ProjectSavePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None))
            {
                using (ZipOutputStream zipOutput = new ZipOutputStream(tempFileStream))
                {
                    // Zip with highest compression.
                    zipOutput.SetLevel(9);
                    zipOutput.SetComment(ProjectInfo.FileVersion.ToString());

                    //Project Data
                    string projfilename = SaveProject(tmpdirectorypath);
                    using (FileStream fileStream = new FileStream(projfilename, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        // Read full stream to in-memory buffer.
                        byte[] buffer = new byte[fileStream.Length];
                        fileStream.Read(buffer, 0, buffer.Length);

                        // Create a new entry for the current file.
                        ZipEntry entry = new ZipEntry(System.IO.Path.GetFileName(projfilename));
                        entry.DateTime = DateTime.Now;
                        entry.Size = fileStream.Length;
                        entry.Comment = "Main";
                        fileStream.Close();
                        zipOutput.PutNextEntry(entry);
                        zipOutput.Write(buffer, 0, buffer.Length);
                        buffer = null;
                    }

                    //Thumbs
                    string[] thumbs = Directory.GetFiles(Thumbpath);
                    for (int i = 0; i < thumbs.Length; i++)
                    {
                        using (FileStream fileStream = new FileStream(thumbs[i], FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            // Read full stream to in-memory buffer.
                            byte[] buffer = new byte[fileStream.Length];
                            fileStream.Read(buffer, 0, buffer.Length);

                            // Create a new entry for the current file.
                            ZipEntry entry = new ZipEntry(System.IO.Path.GetFileName(thumbs[i]));
                            entry.DateTime = DateTime.Now;
                            entry.Size = fileStream.Length;
                            entry.Comment = "Thumb";
                            fileStream.Close();
                            zipOutput.PutNextEntry(entry);
                            zipOutput.Write(buffer, 0, buffer.Length);
                            buffer = null;
                        }
                    }

                    zipOutput.Finish();
                    zipOutput.Flush();
                    zipOutput.Close();
                }
            }

            Directory.Delete(tmpdirectorypath, true);

            ProjectSaved = true;
            e.Result = true;
        }
        catch (Exception ex)
        {
            e.Result = false;
            ThreadException = ex;
        }
    }
开发者ID:TimeScience,项目名称:desert-deflicker,代码行数:72,代码来源:MainBGW.cs

示例12: SetCommentOversize

 public void SetCommentOversize()
 {
     MemoryStream ms = new MemoryStream();
     ZipOutputStream s = new ZipOutputStream(ms);
     s.SetComment(new String('A', 65536));
 }
开发者ID:firestrand,项目名称:SharpZipLib,代码行数:6,代码来源:ZipTests.cs

示例13: Pack

        /// <summary>
        /// Packs the specified dictionary.
        /// </summary>
        /// <param name="dictionary">The dictionary.</param>
        /// <param name="archivePath">The archive path.</param>
        /// <returns>The full path (including the filename) to the archive or String.Empty of the process was interrupted.</returns>
        /// <remarks>Documented by Dev03, 2007-09-10</remarks>
        public string Pack(IDictionary dictionary, string archivePath)
        {
            string dictionaryPath = ((XML.XmlDictionary)dictionary).Path;
            string fullArchivePath = String.Empty;
            if ((Path.GetFileName(archivePath).Length == 0) || (Path.GetExtension(archivePath).Length == 0))
            {
                fullArchivePath = Path.Combine(archivePath, Path.GetRandomFileName() + Resources.DICTIONARY_ARCHIVE_EXTENSION);
            }
            else
            {
                fullArchivePath = archivePath;
            }

            FileStream target = File.Create(fullArchivePath);
            //ZipConstants.DefaultCodePage = Encoding.Unicode.CodePage;   //this may possibly mean that we are not Zip compatible anymore
            ZipOutputStream zip_stream = new ZipOutputStream(target);

            // set compression level 0(low) to 9 (high)
            zip_stream.SetLevel(5);
            // write the old category id to the header for backward compatibility
            zip_stream.SetComment(String.Format(Resources.PACKER_ARCHIVE_HEADER_COMMENT_PACK, dictionary.Category.OldId));

            string dirPath = Path.GetDirectoryName(dictionaryPath);
            Directory.SetCurrentDirectory(dirPath);
            List<string> resourceList = dictionary.GetResources();

            resourceList.Add(dictionaryPath);   //add the dictionary

            if (!ReportProgressUpdate(0)) return String.Empty;
            for (int i = 0; i < resourceList.Count; i++)
            {
                string fullPath, relPath;
                if (Path.IsPathRooted(resourceList[i]))
                {
                    if (resourceList[i].StartsWith(dirPath))
                    {
                        relPath = resourceList[i].Replace(dirPath, String.Empty).Trim(new char[] { Path.DirectorySeparatorChar, ' ' });
                        fullPath = resourceList[i];
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    try
                    {
                        relPath = resourceList[i];
                        fullPath = Path.GetFullPath(resourceList[i]);
                    }
                    catch
                    {
                        continue;
                    }
                }
                if (!File.Exists(fullPath))
                    continue;

                FileStream fs = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                // allocate file buffer
                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);

                // writing zip entry and data
                ZipEntry entry = new ZipEntry(relPath);
                zip_stream.PutNextEntry(entry);
                zip_stream.Write(buffer, 0, buffer.Length);
                zip_stream.CloseEntry();
                fs.Close();

                int progress = (int)Math.Floor(100.0 * (i + 1) / resourceList.Count);
                if (!ReportProgressUpdate(progress)) return String.Empty;
            }
            if (!ReportProgressUpdate(100)) return String.Empty;

            zip_stream.Finish();
            zip_stream.Close();
            target.Close();
            return fullArchivePath;
        }
开发者ID:Stoner19,项目名称:Memory-Lifter,代码行数:88,代码来源:Pack.cs

示例14: ZipFiles

        private bool ZipFiles() {
            Crc32 crc = new Crc32();
            ZipOutputStream zs = null;

            try {
                string zipFileName = Path.GetFullPath(_zipFileName);
                string outputDirectory = Path.GetDirectoryName(zipFileName);

                string baseDirectory = null;
                if (String.IsNullOrEmpty(_workingDirectory) == false) {
                    baseDirectory = Path.GetFullPath(_workingDirectory);
                }

                if (Directory.Exists(outputDirectory) == false) {
                    Directory.CreateDirectory(outputDirectory);
                }

                Log.LogMessage("Creating zip file \"{0}\".", zipFileName);

                using (zs = new ZipOutputStream(File.Create(zipFileName))) {
                    // make sure level in range
                    _zipLevel = Math.Max(0, _zipLevel);
                    _zipLevel = Math.Min(9, _zipLevel);

                    zs.SetLevel(_zipLevel);
                    if (!String.IsNullOrEmpty(_comment)) {
                        zs.SetComment(_comment);
                    }

                    byte[] buffer = new byte[32768];

                    // add files to zip
                    foreach (ITaskItem fileItem in _files) {
                        string name = Path.GetFullPath(fileItem.ItemSpec);

                        FileInfo file = new FileInfo(name);
                        if (!file.Exists) {
                            Log.LogWarning("File Not Found: {0}.", file.FullName);
                            continue;
                        }

                        // clean up name
                        if (_flatten) {
                            name = file.Name;
                        }
                        else if (!String.IsNullOrEmpty(baseDirectory) &&
                                 name.StartsWith(baseDirectory, StringComparison.OrdinalIgnoreCase)) {
                            name = name.Substring(baseDirectory.Length);
                        }
                        name = ZipEntry.CleanName(name, true);

                        ZipEntry entry = new ZipEntry(name);
                        entry.DateTime = file.LastWriteTime;
                        entry.Size = file.Length;

                        using (FileStream fs = file.OpenRead()) {
                            crc.Reset();
                            long len = fs.Length;
                            while (len > 0) {
                                int readSoFar = fs.Read(buffer, 0, buffer.Length);
                                crc.Update(buffer, 0, readSoFar);
                                len -= readSoFar;
                            }
                            entry.Crc = crc.Value;
                            zs.PutNextEntry(entry);

                            len = fs.Length;
                            fs.Seek(0, SeekOrigin.Begin);
                            while (len > 0) {
                                int readSoFar = fs.Read(buffer, 0, buffer.Length);
                                zs.Write(buffer, 0, readSoFar);
                                len -= readSoFar;
                            }
                        }
                        Log.LogMessage("  added \"{0}\".", name);
                    }
                    zs.Finish();
                }
                Log.LogMessage("Created zip file \"{0}\" successfully.", _zipFileName);
                return true;
            }
            catch (Exception exc) {
                Log.LogErrorFromException(exc);
                return false;
            }
            finally {
                if (zs != null) {
                    zs.Close();
                }
            }
        }
开发者ID:fugaku,项目名称:scriptsharp,代码行数:91,代码来源:Zip.cs


注:本文中的ICSharpCode.SharpZipLib.Zip.ZipOutputStream.SetComment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。