public override IAsyncOperation <BaseStorageFile> CopyAsync(IStorageFolder destinationFolder, string desiredNewName, NameCollisionOption option) { return(AsyncInfo.Run <BaseStorageFile>(async(cancellationToken) => { var hFile = NativeFileOperationsHelper.OpenFileForRead(ContainerPath); if (hFile.IsInvalid) { return null; } using (ZipFile zipFile = new ZipFile(new FileStream(hFile, FileAccess.Read))) { zipFile.IsStreamOwner = true; var znt = new ZipNameTransform(ContainerPath); var entry = zipFile.GetEntry(znt.TransformFile(Path)); if (entry != null) { var destFolder = destinationFolder.AsBaseStorageFolder(); var destFile = await destFolder.CreateFileAsync(desiredNewName, option.Convert()); using (var inStream = zipFile.GetInputStream(entry)) using (var outStream = await destFile.OpenStreamForWriteAsync()) { await inStream.CopyToAsync(outStream); await outStream.FlushAsync(); } return destFile; } return null; } })); }
public override IAsyncOperation <BaseStorageFile> CopyAsync(IStorageFolder destinationFolder, string desiredNewName, NameCollisionOption option) { return(AsyncInfo.Run(async(cancellationToken) => { using var ftpClient = new FtpClient(); ftpClient.Host = FtpHelpers.GetFtpHost(Path); ftpClient.Port = FtpHelpers.GetFtpPort(Path); ftpClient.Credentials = FtpManager.Credentials.Get(ftpClient.Host, FtpManager.Anonymous); if (!await ftpClient.EnsureConnectedAsync()) { return null; } BaseStorageFolder destFolder = destinationFolder.AsBaseStorageFolder(); BaseStorageFile file = await destFolder.CreateFileAsync(desiredNewName, option.Convert()); var stream = await file.OpenStreamForWriteAsync(); if (await ftpClient.DownloadAsync(stream, FtpPath, token: cancellationToken)) { return file; } return null; })); }
public override IAsyncOperation <BaseStorageFile> CopyAsync(IStorageFolder destinationFolder, string desiredNewName, NameCollisionOption option) { return(AsyncInfo.Run <BaseStorageFile>(async(cancellationToken) => { var destFolder = destinationFolder.AsBaseStorageFolder(); // Avoid calling IStorageFolder method var destFile = await destFolder.CreateFileAsync(desiredNewName, option.Convert()); using (var inStream = await this.OpenStreamForReadAsync()) using (var outStream = await destFile.OpenStreamForWriteAsync()) { await inStream.CopyToAsync(outStream); await outStream.FlushAsync(); } return destFile; })); }
public override IAsyncOperation <BaseStorageFile> CopyAsync(IStorageFolder destinationFolder, string desiredNewName, NameCollisionOption option) { return(AsyncInfo.Run(async(cancellationToken) => { using var ftpClient = GetFtpClient(); if (!await ftpClient.EnsureConnectedAsync()) { return null; } BaseStorageFolder destFolder = destinationFolder.AsBaseStorageFolder(); BaseStorageFile file = await destFolder.CreateFileAsync(desiredNewName, option.Convert()); var stream = await file.OpenStreamForWriteAsync(); return await ftpClient.DownloadAsync(stream, FtpPath, token: cancellationToken) ? file : null; })); }
public override IAsyncOperation <BaseStorageFile> CopyAsync(IStorageFolder destinationFolder, string desiredNewName, NameCollisionOption option) { return(AsyncInfo.Run <BaseStorageFile>(async(cancellationToken) => { var destFolder = destinationFolder.AsBaseStorageFolder(); // Avoid calling IStorageFolder method if (destFolder is SystemStorageFolder sysFolder) { // File created by CreateFileAsync will get immediately deleted on MTP?! (#7206) return await File.CopyAsync(sysFolder.Folder, desiredNewName, option); } var destFile = await destFolder.CreateFileAsync(desiredNewName, option.Convert()); using (var inStream = await this.OpenStreamForReadAsync()) using (var outStream = await destFile.OpenStreamForWriteAsync()) { await inStream.CopyToAsync(outStream); await outStream.FlushAsync(); } return destFile; })); }