public static void Save(Book.Book book, BookServer bookServer, Color backColor, WebSocketProgress progress, AndroidPublishSettings settings = null) { var progressWithL10N = progress.WithL10NPrefix("PublishTab.Android.File.Progress."); var folder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); if (!string.IsNullOrWhiteSpace(Settings.Default.BloomDeviceFileExportFolder) && Directory.Exists(Settings.Default.BloomDeviceFileExportFolder)) { folder = Settings.Default.BloomDeviceFileExportFolder; } var initialPath = Path.Combine(folder, book.Storage.FolderName + BookCompressor.BloomPubExtensionWithDot); var bloomdFileDescription = LocalizationManager.GetString("PublishTab.Android.bloomdFileFormatLabel", "Bloom Book for Devices", "This is shown in the 'Save' dialog when you save a bloom book in the format that works with the Bloom Reader Android App"); var filter = $"{bloomdFileDescription}|*{BookCompressor.BloomPubExtensionWithDot}"; var destFileName = Utils.MiscUtils.GetOutputFilePathOutsideCollectionFolder(initialPath, filter); if (String.IsNullOrEmpty(destFileName)) { return; } Settings.Default.BloomDeviceFileExportFolder = Path.GetDirectoryName(destFileName); PublishToAndroidApi.CheckBookLayout(book, progress); PublishToAndroidApi.SendBook(book, bookServer, destFileName, null, progressWithL10N, (publishedFileName, bookTitle) => progressWithL10N.GetMessageWithParams("Saving", "{0} is a file path", "Saving as {0}", destFileName), null, backColor, settings: settings); PublishToAndroidApi.ReportAnalytics("file", book); }
public static void Save(Book.Book book, BookServer bookServer, Color backColor, WebSocketProgress progress, AndroidPublishSettings settings = null) { var progressWithL10N = progress.WithL10NPrefix("PublishTab.Android.File.Progress."); using (var dlg = new DialogAdapters.SaveFileDialogAdapter()) { dlg.DefaultExt = BookCompressor.ExtensionForDeviceBloomBook; var bloomdFileDescription = LocalizationManager.GetString("PublishTab.Android.bloomdFileFormatLabel", "Bloom Book for Devices", "This is shown in the 'Save' dialog when you save a bloom book in the format that works with the Bloom Reader Android App"); dlg.Filter = $"{bloomdFileDescription}|*{BookCompressor.ExtensionForDeviceBloomBook}"; dlg.FileName = Path.GetFileName(book.FolderPath) + BookCompressor.ExtensionForDeviceBloomBook; if (!string.IsNullOrWhiteSpace(Settings.Default.BloomDeviceFileExportFolder) && Directory.Exists(Settings.Default.BloomDeviceFileExportFolder)) { dlg.InitialDirectory = Settings.Default.BloomDeviceFileExportFolder; //(otherwise leave to default save location) } dlg.OverwritePrompt = true; if (DialogResult.OK == dlg.ShowDialog()) { Settings.Default.BloomDeviceFileExportFolder = Path.GetDirectoryName(dlg.FileName); PublishToAndroidApi.CheckBookLayout(book, progress); PublishToAndroidApi.SendBook(book, bookServer, dlg.FileName, null, progressWithL10N, (publishedFileName, bookTitle) => progressWithL10N.GetMessageWithParams("Saving", "{0} is a file path", "Saving as {0}", dlg.FileName), null, backColor, settings: settings); PublishToAndroidApi.ReportAnalytics("file", book); } } }
private string MakeEpub(string parentDirectory, WebSocketProgress progress) { var settings = new EpubPublishUiSettings(); _epubApi.GetEpubSettingsForCurrentBook(settings); var path = Path.Combine(parentDirectory, Guid.NewGuid().ToString() + ".epub"); _epubApi.UpdateAndSave(settings, path, true, _webSocketProgress.WithL10NPrefix("PublishTab.Epub.")); return(path); }
public AccessibilityCheckApi(BloomWebSocketServer webSocketServer, BookSelection bookSelection, BookRenamedEvent bookRenamedEvent, BookSavedEvent bookSavedEvent, EpubMaker.Factory epubMakerFactory, PublishEpubApi epubApi) { _webSocketServer = webSocketServer; var progress = new WebSocketProgress(_webSocketServer, kWebSocketContext); _webSocketProgress = progress.WithL10NPrefix("AccessibilityCheck."); _epubApi = epubApi; bookSelection.SelectionChanged += (unused1, unused2) => { _webSocketServer.SendEvent(kWebSocketContext, kBookSelectionChanged); }; // we get this when the book is renamed bookRenamedEvent.Subscribe((book) => { RefreshClient(); }); // we get this when the contents of the page might have changed bookSavedEvent.Subscribe((book) => { RefreshClient(); }); }
public UsbPublisher(WebSocketProgress progress, BookServer bookServer) { _bookServer = bookServer; _progress = progress.WithL10NPrefix("PublishTab.Android.Usb.Progress."); _androidDeviceUsbConnection = new AndroidDeviceUsbConnection(); }
public bool UpdatePreview(EpubPublishUiSettings newSettings, bool force, WebSocketProgress progress = null) { _progress = progress ?? _standardProgress.WithL10NPrefix("PublishTab.Epub."); if (Program.RunningOnUiThread) { // There's some stuff inside this lock that has to run on the UI thread. // If we lock the UI thread here, we can deadlock the whole program. throw new ApplicationException(@"Must not attempt to make epubs on UI thread...will produce deadlocks"); } lock (_epubMakerLock) { if (EpubMaker != null) { EpubMaker.AbortRequested = false; } _stagingEpub = true; } // For some unknown reason, if the accessibility window is showing, some of the browser navigation // that is needed to accurately determine which content is visible simply doesn't happen. // It would be disconcerting if it popped to the top after we close it and reopen it. // So, we just close the window if it is showing when we do this. See BL-7807. // Except that opening the Ace Checker tab invokes this code path in a way that works without the // deadlock (or whatever causes the failure). This call can be detected by the progress argument not // being null. The Refresh button on the AccessibilityCheckWindow also uses this code path in the // same way, so the next two lines also allow that Refresh button to work. See BL-9341 for why // the original fix is inadequate. if (progress == null) { AccessibilityChecker.AccessibilityCheckWindow.StaticClose(); } try { _webSocketServer.SendString(kWebsocketContext, "startingEbookCreation", _previewSrc); var htmlPath = _bookSelection.CurrentSelection.GetPathHtmlFile(); var newVersion = Book.Book.ComputeHashForAllBookRelatedFiles(htmlPath); bool previewIsAlreadyCurrent; lock (_epubMakerLock) { previewIsAlreadyCurrent = _desiredEpubSettings == newSettings && EpubMaker != null && newVersion == _bookVersion && !EpubMaker.AbortRequested && !force; } if (previewIsAlreadyCurrent) { SaveAsEpub(); // just in case there's a race condition where we haven't already saved it. return(true); // preview is already up to date. } _desiredEpubSettings = newSettings; // clear the obsolete preview, if any; this also ensures that when the new one gets done, // we will really be changing the src attr in the preview iframe so the display will update. _webSocketServer.SendEvent(kWebsocketContext, kWebsocketEventId_epubReady); _bookVersion = newVersion; ReportProgress(LocalizationManager.GetString("PublishTab.Epub.PreparingPreview", "Preparing Preview")); // This three-tries loop is an attempt to recover from a weird state the system sometimes gets into // where a browser won't navigate to a temporary page that the EpubMaker uses. I'm not sure it actually // helps, once the system gets into this state even a brand new browser seems to have the same problem. // Usually there will be no exception, and the loop breaks at the end of the first iteration. for (int i = 0; i < 3; i++) { try { if (!PublishHelper.InPublishTab) { return(false); } _previewSrc = UpdateEpubControlContent(); } catch (ApplicationException ex) { if (i >= 2) { throw; } ReportProgress("Something went wrong, trying again"); continue; } break; // normal case, no exception } lock (_epubMakerLock) { if (EpubMaker.AbortRequested) { return(false); // the code that set the abort flag will request a new preview. } } } finally { lock (_epubMakerLock) { _stagingEpub = false; } } // Do pending save if the user requested it while the preview was still in progress. SaveAsEpub(); ReportProgress(LocalizationManager.GetString("PublishTab.Epub.Done", "Done")); return(true); }
public WiFiPublisher(WebSocketProgress progress, BookServer bookServer) { _bookServer = bookServer; _progress = progress.WithL10NPrefix("PublishTab.Android.Wifi.Progress."); }
public bool UpdatePreview(EpubPublishUiSettings newSettings, bool force, WebSocketProgress progress = null) { _progress = progress ?? _standardProgress.WithL10NPrefix("PublishTab.Epub."); if (Program.RunningOnUiThread) { // There's some stuff inside this lock that has to run on the UI thread. // If we lock the UI thread here, we can deadlock the whole program. throw new ApplicationException(@"Must not attempt to make epubs on UI thread...will produce deadlocks"); } lock (_epubMakerLock) { if (EpubMaker != null) { EpubMaker.AbortRequested = false; } _stagingEpub = true; } try { _webSocketServer.SendString(kWebsocketContext, "startingEbookCreation", _previewSrc); var htmlPath = _bookSelection.CurrentSelection.GetPathHtmlFile(); var newVersion = Book.Book.MakeVersionCode(File.ReadAllText(htmlPath), htmlPath); bool previewIsAlreadyCurrent; lock (_epubMakerLock) { previewIsAlreadyCurrent = _desiredEpubSettings == newSettings && EpubMaker != null && newVersion == _bookVersion && !EpubMaker.AbortRequested && !force; } if (previewIsAlreadyCurrent) { SaveAsEpub(); // just in case there's a race condition where we haven't already saved it. return(true); // preview is already up to date. } _desiredEpubSettings = newSettings; // clear the obsolete preview, if any; this also ensures that when the new one gets done, // we will really be changing the src attr in the preview iframe so the display will update. _webSocketServer.SendEvent(kWebsocketContext, kWebsocketEventId_epubReady); _bookVersion = newVersion; ReportProgress(LocalizationManager.GetString("PublishTab.Epub.PreparingPreview", "Preparing Preview")); // This three-tries loop is an attempt to recover from a weird state the system sometimes gets into // where a browser won't navigate to a temporary page that the EpubMaker uses. I'm not sure it actually // helps, once the system gets into this state even a brand new browser seems to have the same problem. // Usually there will be no exception, and the loop breaks at the end of the first iteration. for (int i = 0; i < 3; i++) { try { if (!PublishHelper.InPublishTab) { return(false); } _previewSrc = UpdateEpubControlContent(); } catch (ApplicationException ex) { if (i >= 2) { throw; } ReportProgress("Something went wrong, trying again"); continue; } break; // normal case, no exception } lock (_epubMakerLock) { if (EpubMaker.AbortRequested) { return(false); // the code that set the abort flag will request a new preview. } } } finally { lock (_epubMakerLock) { _stagingEpub = false; } } // Do pending save if the user requested it while the preview was still in progress. SaveAsEpub(); ReportProgress(LocalizationManager.GetString("PublishTab.Epub.Done", "Done")); return(true); }