public async Task <List <BitmapImage> > Extract(string Uri) { _extractProgress.Title = "Extracting..."; _extractProgress.ShowAsync(); return(await UnzipFileHelper(Uri)); }
public async Task <StorageFile> Download(string uri) { Uri source = new Uri(uri + @"/download"); HttpClient client = new HttpClient(); var result = await client.GetAsync(source, HttpCompletionOption.ResponseHeadersRead); var content = result.Content; var header = content.Headers; //Clean invalid chars in filename string fileName = CleanFileName(header.ContentDisposition.FileName); StorageFolder d = await StorageFolder.GetFolderFromPathAsync(ApplicationData.Current.LocalCacheFolder.Path); StorageFile file = await d.CreateFileAsync(fileName, CreationCollisionOption.OpenIfExists); var size = await file.GetBasicPropertiesAsync(); if (size.Size == 0) { _progress = new DownloadProgress(); _progress.ShowAsync(); _backgroundDownloader = new BackgroundDownloader(); Progress <DownloadOperation> progress = new Progress <DownloadOperation>(progressChanged); _downloadOperation = _backgroundDownloader.CreateDownload(source, file); _downloadOperation.StartAsync(); await _downloadOperation.AttachAsync().AsTask(_cancellationTokenSourceken.Token, progress); } return(file); }
public async Task <List <BitmapImage> > Extract(string Uri) { _progress.Title = "Reading ..."; _progress.ShowAsync(); int numOfFile = 0; List <BitmapImage> images = new List <BitmapImage>(); StorageFolder fd = await StorageFolder.GetFolderFromPathAsync(Uri); var fileList = await fd.GetFilesAsync(); int totalFile = fileList.Count; foreach (var storageFile in fileList) { if (storageFile.IsOfType(StorageItemTypes.File)) { numOfFile++; string mediaType = storageFile.ContentType.Split('/')[0]; if (mediaType == "image") { using (var stream = await storageFile.OpenAsync(FileAccessMode.Read)) { var bitmapImage = new BitmapImage(); await bitmapImage.SetSourceAsync(stream); images.Add(bitmapImage); } } _progress.Percent = numOfFile * 100 / totalFile; _progress.PercentString = string.Format("{0} / {1}", numOfFile, totalFile); if (_progress.Percent == 100) { _progress.Hide(); } } } return(images); }