private static void CopyFileOrDirectory(Logger logger, string sourceDir, string root, string path) { // Root path not handled if (root.Length == 0) { throw new NotSupportedException(); } try { var zipFile = new ZipFile(sourceDir); foreach (var zipEntry in zipFile.GetAllEntries()) { var zipFilename = zipEntry.FilenameInZip; if (!zipFilename.StartsWith(root)) { continue; } // Get filename without leading "assets/data" var assetFilename = zipFilename.Substring(root.Length); var fullPath = path + assetFilename; var directoryName = VirtualFileSystem.GetParentFolder(fullPath); try { if (directoryName != string.Empty) { ApplicationData.CreateDirectory(directoryName); } } catch (IOException) { } using (var output = ApplicationData.OpenStream(fullPath, VirtualFileMode.Create, VirtualFileAccess.Write)) zipFile.ExtractFile(zipEntry, output); } } catch (IOException ex) { logger.Info("I/O Exception", ex); } }
public override Stream OpenStream(string url, VirtualFileMode mode, VirtualFileAccess access, VirtualFileShare share = VirtualFileShare.Read, StreamFlags streamType = StreamFlags.None) { // For now, block multithreading (not sure it can work or not) lock (fileSystemProvider) { if (!fileSystemProvider.FileExists(url)) { // Ensure top directory exists fileSystemProvider.CreateDirectory(VirtualFileSystem.GetParentFolder(url)); using (var asset = PlatformAndroid.Context.Assets.Open(assetRoot + url)) using (var output = fileSystemProvider.OpenStream(url, VirtualFileMode.CreateNew, VirtualFileAccess.Write, share, streamType)) asset.CopyTo(output); } } return(fileSystemProvider.OpenStream(url, mode, access)); }