Example #1
0
        public static void CreateBloomPub(BookInfo bookInfo, AndroidPublishSettings settings, string outputFolder, BookServer bookServer, IWebSocketProgress progress)
        {
            var outputPath = Path.Combine(outputFolder, Path.GetFileName(bookInfo.FolderPath) + BookCompressor.BloomPubExtensionWithDot);

            BloomPubMaker.CreateBloomPub(outputPath, bookInfo.FolderPath, bookServer, progress, bookInfo.IsSuitableForMakingShells, settings: settings);
        }
        // Precondition: bulkSaveSettings must be non-null
        public void PublishAllBooks(BulkBloomPubPublishSettings bulkSaveSettings)
        {
            BrowserProgressDialog.DoWorkWithProgressDialog(_webSocketServer, "Bulk Save BloomPubs",
                                                           (progress, worker) =>
            {
                var dest = new TemporaryFolder("BloomPubs");
                progress.MessageWithoutLocalizing($"Creating files in {dest.FolderPath}...");

                var filenameWithoutExtension = _collectionModel.CollectionSettings.DefaultBookshelf.SanitizeFilename(' ', true);
                ;
                if (bulkSaveSettings.makeBookshelfFile)
                {
                    // see https://docs.google.com/document/d/1UUvwxJ32W2X5CRgq-TS-1HmPj7gCKH9Y9bxZKbmpdAI

                    progress.MessageWithoutLocalizing($"Creating bloomshelf file...");
                    System.Diagnostics.Debug.Assert(!bulkSaveSettings.bookshelfColor.Contains("\n") && !bulkSaveSettings.bookshelfColor.Contains("\r"), "(BL-10190 Repro) Invalid bookshelfColor setting (contains newline). Please investigate!");
                    var colorString = getBloomReaderColorString(bulkSaveSettings.bookshelfColor);
                    System.Diagnostics.Debug.Assert(!colorString.Contains("\n") && !colorString.Contains("\r"), "(BL-10190 Repro) Invalid computed colorString value (contains newline). Please investigate!");

                    // OK I know this looks lame but trust me, using jsconvert to make that trivial label array is way too verbose.
                    var template =
                        "{ 'label': [{ 'en': 'bookshelf-name'}], 'id': 'id-of-the-bookshelf', 'color': 'hex-color-value'}";
                    var json = template.Replace('\'', '"')
                               .Replace("bookshelf-name", bulkSaveSettings.bookshelfLabel.Replace('"', '\''))
                               .Replace("id-of-the-bookshelf", _collectionModel.CollectionSettings.DefaultBookshelf)
                               .Replace("hex-color-value", colorString);
                    var filename       = $"{filenameWithoutExtension}.bloomshelf";
                    var bloomShelfPath = Path.Combine(dest.FolderPath, filename);
                    RobustFile.WriteAllText(bloomShelfPath, json, Encoding.UTF8);
                }

                foreach (var bookInfo in _collectionModel.TheOneEditableCollection.GetBookInfos())
                {
                    if (worker.CancellationPending)
                    {
                        progress.MessageWithoutLocalizing("Cancelled.");
                        return(true);
                    }
                    progress.MessageWithoutLocalizing($"Making BloomPUB for {bookInfo.QuickTitleUserDisplay}...",
                                                      ProgressKind.Heading);

                    var settings             = AndroidPublishSettings.GetPublishSettingsForBook(_bookServer, bookInfo);
                    settings.DistributionTag = bulkSaveSettings.distributionTag;
                    if (bulkSaveSettings.makeBookshelfFile)
                    {
                        settings.BookshelfTag = _collectionModel.CollectionSettings.DefaultBookshelf;
                    }
                    BloomPubMaker.CreateBloomPub(bookInfo, settings, dest.FolderPath, _bookServer, progress);
                }

                if (bulkSaveSettings.makeBloomBundle)
                {
                    var bloomBundlePath = Path.Combine(dest.FolderPath, $"{filenameWithoutExtension}.bloombundle");

                    var bloomBundleFile = new BloomTarArchive(bloomBundlePath);
                    bloomBundleFile.AddDirectoryContents(dest.FolderPath, new string[] { ".bloombundle" });
                    bloomBundleFile.Save();
                }

                progress.MessageWithoutLocalizing("Done.", ProgressKind.Heading);
                Process.SafeStart(dest.FolderPath);
                // true means wait for the user, don't close automatically
                return(true);
            });
        }