本文整理汇总了C#中ZipArchive.GetFolder方法的典型用法代码示例。如果您正苦于以下问题:C# ZipArchive.GetFolder方法的具体用法?C# ZipArchive.GetFolder怎么用?C# ZipArchive.GetFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipArchive
的用法示例。
在下文中一共展示了ZipArchive.GetFolder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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)
{
//.........这里部分代码省略.........