本文整理汇总了C#中ICSharpCode.SharpZipLib.Zip.ZipFile.Entries方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.Entries方法的具体用法?C# ZipFile.Entries怎么用?C# ZipFile.Entries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.SharpZipLib.Zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.Entries方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FromNupkg
public static Package FromNupkg(string filePath)
{
var pkg = new Package();
pkg.Path = filePath;
pkg.PackageHash = SHAHelper.CalculateSHA512Hash(File.ReadAllText(filePath));
pkg.PackageHashAlgorithm = "SHA512";
var fInfo = new FileInfo(filePath);
pkg.Updated = fInfo.LastWriteTimeUtc;
pkg.Published = fInfo.LastWriteTimeUtc;
pkg.PackageSize = fInfo.Length;
using (var zipArchive = new ZipFile(File.OpenRead(filePath)))
{
var nuspecEntry = zipArchive.Entries().First(x => x.Name.Contains(".nuspec"));
var reader = XmlReader.Create(zipArchive.GetInputStream(nuspecEntry));
XElement element = XElement.Load(reader);
XNamespace ns = element.GetDefaultNamespace();
var nsm = new XmlNamespaceManager(reader.NameTable);
nsm.AddNamespace("ns", ns.NamespaceName);
pkg.Title = pkg.Id = element.XPathSelectElement("//ns:id", nsm).AsString();
pkg.Version = new Version(element.XPathSelectElement("//ns:version", nsm).AsString());
pkg.Author = element.XPathSelectElement("//ns:authors", nsm).AsString();
pkg.LicenceUrl = element.XPathSelectElement("//ns:licenseUrl", nsm).AsString();
pkg.ProjectUrl = element.XPathSelectElement("//ns:projectUrl", nsm).AsString();
pkg.IconUrl = element.XPathSelectElement("//ns:iconUrl", nsm).AsString();
pkg.RequireLicenseAcceptance = element.XPathSelectElement("//ns:requireLicenseAcceptance", nsm).As<bool>(false);
pkg.Description = element.XPathSelectElement("//ns:description", nsm).AsString();
pkg.Summary = element.XPathSelectElement("//ns:summary", nsm).AsString();
pkg.Copyright = element.XPathSelectElement("//ns:copyright", nsm).AsString();
pkg.Tags = element.XPathSelectElement("//ns:tags", nsm).AsString();
pkg.Language = element.XPathSelectElement("//ns:language", nsm).AsString();
var minClientVersionAttr = element.XPathSelectElement("//ns:metadata", nsm).Attribute("minClientVersion");
pkg.MinClientVersion = minClientVersionAttr != null ? minClientVersionAttr.Value : null;
var dependencyNodes = element.Descendants(ns + "dependency");
if(dependencyNodes.Any()){
pkg.Dependencies = dependencyNodes.Select(x => x.Attribute("id").Value + ":" + x.Attribute("version").Value).Aggregate((x, y) => x + "|" + y);
}
}
return pkg;
}