private async Task WriteFilesRecursiveToZip(ZipArchive archive, IStorage storage,
string sourceBasePath, string destinationBasePath)
{
var searchPattern = sourceBasePath;
var fileNames = await storage.GetFileNamesAsync(searchPattern);
foreach (string fileName in fileNames)
{
if (fileName.EndsWith(StorageConstants.ImageThumbnailExtension))
continue;
var tempPath = Path.Combine(sourceBasePath, fileName);
using (var fileStream = await storage.OpenFileAsync(tempPath,
StorageFileMode.Open, StorageFileAccess.Read))
{
var destinationPath = Path.Combine(destinationBasePath, fileName);
var newEntry = archive.CreateEntry(destinationPath);
using (var stream = newEntry.Open())
{
await fileStream.CopyToAsync(stream);
}
}
}
var directrryNames = await storage.GetDirectoryNamesAsync(searchPattern);
foreach (string directoryName in directrryNames)
{
var tempZipPath = Path.Combine(sourceBasePath, directoryName);
var nextDestinationBasePath = Path.Combine(destinationBasePath, directoryName);
await WriteFilesRecursiveToZip(archive, storage, tempZipPath, nextDestinationBasePath);
}
}
}