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


C# ZipArchive.EndUpdate方法代码示例

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


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

示例1: CreateZip

        void CreateZip()
        {
            Console.WriteLine("creating zip file");

            // Needed contents at ZipPath:
            // Files\Application\ --> All contents requied for Programm Files (x86)\Sharpkit\
            // Files\NET\ --> the content of FrameworkDir\SharpKit
            // Files\NET_Unix\ --> only the modified files for unix. At this time, it will contain only the file SharpKit.Build.targets.
            // Files\Templates\ --> contains 'SharpKit Web Application.zip' and 'SharpKit 5 Web Application.zip'

            // Just copy the needed above files to @SourceFilesDir() and run this code.
            // @SourceFilesDir must be the parent directory of Files\

            using (var zip = new ZipArchive(ZipPath) { AddFileCallback = t => Console.WriteLine(t) })
            {
                zip.BeginUpdate();
                zip.AddDirectory(SourceFilesDir);
                zip.EndUpdate();
            }
        }
开发者ID:benbon,项目名称:SharpKit,代码行数:20,代码来源:SetupBuilder.cs

示例2: ReadSessionArchive

        /// <summary>
        /// Reads a session archive zip file into an array of Session objects
        /// </summary>
        /// <param name="sFilename">Filename to load</param>
        /// <param name="bVerboseDialogs"></param>
        /// <returns>Loaded array of sessions or null, in case of failure</returns>        
        private static Session[] ReadSessionArchive(string sFilename, bool bVerboseDialogs)
        {
            /*  Okay, given the zip, we gotta:
             *		Unzip
             *		Find all matching pairs of request, response
             *		Create new Session object for each pair
             */
            if (!File.Exists(sFilename))
            {
                FiddlerApplication.Log.LogString("SAZFormat> ReadSessionArchive Failed. File " + sFilename + " does not exist.");
                return null;
            }

            ZipArchive oZip = null;
            List<Session> outSessions = new List<Session>();

            try
            {
                // Sniff for ZIP file.
                FileStream oSniff = File.Open(sFilename, FileMode.Open, FileAccess.Read, FileShare.Read);
                if (oSniff.Length < 64 || oSniff.ReadByte() != 0x50 || oSniff.ReadByte() != 0x4B)
                {  // Sniff for 'PK'
                    FiddlerApplication.Log.LogString("SAZFormat> ReadSessionArchive Failed. " + sFilename + " is not a Fiddler-generated .SAZ archive of HTTP Sessions.");
                    oSniff.Close();
                    return null;
                }
                oSniff.Close();

                oZip = new ZipArchive(new DiskFile(sFilename));
                oZip.BeginUpdate();

                AbstractFolder oRaw = oZip.GetFolder("raw");
                if (!oRaw.Exists)
                {
                    FiddlerApplication.Log.LogString("SAZFormat> ReadSessionArchive Failed. The selected ZIP is not a Fiddler-generated .SAZ archive of HTTP Sessions.");
                    oZip.EndUpdate();
                    return null;
                }

                foreach (AbstractFile oRequestFile in oRaw.GetFiles(true, @"*_c.txt"))
                {
                    try
                    {
                        byte[] arrRequest = new byte[oRequestFile.Size];
                        Stream oFS;

                    RetryWithPassword:
                        try
                        {
                            oFS = oRequestFile.OpenRead(FileShare.Read);
                        }
                        catch (Xceed.Zip.InvalidDecryptionPasswordException)
                        {
                            Console.Write("Password-Protected Session Archive.\nEnter the password to decrypt, or enter nothing to abort opening.\n>");
                            string sPassword = Console.ReadLine();
                            if (sPassword != String.Empty)
                            {
                                oZip.DefaultDecryptionPassword = sPassword;
                                goto RetryWithPassword;
                            }

                            return null;
                        }
                        int iRead = Utilities.ReadEntireStream(oFS, arrRequest);
                        oFS.Close();
                        Debug.Assert(iRead == arrRequest.Length, "Failed to read entire request.");

                        AbstractFile oResponseFile = oRaw.GetFile(oRequestFile.Name.Replace("_c.txt", "_s.txt"));
                        if (!oResponseFile.Exists)
                        {
                            FiddlerApplication.Log.LogString("Could not find a server response for: " + oResponseFile.FullName);
                            continue;
                        }

                        byte[] arrResponse = new byte[oResponseFile.Size];
                        oFS = oResponseFile.OpenRead();
                        iRead = Utilities.ReadEntireStream(oFS, arrResponse);
                        oFS.Close();
                        Debug.Assert(iRead == arrResponse.Length, "Failed to read entire response.");

                        oResponseFile = oRaw.GetFile(oRequestFile.Name.Replace("_c.txt", "_m.xml"));

                        Session oSession = new Session(arrRequest, arrResponse);

                        if (oResponseFile.Exists)
                        {
                            oSession.LoadMetadata(oResponseFile.OpenRead());
                        }
                        oSession.oFlags["x-LoadedFrom"] = oRequestFile.Name.Replace("_c.txt", "_s.txt");
                        outSessions.Add(oSession);

                    }
                    catch (Exception eX)
                    {
//.........这里部分代码省略.........
开发者ID:LeePaulSmith,项目名称:gocardless-dotnet,代码行数:101,代码来源:SAZ-XCEEDZIP.cs

示例3: WriteSessionArchive

        private static bool WriteSessionArchive(string sFilename, Session[] arrSessions, string sPassword, bool bDisplayErrorMessages)
        {
            if ((null == arrSessions || (arrSessions.Length < 1)))
            {
                if (bDisplayErrorMessages)
                {
                    FiddlerApplication.Log.LogString("WriteSessionArchive - No Input. No sessions were provided to save to the archive.");
                }
                return false;
            }

            try
            {
                if (File.Exists(sFilename))
                {
                    File.Delete(sFilename);
                }

                DiskFile odfZip = new DiskFile(sFilename);
                ZipArchive oZip = new ZipArchive(odfZip);
                oZip.TempFolder = new MemoryFolder();

                oZip.BeginUpdate();
                ZippedFolder oZipRawFolder = (ZippedFolder)oZip.CreateFolder("raw");

#region PasswordProtectIfNeeded
                if (!String.IsNullOrEmpty(sPassword))
                {
                    if (CONFIG.bUseAESForSAZ)
                    {
                        oZip.DefaultEncryptionMethod = EncryptionMethod.WinZipAes;  // Use 256bit AES
                    }
                    oZip.DefaultEncryptionPassword = sPassword;
                }
#endregion PasswordProtectIfNeeded

                oZip.Comment = Fiddler.CONFIG.FiddlerVersionInfo + " " + GetZipLibraryInfo() + " Session Archive. See http://www.fiddler2.com";

#region ProcessEachSession
                int iFileNumber = 1;
                // Our format string must pad all session ids with leading 0s for proper sorting.
                string sFileNumberFormatter = ("D" + arrSessions.Length.ToString().Length);
               
                foreach (Session oSession in arrSessions)
                {
                    WriteSessionToSAZ(oSession, odfZip, iFileNumber, sFileNumberFormatter, null, bDisplayErrorMessages);
                    iFileNumber++;
                }
#endregion ProcessEachSession

                oZip.EndUpdate();
                return true;
            }
            catch (Exception eX)
            {
                // TODO: Should close any open handles here. 
                if (bDisplayErrorMessages)
                {
                    FiddlerApplication.Log.LogString("Failed to save Session Archive.\n\n" + eX.Message);
                }
                return false;
            }
        }
开发者ID:LeePaulSmith,项目名称:gocardless-dotnet,代码行数:63,代码来源:SAZ-XCEEDZIP.cs


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