/// <summary> /// Method to set the source of the pic from windows storage /// </summary> /// <param name="img">bitmapimage to set a source for</param> /// <param name="path">string location of the image in storage</param> /// <returns>sets the img.source to a new filestream</returns> private async Task SetSource(BitmapImage img, string path) { StorageFile imageFile = null; var folders = path.Split('/'); try { StorageFolder appBaseFolder = ApplicationData.Current.LocalFolder; StorageFolder imageFolder = await Io.CreateOrGetFolders(appBaseFolder, folders); imageFile = await imageFolder.GetFileAsync(folders[folders.Length - 1]); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } if (imageFile != null) { using (var fileStream = await imageFile.OpenReadAsync()) { if (fileStream.CanRead) { await img.SetSourceAsync(fileStream); } } } }
/// <summary> /// Unzips the .zip file into the specified folder to allow for the reading necessary /// to open the book in this app /// </summary> /// <param name="fileName"></param> /// <param name="folderName"></param> /// <returns></returns> private async Task UnZipTheFile(string fileName, string folderName) { var folder = await sFolder.GetFolderAsync(folderName); using (var stream = await sFolder.OpenStreamForReadAsync(fileName)) { using (var archive = new ZipArchive(stream)) { foreach (var entry in archive.Entries) { if (entry.FullName.Contains('/')) { if (entry.FullName.ElementAt(entry.FullName.Length - 1) == '/') { var multiFolder = entry.FullName.Substring(0, entry.FullName.Length - 1); try { await sFolder.CreateFolderAsync(folderName + "\\" + multiFolder); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } } else { var directoryName = entry.FullName.Split('/'); var lastFolder = await Io.CreateOrGetFolders(folder, directoryName); using (var file = entry.Open()) { StorageFile newFile = null; try { newFile = await lastFolder.CreateFileAsync(entry.Name, CreationCollisionOption.ReplaceExisting); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } if (newFile == null) { newFile = await lastFolder.GetFileAsync(entry.Name); } using (var trans = await newFile.OpenStreamForWriteAsync()) { file.CopyTo(trans); } } } } else { //add files to the base folder using (var file = entry.Open()) { StorageFile newFile = null; try { newFile = await folder.CreateFileAsync(entry.FullName, CreationCollisionOption.ReplaceExisting); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } if (newFile == null) { newFile = await folder.GetFileAsync(entry.FullName); } using (var trans = await newFile.OpenStreamForWriteAsync()) { file.CopyTo(trans); } } } } } } }