public BookSearch() { BookSearchSingleton = this; // SIGH. this.InitializeComponent(); this.DataContext = this; this.Loaded += BookSearch_Loaded; }
/// <summary> /// Called externally in order to display a book; will use the BookNavigationData to move /// to the previous spot. /// </summary> /// <param name="bookId"></param> /// <returns></returns> public async Task DisplayBook(BookData bookData, BookLocation location = null) { // Reset all of the position values. CurrHtml = ""; CurrHtmlIndex = -1; CurrHtmlFileName = null; CurrScrollPosition = double.NaN; CurrSelectPosition = double.NaN; BookData = bookData; var bookdb = BookDataContext.Get(); var dd = bookData.DownloadData ?? CommonQueries.DownloadedBookFind(bookdb, BookData.BookId); var nav = bookData.NavigationData ?? CommonQueries.BookNavigationDataFind(bookdb, BookData.BookId); if (location == null && !string.IsNullOrEmpty(nav?.CurrSpot)) { location = BookLocation.FromJson(nav.CurrSpot); } SetReviewSymbol(); if (dd == null) { return; } var fullpath = dd.FullFilePath; if (fullpath.Contains(@"\source\repos\SimpleEpubReader\SimpleEpubReader\bin\x64\Debug\AppX\Assets\PreinstalledBooks")) { // Whoops. The initial database might incorrectly have a developer path hard-coded. // Replace with correct location. var installationFolder = FolderMethods.InstallationFolder; fullpath = $"{installationFolder}\\Assets\\PreinstalledBooks\\{dd.FileName}"; } else if (fullpath.StartsWith("PreinstalledBooks:")) { // Preinstalled books are in a sort of relative path. It's designed to be an invalid // (or at least incredibly rare) directory. var installationFolder = FolderMethods.InstallationFolder; fullpath = $"{installationFolder}\\Assets\\PreinstalledBooks\\{dd.FileName}"; } var openResult = await OpenFile(fullpath, location); switch (openResult) { case OpenResult.OK: // Set up the uiAllUpPosition var sectionSizes = new List <double>(); foreach (var file in EpubBook.ResourcesHtmlOrdered) { sectionSizes.Add(file.Content.Length); } uiAllUpPosition.SetSectionSizes(sectionSizes); // No need to set to zero; it's already set in the OpenFile!. uiAllUpPosition.UpdatePosition(0, 0); // set to zero! ApplicationView appView = ApplicationView.GetForCurrentView(); appView.Title = bookData.Title.Replace("\n", " -- "); // title is multi-line break; case OpenResult.RedownloadableError: // An error. Mark the book as not downloaded + redownload dd.CurrFileStatus = DownloadData.FileStatus.Unknown; // deleted? gone? corrupt? we really don't know. CommonQueries.BookSaveChanges(bookdb); await BookSearch.DoSwipeDownloadOrReadAsync(BookData); break; default: // An error. Mark the book as not downloaded dd.CurrFileStatus = DownloadData.FileStatus.Unknown; // deleted? gone? corrupt? we really don't know. CommonQueries.BookSaveChanges(bookdb); break; } }