public static string GetId(string Src) { OpfDocument doc = new OpfDocument(); Dictionary <string, string> srcTag = doc.GetFilesList(); return(GetId(Src, srcTag)); }
public static Dictionary <string, string> GetFileList() { if (FileList == null) { OpfDocument doc = new OpfDocument(); FileList = doc.GetFilesList(); } return(FileList); }
public static string GetSrc(string idRef) { OpfDocument doc = new OpfDocument(); Dictionary <string, string> srcTag = doc.GetFilesList(); string src; if (srcTag.TryGetValue(idRef, out src)) { return(src); } return(null); }
public static System.Collections.ObjectModel.Collection <Node> RemoveNonExistantNode(System.Collections.ObjectModel.Collection <Node> NodeCollection) { OpfDocument opfDoc = new OpfDocument(); List <string> htmlFiles = opfDoc.GetFilesList("html"); for (int i = NodeCollection.Count - 1; i >= 0; i--) { Node item = NodeCollection[i]; NavDetails nav = item.Tag as NavDetails; if (nav.ContentSrc == null || !Utils.VerifyFileExists(nav.File) | !htmlFiles.Contains(nav.File)) { NodeCollection.Remove(item); } if (item.Nodes.Count > 0) { RemoveNonExistantNode(item.Nodes); } } return(NodeCollection); }
private XElement LoadFiles() { //Get Files LIst OpfDocument OpfDoc = new OpfDocument(); List<string> htmlFileLIst = OpfDoc.GetFilesList("html"); List<string> t = htmlFileLIst; //Load text from Chapter MyHtmlDocument htmlDoc = new MyHtmlDocument(); Dictionary<string, DetectedHeaders> DetectText = htmlDoc.FindHeaderTextInFile(t); //Create NavDetails ENtry for Each FIles List<NavDetails> FilesToAdd = new List<NavDetails>(); foreach (var item in DetectText) { string Text = String.Empty; Text = Variables.TextInChapters == true ? item.Value.Result.Count == 0 ? item.Key : item.Value.Result[0] : item.Key; FilesToAdd.Add(new NavDetails(Utils.GetId(item.Key), item.Key, Text)); } List<XElement> list = new List<XElement>(); //Converts the navdetails to xml foreach (var item in FilesToAdd) { XElement navPoint = ConvertToXElement(item); if (navPoint != null) { list.Add(navPoint); } } XElement navMap = new XElement(ns + "navMap", list); //return the new xml file return navMap; }
public string FindBodyStyleClass(ref string CSSfile) { OpfDocument doc = new OpfDocument(); List <string> filelist = doc.GetFilesList("html"); string file = filelist[filelist.Count / 2]; HtmlDocument html = GetHtml(file); HtmlNode BodyNode = html.DocumentNode.SelectSingleNode("//body//@class"); HtmlNode CSSNode = html.DocumentNode.SelectSingleNode("//head/link[@type='text/css']"); //Select CSS file if (CSSNode != null) { CSSfile = CSSNode.GetAttributeValue("href", "css"); string[] path = CSSfile.Split('/'); CSSfile = path[path.Length - 1]; } string tag = BodyNode.GetAttributeValue("class", ""); return(tag); }
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 LoadFiles() { try { using (new HourGlass()) { treeView1.BeginUpdate(); if (Model != null && Model.Nodes.Count > 0) { Model.Nodes.Clear(); } OpfDocument OpfDoc = new OpfDocument(); List <string> htmlFileLIst = OpfDoc.GetFilesList("html"); List <string> t = htmlFileLIst; if (!cbShowAll.Checked) { t = (from i in htmlFileLIst where !PresentFileList.Contains(i) select i).ToList(); } MyHtmlDocument htmlDoc = new MyHtmlDocument(); Dictionary <string, DetectedHeaders> DetectText = htmlDoc.FindHeaderTextInFile(t); foreach (string item in t) { DetectedHeaders det = new DetectedHeaders(); DetectText.TryGetValue(item, out det); List <string> text = det != null ? det.Result : null; MyNode n = new MyNode(item, text); n.OriginalCount = det != null ? det.OriginalCount : 0; Model.Nodes.Add(n); } SortList(); Dictionary <string, string> SrcTag = OpfDoc.GetFilesList(); foreach (MyNode item in Model.Nodes) { item.Tag = new NavDetails(Utils.GetId(item.Text, SrcTag), item.Text, item.DetectedCombo); NavDetails nav = item.Tag as NavDetails; if (AddType == AddWindowType.TOCEdit && cbShowAnchors.Checked) { List <string> Anchors = htmlDoc.FindAnchorsInFile(item.Text); if (!cbShowAll.Checked) { Anchors = (from i in Anchors where !PresentAnchors.ContainsKey(nav.File + "#" + i) select i).ToList(); } Dictionary <string, DetectedHeaders> DetectAnchorText = htmlDoc.FindAchorTextInFile(item.Text, Anchors); item.AddAnchors(Anchors, DetectAnchorText); } } RemoveEmptyNodes(); treeView1.EndUpdate(); //Utils.RemoveNonExistantNode(Model.Nodes); } } catch (Exception) { treeView1.EndUpdate(); } }
public static System.Collections.ObjectModel.Collection<Node> RemoveNonExistantNode(System.Collections.ObjectModel.Collection<Node> NodeCollection) { OpfDocument opfDoc = new OpfDocument(); List<string> htmlFiles = opfDoc.GetFilesList("html"); for (int i = NodeCollection.Count - 1; i >= 0; i--) { Node item = NodeCollection[i]; NavDetails nav = item.Tag as NavDetails; if (nav.ContentSrc == null || !Utils.VerifyFileExists(nav.File) | !htmlFiles.Contains(nav.File)) { NodeCollection.Remove(item); } if (item.Nodes.Count > 0) { RemoveNonExistantNode(item.Nodes); } } return NodeCollection; }
public static string GetSrc(string idRef) { OpfDocument doc = new OpfDocument(); Dictionary<string, string> srcTag = doc.GetFilesList(); string src; if (srcTag.TryGetValue(idRef, out src)) { return src; } return null; }
public static string GetId(string Src) { OpfDocument doc = new OpfDocument(); Dictionary<string, string> srcTag = doc.GetFilesList(); return GetId(Src, srcTag); }
public static Dictionary<string, string> GetFileList() { if (FileList == null) { OpfDocument doc = new OpfDocument(); FileList = doc.GetFilesList(); } return FileList; }
private void LoadFiles() { try { using (new HourGlass()) { treeView1.BeginUpdate(); if (Model != null && Model.Nodes.Count > 0) Model.Nodes.Clear(); OpfDocument OpfDoc = new OpfDocument(); List<string> htmlFileLIst = OpfDoc.GetFilesList("html"); List<string> t = htmlFileLIst; if (!cbShowAll.Checked) { t = (from i in htmlFileLIst where !PresentFileList.Contains(i) select i).ToList(); } MyHtmlDocument htmlDoc = new MyHtmlDocument(); Dictionary<string, DetectedHeaders> DetectText = htmlDoc.FindHeaderTextInFile(t); foreach (string item in t) { DetectedHeaders det = new DetectedHeaders(); DetectText.TryGetValue(item, out det); List<string> text = det != null ? det.Result : null; MyNode n = new MyNode(item, text); n.OriginalCount = det != null ? det.OriginalCount : 0; Model.Nodes.Add(n); } SortList(); Dictionary<string, string> SrcTag = OpfDoc.GetFilesList(); foreach (MyNode item in Model.Nodes) { item.Tag = new NavDetails(Utils.GetId(item.Text, SrcTag), item.Text, item.DetectedCombo); NavDetails nav = item.Tag as NavDetails; if (AddType == AddWindowType.TOCEdit && cbShowAnchors.Checked) { List<string> Anchors = htmlDoc.FindAnchorsInFile(item.Text); if (!cbShowAll.Checked) { Anchors = (from i in Anchors where !PresentAnchors.ContainsKey(nav.File + "#" + i) select i).ToList(); } Dictionary<string, DetectedHeaders> DetectAnchorText = htmlDoc.FindAchorTextInFile(item.Text, Anchors); item.AddAnchors(Anchors, DetectAnchorText); } } RemoveEmptyNodes(); treeView1.EndUpdate(); //Utils.RemoveNonExistantNode(Model.Nodes); } } catch (Exception) { treeView1.EndUpdate(); } }
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); }