public static string GetBrowserFile(bool optional, params string[] parts) { parts[0] = Path.Combine(BrowserRoot, parts[0]); return(FileLocationUtilities.GetFileDistributedWithApplication(optional, parts)); }
public MercurialExtensionHider() { _extensionPath = FileLocationUtilities.GetDirectoryDistributedWithApplication(false, "MercurialExtensions", "fixutf8"); _extensionPathRenamed = _extensionPath + "-HidingForTest"; Directory.Move(_extensionPath, _extensionPathRenamed); }
public static Book.Book PrepareBookForBloomReader(string bookFolderPath, BookServer bookServer, TemporaryFolder temp, WebSocketProgress progress, bool isTemplateBook, string creator = kCreatorBloom, AndroidPublishSettings settings = null) { // MakeDeviceXmatterTempBook needs to be able to copy customCollectionStyles.css etc into parent of bookFolderPath // And bloom-player expects folder name to match html file name. var htmPath = BookStorage.FindBookHtmlInFolder(bookFolderPath); var tentativeBookFolderPath = Path.Combine(temp.FolderPath, Path.GetFileNameWithoutExtension(htmPath)); Directory.CreateDirectory(tentativeBookFolderPath); var modifiedBook = PublishHelper.MakeDeviceXmatterTempBook(bookFolderPath, bookServer, tentativeBookFolderPath, isTemplateBook); // Although usually tentativeBookFolderPath and modifiedBook.FolderPath are the same, there are some exceptions // In the process of bringing a book up-to-date (called by MakeDeviceXmatterTempBook), the folder path may change. // For example, it could change if the original folder path contains punctuation marks now deemed dangerous. // The book will be moved to the sanitized version of the file name instead. // It can also happen if we end up picking a different version of the title (i.e. in a different language) // than the one written to the .htm file. string modifiedBookFolderPath = modifiedBook.FolderPath; if (modifiedBook.CollectionSettings.HaveEnterpriseFeatures) { ProcessQuizzes(modifiedBookFolderPath, modifiedBook.RawDom); } // Right here, let's maintain the history of what the BloomdVersion signifies to a reader. // Version 1 (as opposed to no BloomdVersion field): the bookFeatures property may be // used to report features analytics (with earlier bloomd's, the reader must use its own logic) modifiedBook.Storage.BookInfo.MetaData.BloomdVersion = 1; if (settings?.LanguagesToInclude != null) { PublishModel.RemoveUnwantedLanguageData(modifiedBook.OurHtmlDom, settings.LanguagesToInclude, modifiedBook.BookData.MetadataLanguage1IsoCode); } else if (Program.RunningHarvesterMode && modifiedBook.OurHtmlDom.SelectSingleNode(BookStorage.ComicalXpath) != null) { // This indicates that we are harvesting a book with comic speech bubbles. // For comical books, we only publish a single language. It's not currently feasible to // allow the reader to switch language in a Comical book, because typically that requires // adjusting the positions of the bubbles, and we don't yet support having more than one // set of bubble locations in a single book. See BL-7912 for some ideas on how we might // eventually improve this. In the meantime, switching language would have bad effects, // and if you can't switch language, there's no point in the book containing more than one. var languagesToInclude = new string[1] { modifiedBook.BookData.Language1.Iso639Code }; PublishModel.RemoveUnwantedLanguageData(modifiedBook.OurHtmlDom, languagesToInclude, modifiedBook.BookData.MetadataLanguage1IsoCode); } // Do this after processing interactive pages, as they can satisfy the criteria for being 'blank' HashSet <string> fontsUsed = null; using (var helper = new PublishHelper()) { helper.ControlForInvoke = ControlForInvoke; ISet <string> warningMessages = new HashSet <string>(); helper.RemoveUnwantedContent(modifiedBook.OurHtmlDom, modifiedBook, false, warningMessages); PublishHelper.SendBatchedWarningMessagesToProgress(warningMessages, progress); fontsUsed = helper.FontsUsed; } if (!modifiedBook.IsTemplateBook) { modifiedBook.RemoveBlankPages(settings?.LanguagesToInclude); } // See https://issues.bloomlibrary.org/youtrack/issue/BL-6835. RemoveInvisibleImageElements(modifiedBook); modifiedBook.Storage.CleanupUnusedSupportFiles(/*isForPublish:*/ true, settings?.AudioLanguagesToExclude); if (!modifiedBook.IsTemplateBook && RobustFile.Exists(Path.Combine(modifiedBookFolderPath, "placeHolder.png"))) { RobustFile.Delete(Path.Combine(modifiedBookFolderPath, "placeHolder.png")); } modifiedBook.RemoveObsoleteAudioMarkup(); // We want these to run after RemoveUnwantedContent() so that the metadata will more accurately reflect // the subset of contents that are included in the .bloomd // Note that we generally want to disable features here, but not enable them, especially while // running harvester! See https://issues.bloomlibrary.org/youtrack/issue/BL-8995. var enableBlind = modifiedBook.BookInfo.MetaData.Feature_Blind || !Program.RunningHarvesterMode; // BloomReader and BloomPlayer are not using the SignLanguage feature, and it's misleading to // assume the existence of videos implies sign language. There is a separate "Video" feature // now that gets set automatically. (Automated setting of the Blind feature is imperfect, but // more meaningful than trying to automate sign language just based on one video existing.) var enableSignLanguage = modifiedBook.BookInfo.MetaData.Feature_SignLanguage; modifiedBook.UpdateMetadataFeatures( isBlindEnabled: enableBlind, isSignLanguageEnabled: enableSignLanguage, isTalkingBookEnabled: true); // talkingBook is only ever set automatically as far as I can tell. modifiedBook.SetAnimationDurationsFromAudioDurations(); modifiedBook.OurHtmlDom.SetMedia("bloomReader"); modifiedBook.OurHtmlDom.AddOrReplaceMetaElement("bloom-digital-creator", creator); EmbedFonts(modifiedBook, progress, fontsUsed, FontFileFinder.GetInstance(Program.RunningUnitTests)); var bookFile = BookStorage.FindBookHtmlInFolder(modifiedBook.FolderPath); StripImgIfWeCannotFindFile(modifiedBook.RawDom, bookFile); StripContentEditableAndTabIndex(modifiedBook.RawDom); InsertReaderStylesheet(modifiedBook.RawDom); RobustFile.Copy(FileLocationUtilities.GetFileDistributedWithApplication(BloomFileLocator.BrowserRoot, "publish", "ReaderPublish", "readerStyles.css"), Path.Combine(modifiedBookFolderPath, "readerStyles.css")); ConvertImagesToBackground(modifiedBook.RawDom); AddDistributionFile(modifiedBookFolderPath, creator); modifiedBook.Save(); return(modifiedBook); }
public InstructionsDialogBox() { InitializeComponent(); _browser.Navigate(FileLocationUtilities.GetFileDistributedWithApplication("instructions.htm")); }
public bool ShowPdf(string pdfFile) { _pdfPath = pdfFile; #if !__MonoCS__ var arc = _pdfViewerControl as AdobeReaderControl; if (arc != null) // We haven't yet had a problem displaying with Acrobat... { if (arc.ShowPdf(pdfFile)) { return(true); // success using acrobat } // Acrobat not working (probably not installed). Switch to using Gecko to display PDF. UpdatePdfViewer(new GeckoWebBrowser()); // and continue to show it using that. } #endif // Escaping the filename twice for characters like # is needed in order to get the // pdf filename through Geckofx/xulrunner to our local server on Linux. This is to // prevent the filename from being cut short at the # character. As far as I can // tell, Linux xulrunner strips one level of escaping on input, then before passing // the query on to the localhost server it truncates the query portion at the first // # it sees. The localhost processor expects one level of encoding, and we deal // with having a # in the query (file path) there without any problem. You may // regard this double escaping as a hack to get around the Linux xulrunner which // behaves differently than the Windows xulrunner. It is an exception to the rule // of matching EscapeFileNameForHttp() with UnescapeFileNameForHttp(). See a comment in // https://jira.sil.org/browse/BL-951 for a description of the buggy program // behavior without this hack. var file = pdfFile; if (SIL.PlatformUtilities.Platform.IsUnix) { file = file.EscapeFileNameForHttp().EscapeFileNameForHttp(); } var url = string.Format("{0}{1}?file=/bloom/{2}", Api.BloomServer.ServerUrlWithBloomPrefixEndingInSlash, FileLocationUtilities.GetFileDistributedWithApplication("pdf/web/viewer.html"), file); var browser = ((GeckoWebBrowser)_pdfViewerControl); browser.Navigate(url); browser.DocumentCompleted += (sender, args) => { // We want to suppress several of the buttons that the control normally shows. // It's nice if we don't have to modify the html and related files, because they are unzipped from a package we install // from a source I'm not sure we control, and installed into a directory we can't modify at runtime. // A workaround is to tweak the stylesheet to hide them. The actual buttons (and two menu items) are easily // hidden by ID. // Unfortunately we're getting rid of a complete group in the pull-down menu, which leaves an ugly pair of // adjacent separators. And the separators don't have IDs so we can't easily select just one to hide. // Fortunately there are no other divs in the parent (besides the separator) so we just hide the second one. // This is unfortunately rather fragile and may not do exactly what we want if the viewer.html file // defining the pdfjs viewer changes. GeckoStyleSheet stylesheet = browser.Document.StyleSheets.First(); stylesheet.CssRules.Add("#toolbarViewerRight, #viewOutline, #viewAttachments, #viewThumbnail, #viewFind {display: none}"); stylesheet.CssRules.Add("#previous, #next, #pageNumberLabel, #pageNumber, #numPages {display: none}"); stylesheet.CssRules.Add("#toolbarViewerLeft .splitToolbarButtonSeparator {display: none}"); #if !__MonoCS__ if (!_haveShownAdobeReaderRecommendation) { _haveShownAdobeReaderRecommendation = true; var message = LocalizationManager.GetString("PublishTab.Notifications.AdobeReaderRecommendation", "This PDF viewer can be improved by installing the free Adobe Reader on this computer."); RunJavaScript("toastr.remove();" + "toastr.options = { 'positionClass': 'toast-bottom-right','timeOut': '15000'};" + "toastr['info']('" + message + "')"); } #endif }; return(true); }
public void CloneAndShrinkProject(string originalProjectFolder, string destinationFolder) { FFmpegRunner.FFmpegLocation = FileLocationUtilities.GetFileDistributedWithApplication("FFmpeg", "ffmpeg.exe"); RequireThat.Directory(destinationFolder).DoesNotExist(); RequireThat.Directory(originalProjectFolder).Exists(); Directory.CreateDirectory(destinationFolder); //we don't currently process anything at this level, just copy it foreach (var original in Directory.GetFiles(originalProjectFolder)) { File.Copy(original, Path.Combine(destinationFolder, Path.GetFileName(original))); } foreach (var directory in Directory.GetDirectories(originalProjectFolder)) { var currentDestSubDirectory = Path.Combine(destinationFolder, Path.GetFileName(directory)); Directory.CreateDirectory(currentDestSubDirectory); //we don't currently process anything at this level, just copy it foreach (var original in Directory.GetFiles(directory)) { File.Copy(original, Path.Combine(currentDestSubDirectory, Path.GetFileName(original))); } foreach (var sub in Directory.GetDirectories(directory)) { var currentDestSubSubDirectory = Path.Combine(currentDestSubDirectory, Path.GetFileName(sub)); Directory.CreateDirectory(currentDestSubSubDirectory); foreach (var original in Directory.GetFiles(sub)) { Debug.WriteLine("File: " + original); if (original.Contains("-small")) { continue; } if (original.EndsWith(".meta")) { continue; } if (original.EndsWith(".smd")) //artifact of old version { continue; } var extension = Path.GetExtension(original).ToLower(); string newPath = string.Empty; var newPathRoot = Path.Combine(currentDestSubSubDirectory, Path.GetFileNameWithoutExtension(original)); switch (extension) { default: File.Copy(original, Path.Combine(currentDestSubSubDirectory, Path.GetFileName(original))); break; case ".mov": case ".avi": case ".mp4": newPath = ShrinkVideo(original, newPathRoot); break; case ".jpg": newPath = ShrinkPicture(original, newPathRoot); break; case ".wav": case ".mp3": newPath = ShrinkAudio(original, newPathRoot); break; case ".meta": break; } if (!string.IsNullOrEmpty(newPath) && File.Exists(newPath) && File.Exists(original + ".meta")) { Debug.WriteLine("copying metadata"); File.Move(original + ".meta", newPath + ".meta"); } Debug.WriteLine(""); } } } }
/// ------------------------------------------------------------------------------------ private void HandleHelpAboutClick(object sender, EventArgs e) { using (var dlg = new SIL.Windows.Forms.Miscellaneous.SILAboutBox(FileLocationUtilities.GetFileDistributedWithApplication("aboutbox.htm"))) dlg.ShowDialog(); }
public static string GetBrowserDirectory(params string[] parts) { parts[0] = Path.Combine(BrowserRoot, parts[0]); return(FileLocationUtilities.GetDirectoryDistributedWithApplication(false, parts)); }