Example #1
0
        private void OnSwipeRemove(SwipeItem sender, SwipeItemInvokedEventArgs args)
        {
            var bookdb   = BookDataContext.Get();
            var bookcard = GetBookCardFromSwipe(args);

            if (bookcard == null)
            {
                return;
            }

            var bookData = bookcard.GetBookData();
            var nd       = CommonQueries.BookNavigationDataEnsure(bookdb, bookData);

            nd.NSwipeLeft++;
            CommonQueries.BookSaveChanges(bookdb);

            bookData = args.SwipeControl.DataContext as BookData;
            Books.Remove(bookData);
        }
Example #2
0
 private void OnUserStatusChecked(object sender, RoutedEventArgs e)
 {
     if (BookData.NavigationData != null)
     {
         if (uiUserStatusAbandoned.IsChecked.Value)
         {
             BookData.NavigationData.CurrStatus = BookNavigationData.UserStatus.Abandoned;
         }
         if (uiUserStatusDone.IsChecked.Value)
         {
             BookData.NavigationData.CurrStatus = BookNavigationData.UserStatus.Done;
         }
         if (uiUserStatusReading.IsChecked.Value)
         {
             BookData.NavigationData.CurrStatus = BookNavigationData.UserStatus.Reading;
         }
         var bookdb = BookDataContext.Get();
         CommonQueries.BookSaveChanges(bookdb);
     }
 }
Example #3
0
        private async void OnSend(object sender, RoutedEventArgs e)
        {
            int nok   = 0;
            int nfail = 0;

            var           bookdb        = BookDataContext.Get();
            var           selectedBooks = GetSelectedBooks();
            StorageFolder folder        = (await EBookFolder.GetFolderSilentAsync()).Folder;

            if (folder == null)
            {
                folder = await EBookFolder.PickFolderAsync();
            }
            EbookReaderProgressControl progress = null;

            if (folder != null)
            {
                progress = new EbookReaderProgressControl();
                uiAlternateContent.Visibility = Visibility.Visible;
                uiAlternateContent.Children.Clear();
                uiAlternateContent.Children.Add(progress);
                progress.SetNBooks(selectedBooks.Count);


                foreach (var bookData in selectedBooks)
                {
                    var srcfullname = bookData.DownloadData.FullFilePath;
                    var fname       = bookData.DownloadData.FileName;
                    try
                    {
                        var src = await StorageFile.GetFileFromPathAsync(srcfullname);

                        var exists = await folder.FileExistsAsync(fname);

                        if (!exists)
                        {
                            progress.SetCurrentBook(bookData.Title);
                            Logger.Log($"SEND: sending {fname}");
                            await src.CopyAsync(folder, fname, NameCollisionOption.FailIfExists);
                        }
                        else
                        {
                            progress.AddLog($"No need to send {fname}");
                            Logger.Log($"SEND: no need to send {fname}\n");
                            ; //NOTE: possibly in the future I'll do something useful here -- like offer to
                              // re-copy the file, or verify that it's at least the same size or something.
                        }
                        var nd = CommonQueries.BookNavigationDataEnsure(bookdb, bookData);
                        nd.CurrStatus = BookNavigationData.UserStatus.CopiedToEBookReader;
                        nok++;
                    }
                    catch (Exception ex)
                    {
                        nfail++;
                        progress.AddLog($"ERROR: exception when sending {fname} message {ex.Message}\n");
                        Logger.Log($"ERROR: COPY: exception when copying {fname} message {ex.Message}");
                    }
                }
            }


            Logger.Log($"COPY: OK={nok} FAIL={nfail}\n");

            if (nok > 0)
            {
                CommonQueries.BookSaveChanges(bookdb);
            }
            if (progress != null)
            {
                progress.AddLog($"Book send complete OK={nok} FAIL={nfail}");
                await Task.Delay(5_000); // wait so the user can see something happened.
            }

            // End by closing the dialog box.
            var parent = this.Parent as ContentDialog;

            parent.Hide();
        }
Example #4
0
        /// <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;
            }
        }
        private async void OnMark(object sender, RoutedEventArgs e)
        {
            int             nok       = 0;
            var             newStatus = NewStatus;
            MarkCommandType mark      = GetCommandType();

            if (mark == MarkCommandType.ChangeStatus)
            {
                newStatus = GetUserStatus();
            }
            var deleteBook = uiDeleteFromReader.IsChecked.Value;

            var bookdb        = BookDataContext.Get();
            var selectedBooks = GetSelectedBooks();

            // Setup to delete all selected books from the Nook
            EbookReaderProgressControl progress = null;

            if (deleteBook && mark != MarkCommandType.ReviewEachBook) // ReviewEachBook does this itself.
            {
                await SetupProgressFolderAsync();

                progress = new EbookReaderProgressControl();
                uiAlternateContent.Visibility = Visibility.Visible;
                uiAlternateContent.Children.Clear();
                uiAlternateContent.Children.Add(progress);
                progress.SetNBooks(selectedBooks.Count);
            }

            switch (mark)
            {
            case MarkCommandType.ChangeStatus:
                foreach (var bookData in selectedBooks)
                {
                    var srcfullname = bookData.DownloadData.FullFilePath;
                    var fname       = bookData.DownloadData.FileName;
                    Logger.Log($"MARK: setting {fname} to {NewStatus}");

                    bool deleteOk = true;
                    if (progress != null)
                    {
                        deleteOk = await DeleteDownloadedBookAsync(progress, bookData);
                    }

                    if (deleteOk)
                    {
                        var nd = CommonQueries.BookNavigationDataEnsure(bookdb, bookData);
                        nd.CurrStatus = newStatus;
                        nok++;
                    }
                }
                break;

            case MarkCommandType.NoChange:
                break;

            case MarkCommandType.ReviewEachBook:
                SavedSelectedBooks = selectedBooks;
                SavedDeleteBook    = deleteBook;
                break;
            }

            if (nok > 0)
            {
                CommonQueries.BookSaveChanges(bookdb);
            }

            if (progress != null)
            {
                progress.AddLog($"Book move complete");
                await Task.Delay(5_000); // wait so the user can see something happened.
            }


            Logger.Log($"COPY: OK={nok}");

            // End by closing the dialog box.
            var parent = this.Parent as ContentDialog;

            parent.Hide();
        }
Example #6
0
        private static async Task <BookData> InsertFileIntoDatabase(BookDataContext bookdb, IFolder folder, string filename, bool getFullData = false)
        {
            BookData bookData = null;

            if (bookdb == null)
            {
                bookdb = BookDataContext.Get();
            }
            string fullfname = $"{folder.Path}\\{filename}";
            var    wd        = new WizardData()
            {
                FilePath = fullfname, FileName = filename
            };

            try
            {
                wd = await GutenbergFileWizard.GetDataAsync(wd, getFullData);

                if (!string.IsNullOrEmpty(wd.BookId))
                {
                    bookData = CommonQueries.BookGet(bookdb, wd.BookId);

                    //TODO: when I drop a book that's been added to the database because it was
                    // in a bookmark file (which should happen reasonably often!)
                    // then the bookData here is non-null, but also not really filled in well.
                    if (bookData == null || bookData.BookSource.StartsWith(BookData.BookSourceBookMarkFile))
                    {
                        if (wd.BD != null)
                        {
                            // Gotcha! Add to the main book database!
                            if (!string.IsNullOrEmpty(wd.BD.BookId))
                            {
                                wd.BD.Files.Add(new FilenameAndFormatData()
                                {
                                    FileName = filename,
                                    BookId   = wd.BookId,
                                    MimeType = "application/epub+zip"
                                });
                                wd.BD.BookSource = BookData.BookSourceUser;

                                // Add in possible data from the bookData set by the user
                                if (bookData != null)
                                {
                                    wd.BD.NavigationData = bookData.NavigationData;
                                    wd.BD.Review         = bookData.Review;
                                    wd.BD.Notes          = bookData.Notes;

                                    //TODO: now get this book into the database.
                                    // via some kind of merge??
                                }
                                else
                                {
                                    CommonQueries.BookAdd(bookdb, wd.BD, CommonQueries.ExistHandling.IfNotExists);
                                    CommonQueries.BookSaveChanges(bookdb);
                                    bookData = wd.BD;
                                }
                            }
                            else
                            {
                                App.Error($"ERROR: {filename} ({wd.BookId}) was unable to wizard read and get ID");
                            }
                        }
                        else
                        {
                            App.Error($"ERROR: {filename} ({wd.BookId}) was unable to wizard read");
                        }
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine($"{filename}({wd.BookId}) is {bookData.GetBestTitleForFilename()}");
                    }
                    var fullpath = folder.Path;
                    if (fullpath.Contains(@"AppX\Assets\PreinstalledBooks"))
                    {
                        // Whoops. The initial database might incorrectly have a developer path hard-coded.
                        // Replace with correct location.
                        fullpath = $"PreinstalledBooks:";
                    }
                    CommonQueries.DownloadedBookEnsureFileMarkedAsDownloaded(bookdb, wd.BookId, fullpath, filename);
                }
                else
                {
                    App.Error($"{filename} with id {wd.BookId} is not a known type of e-book");
                }
            }
            catch (Exception)
            {
                App.Error($"{filename} is not a readable e-book");
            }
            return(bookData);
        }