Exemplo n.º 1
0
        /// <summary>
        /// Common routine used in normal upload and bulk upload.
        /// </summary>
        /// <param name="book"></param>
        /// <param name="progressBox"></param>
        /// <param name="publishView"></param>
        /// <param name="languages"></param>
        /// <param name="parseId"></param>
        /// <param name="excludeAudio"></param>
        /// <returns></returns>
        internal string FullUpload(Book.Book book, LogBox progressBox, PublishView publishView, string[] languages, out string parseId, bool excludeAudio = true)
        {
            var bookFolder = book.FolderPath;

            parseId = "";             // in case of early return
            // Set this in the metadata so it gets uploaded. Do this in the background task as it can take some time.
            // These bits of data can't easily be set while saving the book because we save one page at a time
            // and they apply to the book as a whole.
            book.BookInfo.LanguageTableReferences = _parseClient.GetLanguagePointers(book.CollectionSettings.MakeLanguageUploadData(languages));
            book.BookInfo.PageCount = book.GetPages().Count();
            book.BookInfo.Save();
            progressBox.WriteStatus(LocalizationManager.GetString("PublishTab.Upload.MakingThumbnail", "Making thumbnail image..."));
            //the largest thumbnail I found on Amazon was 300px high. Prathambooks.org about the same.
            _thumbnailer.MakeThumbnailOfCover(book, 70);             // this is a sacrificial one to prime the pump, to fix BL-2673
            _thumbnailer.MakeThumbnailOfCover(book, 70);
            if (progressBox.CancelRequested)
            {
                return("");
            }
            _thumbnailer.MakeThumbnailOfCover(book, 256);
            if (progressBox.CancelRequested)
            {
                return("");
            }

            // It is possible the user never went back to the Collection tab after creating/updating the book, in which case
            // the 'normal' thumbnail never got created/updating. See http://issues.bloomlibrary.org/youtrack/issue/BL-3469.
            _thumbnailer.MakeThumbnailOfCover(book);
            if (progressBox.CancelRequested)
            {
                return("");
            }

            var uploadPdfPath = UploadPdfPath(bookFolder);

            // If there is not already a locked preview in the book folder
            // (which we take to mean the user has created a customized one that he prefers),
            // make sure we have a current correct preview and then copy it to the book folder so it gets uploaded.
            if (!FileUtils.IsFileLocked(uploadPdfPath))
            {
                progressBox.WriteStatus(LocalizationManager.GetString("PublishTab.Upload.MakingPdf", "Making PDF Preview..."));
                publishView.MakePublishPreview();
                if (RobustFile.Exists(publishView.PdfPreviewPath))
                {
                    RobustFile.Copy(publishView.PdfPreviewPath, uploadPdfPath, true);
                }
            }
            if (progressBox.CancelRequested)
            {
                return("");
            }
            return(UploadBook(bookFolder, progressBox, out parseId, Path.GetFileName(uploadPdfPath), excludeAudio));
        }
Exemplo n.º 2
0
        public void HandleThumbnailRequest(ApiRequest request)
        {
            var bookInfo = GetBookInfoFromRequestParam(request);

            lock (_thumbnailEventsLock)
            {
                if (_thumbnailEventsToWaitFor > 0)
                {
                    _thumbnailEventsToWaitFor--;
                    if (_thumbnailEventsToWaitFor == 0)
                    {
                        StartupScreenManager.StartupMilestoneReached("collectionButtonsDrawn");
                    }
                }
            }

            string path = Path.Combine(bookInfo.FolderPath, "thumbnail.png");

            if (!RobustFile.Exists(path))
            {
                // This is rarely if ever needed. Bloom already does this when selecting a book
                // or after editing it. One case (but it won't succeed) is when the book doesn't
                // HAVE an image on the cover.
                _thumbNailer.MakeThumbnailOfCover(_collectionModel.GetBookFromBookInfo(bookInfo));
            }
            if (RobustFile.Exists(path))
            {
                request.ReplyWithImage(path);
            }
            else
            {
                var errorImg = Resources.placeHolderBookThumbnail;
                if (_collectionModel.GetBookFromBookInfo(bookInfo).HasFatalError)
                {
                    errorImg = Resources.Error70x70;
                }
                var stream = new MemoryStream();
                errorImg.Save(stream, ImageFormat.Png);
                stream.Seek(0L, SeekOrigin.Begin);
                request.ReplyWithStreamContent(stream, "image/png");
                //request.Failed("Thumbnail doesn't exist, and making a new thumbnail is not yet implemented.");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Common routine used in normal upload and bulk upload.
        /// </summary>
        internal string FullUpload(Book.Book book, IProgress progress, PublishView publishView, BookUploadParameters bookParams, out string parseId)
        {
            book.Storage.CleanupUnusedSupportFiles(isForPublish: false);            // we are publishing, but this is the real folder not a copy, so play safe.
            var bookFolder = book.FolderPath;

            parseId = "";             // in case of early return
            // Set this in the metadata so it gets uploaded. Do this in the background task as it can take some time.
            // These bits of data can't easily be set while saving the book because we save one page at a time
            // and they apply to the book as a whole.
            book.BookInfo.LanguageTableReferences = ParseClient.GetLanguagePointers(book.BookData.MakeLanguageUploadData(bookParams.LanguagesToUpload));
            book.BookInfo.PageCount = book.GetPages().Count();
            book.BookInfo.Save();
            // If the caller wants to preserve existing thumbnails, recreate them only if one or more of them do not exist.
            var thumbnailsExist = File.Exists(Path.Combine(bookFolder, "thumbnail-70.png")) &&
                                  File.Exists(Path.Combine(bookFolder, "thumbnail-256.png")) &&
                                  File.Exists(Path.Combine(bookFolder, "thumbnail.png"));

            if (!bookParams.PreserveThumbnails || !thumbnailsExist)
            {
                var thumbnailMsg = LocalizationManager.GetString("PublishTab.Upload.MakingThumbnail", "Making thumbnail image...");
                progress.WriteStatus(thumbnailMsg);
                //the largest thumbnail I found on Amazon was 300px high. Prathambooks.org about the same.
                _thumbnailer.MakeThumbnailOfCover(book, 70);                 // this is a sacrificial one to prime the pump, to fix BL-2673
                _thumbnailer.MakeThumbnailOfCover(book, 70);
                if (progress.CancelRequested)
                {
                    return("");
                }
                _thumbnailer.MakeThumbnailOfCover(book, 256);
                if (progress.CancelRequested)
                {
                    return("");
                }

                // It is possible the user never went back to the Collection tab after creating/updating the book, in which case
                // the 'normal' thumbnail never got created/updating. See http://issues.bloomlibrary.org/youtrack/issue/BL-3469.
                _thumbnailer.MakeThumbnailOfCover(book);
                if (progress.CancelRequested)
                {
                    return("");
                }
            }
            var uploadPdfPath = UploadPdfPath(bookFolder);

            // If there is not already a locked preview in the book folder
            // (which we take to mean the user has created a customized one that he prefers),
            // make sure we have a current correct preview and then copy it to the book folder so it gets uploaded.
            if (!FileHelper.IsLocked(uploadPdfPath))
            {
                var pdfMsg = LocalizationManager.GetString("PublishTab.Upload.MakingPdf", "Making PDF Preview...");
                progress.WriteStatus(pdfMsg);

                publishView.MakePDFForUpload(progress);
                if (RobustFile.Exists(publishView.PdfPreviewPath))
                {
                    RobustFile.Copy(publishView.PdfPreviewPath, uploadPdfPath, true);
                }
                else
                {
                    return("");                                 // no PDF, no upload (See BL-6719)
                }
            }
            if (progress.CancelRequested)
            {
                return("");
            }

            return(UploadBook(bookFolder, progress, out parseId, Path.GetFileName(uploadPdfPath),
                              GetAudioFilesToInclude(book, bookParams.ExcludeNarrationAudio, bookParams.ExcludeMusic), GetVideoFilesToInclude(book),
                              bookParams.LanguagesToUpload, book.CollectionSettings));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Common routine used in normal upload and bulk upload.
        /// </summary>
        internal string FullUpload(Book.Book book, IProgress progress, PublishView publishView, BookUploadParameters bookParams, out string parseId)
        {
            // this (isForPublish:true) is dangerous and the product of much discussion.
            // See "finally" block later to see that we put branding files back
            book.Storage.CleanupUnusedSupportFiles(isForPublish: true);
            try
            {
                var bookFolder = book.FolderPath;
                parseId = "";                 // in case of early return

                var languagesToUpload = book.BookInfo.PublishSettings.BloomLibrary.TextLangs.IncludedLanguages().ToArray();
                // When initializing, we may set the collection's sign language to IncludeByDefault so the checkbox on the publish screen
                // gets set by default. Also, videos could have been removed since the user last visited the publish screen (e.g. bulk upload).
                // So we need to make sure we have videos before including the sign language.
                if (book.HasSignLanguageVideos())
                {
                    languagesToUpload = languagesToUpload.Union(book.BookInfo.PublishSettings.BloomLibrary.SignLangs.IncludedLanguages()).ToArray();
                }

                // Set this in the metadata so it gets uploaded. Do this in the background task as it can take some time.
                // These bits of data can't easily be set while saving the book because we save one page at a time
                // and they apply to the book as a whole.
                book.BookInfo.LanguageTableReferences =
                    ParseClient.GetLanguagePointers(book.BookData.MakeLanguageUploadData(languagesToUpload));
                book.BookInfo.PageCount = book.GetPages().Count();
                book.BookInfo.Save();
                // If the caller wants to preserve existing thumbnails, recreate them only if one or more of them do not exist.
                var thumbnailsExist = File.Exists(Path.Combine(bookFolder, "thumbnail-70.png")) &&
                                      File.Exists(Path.Combine(bookFolder, "thumbnail-256.png")) &&
                                      File.Exists(Path.Combine(bookFolder, "thumbnail.png"));
                if (!bookParams.PreserveThumbnails || !thumbnailsExist)
                {
                    var thumbnailMsg = LocalizationManager.GetString("PublishTab.Upload.MakingThumbnail",
                                                                     "Making thumbnail image...");
                    progress.WriteStatus(thumbnailMsg);
                    //the largest thumbnail I found on Amazon was 300px high. Prathambooks.org about the same.
                    _thumbnailer.MakeThumbnailOfCover(book,
                                                      70); // this is a sacrificial one to prime the pump, to fix BL-2673
                    _thumbnailer.MakeThumbnailOfCover(book, 70);
                    if (progress.CancelRequested)
                    {
                        return("");
                    }
                    _thumbnailer.MakeThumbnailOfCover(book, 256);
                    if (progress.CancelRequested)
                    {
                        return("");
                    }

                    // It is possible the user never went back to the Collection tab after creating/updating the book, in which case
                    // the 'normal' thumbnail never got created/updating. See http://issues.bloomlibrary.org/youtrack/issue/BL-3469.
                    _thumbnailer.MakeThumbnailOfCover(book);
                    if (progress.CancelRequested)
                    {
                        return("");
                    }
                }

                var  uploadPdfPath = UploadPdfPath(bookFolder);
                var  videoFiles    = GetVideoFilesToInclude(book);
                bool hasVideo      = videoFiles.Any();
                if (hasVideo)
                {
                    var skipPdfMsg = LocalizationManager.GetString("PublishTab.Upload.SkipMakingPdf", "Skipping PDF because this book has video");
                    progress.WriteStatus(skipPdfMsg);
                }
                else
                {
                    // If there is not already a locked preview in the book folder
                    // (which we take to mean the user has created a customized one that he prefers),
                    // make sure we have a current correct preview and then copy it to the book folder so it gets uploaded.
                    if (!FileHelper.IsLocked(uploadPdfPath))
                    {
                        var pdfMsg = LocalizationManager.GetString("PublishTab.Upload.MakingPdf", "Making PDF Preview...");
                        progress.WriteStatus(pdfMsg);

                        publishView.MakePDFForUpload(progress);
                        if (RobustFile.Exists(publishView.PdfPreviewPath))
                        {
                            RobustFile.Copy(publishView.PdfPreviewPath, uploadPdfPath, true);
                        }
                        else
                        {
                            return("");                            // no PDF, no upload (See BL-6719)
                        }
                    }
                }

                if (progress.CancelRequested)
                {
                    return("");
                }

                return(UploadBook(bookFolder,
                                  progress,
                                  out parseId,
                                  hasVideo ? null : Path.GetFileName(uploadPdfPath),
                                  GetAudioFilesToInclude(book, bookParams.ExcludeMusic),
                                  videoFiles,
                                  languagesToUpload,
                                  book.CollectionSettings));
            }
            finally
            {
                // Put back all the branding files which we removed above in the call to CleanupUnusedSupportFiles()
                book.UpdateSupportFiles();

                // NB: alternatively, we considered refactoring CleanupUnusedSupportFiles() to give us a list of files
                // to not upload.
            }
        }