Catrobat.IDE.Core.Services.Common.ZipService.WriteFilesRecursiveToZip C# (CSharp) Метод

WriteFilesRecursiveToZip() приватный Метод

private WriteFilesRecursiveToZip ( ZipArchive archive, IStorage storage, string sourceBasePath, string destinationBasePath ) : System.Threading.Tasks.Task
archive System.IO.Compression.ZipArchive
storage IStorage
sourceBasePath string
destinationBasePath string
Результат System.Threading.Tasks.Task
        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);
            }
        }
    }