Exemplo n.º 1
0
        /// <summary>
        /// Extracting all E-Book files from epub to disk using book key to creating sub-folder
        /// </summary>
        /// <param name="epubArchive"></param>
        /// <param name="book"></param>
        /// <returns></returns>
        public static async Task ExtractContentFilesToDiskAsync(ZipArchive epubArchive, EpubBook book)
        {
            //double progress = 20;
            //double increment = (double)80 / book.Schema.Package.Manifest.Count;
            string bookFolder = string.Empty;
            //StorageFolder destinationFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("GUTS");
            StorageFolder destinationFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;

            foreach (EpubMetadataIdentifier id in book.Schema.Package.Metadata.Identifiers)
            {
                if (!string.IsNullOrEmpty(id.Identifier))
                {
                    bookFolder = ZipPathUtils.verifyPathName(string.Format("{0}_{1}", id.Identifier, id.Id));
                    break;
                }
            }
            //StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", destinationFolder);

            //Creating uniq subfolder for the book
            StorageFolder unzipFolder = await destinationFolder.CreateFolderAsync(bookFolder, CreationCollisionOption.GenerateUniqueName);

            //Unzippin
            try
            {
                //LogStatus("Unziping file: " + zipFile.DisplayName + "...", NotifyType.StatusMessage);
                await ZipUtils.UnZipFileAsync(epubArchive, unzipFolder);

                //LogStatus("Unzip file '" + zipFile.DisplayName + "' successfully!", NotifyType.StatusMessage);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Failed to unzip file ...{0}", ex.Message));
            }

            return;
        }