本文整理汇总了C#中ZipArchive.AddEntry方法的典型用法代码示例。如果您正苦于以下问题:C# ZipArchive.AddEntry方法的具体用法?C# ZipArchive.AddEntry怎么用?C# ZipArchive.AddEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipArchive
的用法示例。
在下文中一共展示了ZipArchive.AddEntry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteFilesRecursiveToZip
private static void WriteFilesRecursiveToZip(ZipArchive archive, IStorage storage, string basePath)
{
string searchPattern = basePath;
string[] fileNames = storage.GetFileNames(searchPattern);
foreach (string fileName in fileNames)
{
Stream fileStream = storage.OpenFile(basePath + "/" + fileName, StorageFileMode.Open,
StorageFileAccess.Read);
archive.AddEntry(fileName, fileStream);
}
string[] directrryNames = storage.GetDirectoryNames(searchPattern);
foreach (string directoryName in directrryNames)
{
WriteFilesRecursiveToZip(archive, storage, basePath + "/" + directoryName);
}
}
示例2: CreateZipEntry
/// <summary>
/// Creates a ZipEntry of the passed node and its childs to the passed zip file.
/// </summary>
/// <param name="zip">The zip file to add the new zip entry to.</param>
/// <param name="node">The node to create a zip entry for.</param>
/// <param name="processedNodeCount">Count of the processed nodes (for recursive calls only).</param>
/// <returns>Count of the processed nodes.</returns>
private static int CreateZipEntry(ZipArchive zip, ModNode node, int processedNodeCount = 0)
{
string absPath = KSPPathHelper.GetAbsolutePath(node.Destination);
string gameDataPath = KSPPathHelper.GetPath(KSPPaths.GameData);
string path = absPath.Replace(gameDataPath + Path.DirectorySeparatorChar, string.Empty);
if (node.IsFile && node.IsInstalled)
zip.AddEntry(path, absPath);
foreach (ModNode child in node.Nodes)
processedNodeCount = CreateZipEntry(zip, child, processedNodeCount);
return processedNodeCount;
}
示例3: AddSubDirs
/// <summary>
/// Adds the sub directory to the Archive.
/// </summary>
/// <param name="parentDir">Parent directory to scan for sub directories and files.</param>
/// <param name="archive">The Archive to add the directories and files to.</param>
private static void AddSubDirs(string parentDir, ZipArchive archive)
{
foreach (string subDir in Directory.GetDirectories(parentDir))
{
foreach (string file in Directory.GetFiles(subDir))
{
string directoryName = Path.GetDirectoryName(file);
if (directoryName != null)
{
string temp = Path.Combine(directoryName.Replace(KSPPathHelper.GetPath(KSPPaths.KSPRoot) + Path.DirectorySeparatorChar, string.Empty), Path.GetFileName(file));
archive.AddEntry(temp, file);
}
}
AddSubDirs(subDir, archive);
}
}