private string GetTOCRef() { OpfDocument doc = new OpfDocument(); string tocRef = doc.GetHtmlTOCRef(); tocRef = string.IsNullOrEmpty(tocRef) ? string.Empty : Zip.GetFilePathInsideZip(tocRef); if (string.IsNullOrEmpty(tocRef)) { return(NewInlineTOCFile(tocRef)); } else { #if !CLI System.Windows.Forms.DialogResult result = System.Windows.Forms.MessageBox.Show("The file \"" + tocRef + "\" is already set has your Table of Content\n" + "Do you want to replace it?\n\nClicking \"No\" Will create a new Table fo Content", "Replace existing Inline Table of Content", System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Question); #else System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.OK; #endif //Add a confirmation Box before replacing a already existing Inline TOC if (result == System.Windows.Forms.DialogResult.No) { return(NewInlineTOCFile(tocRef)); } else if (result == System.Windows.Forms.DialogResult.Cancel) { tocRef = string.Empty; } } return(tocRef); }
public static bool VerifyFileExists(string filename) { string file = Zip.GetFilePathInsideZip(filename); file = string.IsNullOrEmpty(file) ? Zip.GetFilePathInsideZip(System.Web.HttpUtility.UrlDecode(filename)) : file; file = string.IsNullOrEmpty(file) ? Zip.GetFilePathInsideZip(System.Web.HttpUtility.UrlPathEncode(filename)) : file; return(string.IsNullOrEmpty(file) ? false : true); }
private string GetSource(string path) { try { string relative = RelativePath.GetRelativePath(fileOutName, Zip.GetFilePathInsideZip(path)); return(relative); } catch (Exception) { return(path); } }
internal HtmlDocument GetHtml(string filename) { try { Stream htmlStream = base.GetStreamOPF(filename); fileOutStream = htmlStream; fileOutName = Zip.GetFilePathInsideZip(filename); HtmlDocument html = new HtmlDocument(); html.OptionWriteEmptyNodes = true; html.OptionOutputOriginalCase = true; //html.OptionOutputAsXml = true; html.Load(htmlStream, Encoding.UTF8); return(html); } catch (Exception) { return(null); } }
internal override void UpdateFile() { //if (File.Exists(Variables.SigilDefaultPath)) //{ // Properties.Settings.Default.SigilPath = Variables.SigilDefaultPath; // Properties.Settings.Default.Save(); //} if (Properties.Settings.Default.SigilPath == "") { System.Windows.Forms.MessageBox.Show("Sigil path not set!"); return; } if (!File.Exists(Properties.Settings.Default.SigilPath)) { System.Windows.Forms.MessageBox.Show("Sigil not found"); return; } SaveOpfFixToFile(); //GetBackupTOC string ncxFile = Variables.NCXFile; Stream BackupTOC = GetStreamOPF(ncxFile); base.SaveBackup(); ProcessStartInfo start = new ProcessStartInfo(Properties.Settings.Default.SigilPath); start.Arguments = "\"" + Variables.Filename + "\""; start.UseShellExecute = false; Cursor.Current = Cursors.WaitCursor; Process proc = Process.Start(start); Cursor.Current = Cursors.Default; proc.WaitForExit(); Variables.OPFfile = string.Empty; Variables.NCXFile = string.Empty; Variables.ZipFileList = new List <string>(); Variables.FilesPathFromOPF = new List <string>(); OpfDocument doc = new OpfDocument(); FileList = doc.GetFilesList("html"); XElement NavMap = GetXmlElement(BackupTOC, "navMap"); RearrangeTOC(NavMap); if (!ReplaceNavMap(NavMap)) { return; } WriteXML(); //Find toc.ncx path in Zip //fileOutName = Utils.GetFilePathInsideZip(ncxFile); fileOutName = Zip.GetFilePathInsideZip(Variables.NCXFile); UpdateZip(fileOutStream); }
private void ExportNewCover(object sender, CoverChangedArgs e) { using (new HourGlass()) { if (e.Cover != null && ImageNode != null) { bool ChangedCoverFile = false; #region Replace Existing File with the New One if it is different if (!ImageCompare(e.Cover, BookImage)) { fileOutName = Zip.GetFilePathInsideZip(ImageURL); fileOutStream = e.Cover.ToStream(GetImageType(BookImage)); UpdateZip(); SaveOpfFixToFile(); e.Message = SaveMessage; ChangedCoverFile = true; } else { e.Message = "File has not changed, Aborting"; } #endregion //Make sure it is scaled to fit bool FixedCoverWidth = FixHtml(e); if (FixedCoverWidth) { MyHtmlDoc.fileOutStream = MyHtmlDoc.TidyHtml(ImageNode.OwnerDocument.DocumentNode.OuterHtml).ToStream(); MyHtmlDoc.UpdateZip(); if (PreserveAspectRatio) { e.Message = !ChangedCoverFile ? "File has not changed, But Fixing the dimensions" : e.Message; } else { e.Message = !ChangedCoverFile ? "File has not changed, But making sure that it is scaled to fit" : e.Message; } } #region If guide is empty add it if (IsGuideEmpty) { MyOPFDoc.AddCoverRef(CoverFile); e.Message = !ChangedCoverFile && !FixedCoverWidth ? "File has not changed, But fixing missing Cover Tag in guide" : e.Message; } #endregion //Check to see if the cover file is the first if (!Variables.MassUpdate) { CheckPositionOfCover(); } //Update the stream and BookImage with the new default GetImage(); e.ChangedCoverFile = ChangedCoverFile; } else { e.Message = "Cover is Empty, Aborting"; } } }