public static void DeleteFromSpine(IEnumerable<string> FilesTodelete) { OpfDocument doc = new OpfDocument(); XElement oldSpine = doc.GetXmlElement("spine"); XNamespace ns = oldSpine.Name.Namespace; List<XElement> newItems = new List<XElement>(); foreach (XElement item in oldSpine.Elements()) { string id = item.Attribute("idref").Value; if (!FilesTodelete.Contains(GetSrc(id))) { newItems.Add(item); } } IEnumerable<XAttribute> spine = oldSpine.Attributes(); XElement newSpine = null; if (spine.Count() > 0) { newSpine = new XElement(ns + "spine", spine, newItems); } else { //There is no spine elements XAttribute TocRef = new XAttribute("toc", doc.GetNCXid()); newSpine = new XElement(ns + "spine", TocRef, newItems); } doc.ReplaceSpine(newSpine); if (doc.SaveMessage.StartsWith("Error")) MessageBox.Show(doc.SaveMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
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); }
internal XElement ReplaceNavMap(XElement newNavMap) { OpfDocument doc = new OpfDocument(); //TOC File does not exist or is not Present in manifest if (fileExtractStream == null || fileExtractStream.Length == 0 || string.IsNullOrEmpty(Variables.NCXFile)) { //System.Windows.Forms.MessageBox.Show("No TOC file Present", Variables.BookName); //return; fileOutName = "toc.ncx"; doc.AddTocEntry(); } if (OldTOC != null) { NewTOC = new XElement(OldTOC); NewTOC.Element(ns + "navMap").ReplaceWith(newNavMap); SaveOpfFixToFile(); } else { //Create a new TOC NewTOC = new XElement(ns + "ncx", new XElement(ns + "head", ""), new XElement(ns + "docTitle", new XElement(ns + "text", Variables.BookName)), new XElement(newNavMap)); } return(NewTOC); }
protected override XElement ExportNewTOC() { List <XElement> list = new List <XElement>(); foreach (Node item in Model.Nodes) { XElement navPoint = ConvertToXElement(item); if (navPoint != null) { list.Add(navPoint); } } IEnumerable <XAttribute> spine = TOC.Attributes(); XElement navMap = null; if (spine.Count() > 0) { navMap = new XElement(ns + "spine", spine, list); } else { //There is no spine elements OpfDocument doc = new OpfDocument(); XAttribute TocRef = new XAttribute("toc", doc.GetNCXid()); navMap = new XElement(ns + "spine", TocRef, list); } OnSave(new ExportTocEventArgs(navMap)); //_NewTOC = navMap; return(navMap); }
protected override XElement ExportNewTOC() { List<XElement> list = new List<XElement>(); foreach (Node item in Model.Nodes) { XElement navPoint = ConvertToXElement(item); if (navPoint != null) { list.Add(navPoint); } } IEnumerable<XAttribute> spine = TOC.Attributes(); XElement navMap = null; if (spine.Count()>0) { navMap = new XElement(ns + "spine", spine, list); } else { //There is no spine elements OpfDocument doc = new OpfDocument(); XAttribute TocRef = new XAttribute("toc", doc.GetNCXid()); navMap = new XElement(ns + "spine", TocRef, list); } OnSave(new ExportTocEventArgs(navMap)); //_NewTOC = navMap; return navMap; }
internal XElement ReplaceNavMap(XElement newNavMap) { OpfDocument doc = new OpfDocument(); //TOC File does not exist or is not Present in manifest if (fileExtractStream == null || fileExtractStream.Length == 0 || string.IsNullOrEmpty(Variables.NCXFile)) { //System.Windows.Forms.MessageBox.Show("No TOC file Present", Variables.BookName); //return; fileOutName = "toc.ncx"; doc.AddTocEntry(); } if (OldTOC != null) { NewTOC = new XElement(OldTOC); NewTOC.Element(ns + "navMap").ReplaceWith(newNavMap); SaveOpfFixToFile(); } else { //Create a new TOC NewTOC = new XElement(ns + "ncx", new XElement(ns + "head", ""), new XElement(ns + "docTitle", new XElement(ns + "text", Variables.BookName)), new XElement(newNavMap)); } return NewTOC; }
public static void DeleteFromManifest(IEnumerable <string> FilesTodelete) { OpfDocument doc = new OpfDocument(); XElement oldManifest = doc.GetXmlElement("manifest"); XNamespace ns = oldManifest.Name.Namespace; List <XElement> newItems = new List <XElement>(); foreach (XElement item in oldManifest.Elements()) { string href = item.Attribute("href").Value; string id = item.Attribute("id").Value; string mediaType = item.Attribute("media-type").Value; if (!FilesTodelete.Contains(href)) { newItems.Add(item); } } XElement newManifest = new XElement(ns + "manifest", newItems); doc.ReplaceManifest(newManifest); //if (doc.SaveMessage.StartsWith("Error")) // MessageBox.Show(doc.SaveMessage, "Manifest Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
public static string GetId(string Src) { OpfDocument doc = new OpfDocument(); Dictionary <string, string> srcTag = doc.GetFilesList(); return(GetId(Src, srcTag)); }
private void coverToolStripMenuItem_Click(object sender, EventArgs e) { MyNode node = treeView1.SelectedNode.Tag as MyNode; NavDetails nav = node.Tag as NavDetails; OpfDocument doc = new OpfDocument(); doc.AddCoverRef(nav.File); }
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); }
private void ReplaceManifest() { OpfDocument doc = new OpfDocument(); XElement oldManifest = doc.GetXmlElement("manifest"); XNamespace ns = oldManifest.Name.Namespace; List <XElement> newItems = new List <XElement>(); Ids = new Dictionary <string, string>(); foreach (XElement item in oldManifest.Elements()) { string href = Utils.VerifyFilenameEncoding(item.Attribute("href").Value); string id = item.Attribute("id").Value; string mediaType = item.Attribute("media-type").Value; if (FilesTodelete.Contains(href)) { List <string> filesToAdd = (from i in list where i.Key.Split('#')[0] == href select i.Value).ToList(); foreach (string files in filesToAdd) { string newID = id + "-" + filesToAdd.IndexOf(files); if (!Ids.ContainsKey(newID)) { Ids.Add(newID, id); XElement newEl = new XElement(ns + "item", new XAttribute("href", files), new XAttribute("id", newID), new XAttribute("media-type", mediaType)); newItems.Add(newEl); } } } else { Ids.Add(id, id); newItems.Add(item); } } XElement newManifest = new XElement(ns + "manifest", newItems); doc.ReplaceManifest(newManifest); }
private void ReplaceSpine() { OpfDocument doc = new OpfDocument(); XElement oldSpine = doc.GetXmlElement("spine"); XNamespace ns = oldSpine.Name.Namespace; List <XElement> newItems = new List <XElement>(); foreach (XElement item in oldSpine.Elements()) { string id = item.Attribute("idref").Value; if (Ids.Values.Contains(id)) { List <string> IdsToAdd = (from i in Ids where i.Value == id select i.Key).ToList(); foreach (string ids in IdsToAdd) { XElement newEl = new XElement(ns + "itemref", new XAttribute("idref", ids)); newItems.Add(newEl); } } else { newItems.Add(item); } } IEnumerable <XAttribute> spine = oldSpine.Attributes(); XElement newSpine = null; if (spine.Count() > 0) { newSpine = new XElement(ns + "spine", spine, newItems); } else { //There is no spine elements XAttribute TocRef = new XAttribute("toc", doc.GetNCXid()); newSpine = new XElement(ns + "spine", TocRef, newItems); } doc.ReplaceSpine(newSpine); }
protected void SaveOpfFixToFile() { List <string> list = new List <string>() { "metadata", "manifest", "spine", "guide" }; OpfDocument doc = new OpfDocument(); foreach (string item in list) { XElement meta = doc.GetXmlElement(item); if (meta != null) { doc.ReplaceSection(meta, item); } } }
private string GetCoverFile() { MyOPFDoc = new OpfDocument(); string coverRef = MyOPFDoc.GetCoverRef(); //If it does not exist get first page in spine if (string.IsNullOrEmpty(coverRef) || !Utils.VerifyFileExists(coverRef)) { coverRef = MyOPFDoc.GetSpineRefAtIndex(0); } else { IsGuideEmpty = false; } return(coverRef); }
public static void DeleteFromGuide(IEnumerable<string> FilesToDelete) { OpfDocument doc = new OpfDocument(); XElement oldManifest = doc.GetXmlElement("guide"); XNamespace ns = oldManifest.Name.Namespace; List<XElement> newItems = new List<XElement>(); foreach (XElement item in oldManifest.Elements()) { string href = item.Attribute("href").Value; if (!FilesToDelete.Contains(href)) { newItems.Add(item); } } XElement newManifest = new XElement(ns + "guide", newItems); doc.ReplaceSection(newManifest, "guide"); }
public static void DeleteFromGuide(IEnumerable <string> FilesToDelete) { OpfDocument doc = new OpfDocument(); XElement oldManifest = doc.GetXmlElement("guide"); XNamespace ns = oldManifest.Name.Namespace; List <XElement> newItems = new List <XElement>(); foreach (XElement item in oldManifest.Elements()) { string href = item.Attribute("href").Value; if (!FilesToDelete.Contains(href)) { newItems.Add(item); } } XElement newManifest = new XElement(ns + "guide", newItems); doc.ReplaceSection(newManifest, "guide"); }
internal override void UpdateFile() { string text = CreateHtmlTOC(); if (!string.IsNullOrEmpty(fileOutName) || !string.IsNullOrEmpty(text)) { fileOutStream = text.ToStream(); UpdateZip(); if (CreateTOCNeeded) { //We need to add the new file inside the spine and manifest and guide OpfDocument doc = new OpfDocument(); string file = Variables.OPFpath.Length == 0 ? fileOutName : fileOutName.Replace(Variables.OPFpath, ""); doc.AddTOCContentRef(file); doc.AddHtmlFile(file);//Will also add the spine option } Utils.NewFilename(); } }
public static void DeleteFromSpine(IEnumerable <string> FilesTodelete) { OpfDocument doc = new OpfDocument(); XElement oldSpine = doc.GetXmlElement("spine"); XNamespace ns = oldSpine.Name.Namespace; List <XElement> newItems = new List <XElement>(); foreach (XElement item in oldSpine.Elements()) { string id = item.Attribute("idref").Value; if (!FilesTodelete.Contains(GetSrc(id))) { newItems.Add(item); } } IEnumerable <XAttribute> spine = oldSpine.Attributes(); XElement newSpine = null; if (spine.Count() > 0) { newSpine = new XElement(ns + "spine", spine, newItems); } else { //There is no spine elements XAttribute TocRef = new XAttribute("toc", doc.GetNCXid()); newSpine = new XElement(ns + "spine", TocRef, newItems); } doc.ReplaceSpine(newSpine); if (doc.SaveMessage.StartsWith("Error")) { MessageBox.Show(doc.SaveMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); }
public static void DeleteFromManifest(IEnumerable<string> FilesTodelete) { OpfDocument doc = new OpfDocument(); XElement oldManifest = doc.GetXmlElement("manifest"); XNamespace ns = oldManifest.Name.Namespace; List<XElement> newItems = new List<XElement>(); foreach (XElement item in oldManifest.Elements()) { string href = item.Attribute("href").Value; string id = item.Attribute("id").Value; string mediaType = item.Attribute("media-type").Value; if (!FilesTodelete.Contains(href)) { newItems.Add(item); } } XElement newManifest = new XElement(ns + "manifest", newItems); doc.ReplaceManifest(newManifest); //if (doc.SaveMessage.StartsWith("Error")) // MessageBox.Show(doc.SaveMessage, "Manifest Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
private string GetCoverFile() { MyOPFDoc = new OpfDocument(); string coverRef = MyOPFDoc.GetCoverRef(); //If it does not exist get first page in spine if (string.IsNullOrEmpty(coverRef) || !Utils.VerifyFileExists(coverRef)) coverRef = MyOPFDoc.GetSpineRefAtIndex(0); else IsGuideEmpty = false; return coverRef; }
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 string GetId(string Src) { OpfDocument doc = new OpfDocument(); Dictionary<string, string> srcTag = doc.GetFilesList(); return GetId(Src, srcTag); }
private void ReplaceSpine() { OpfDocument doc = new OpfDocument(); XElement oldSpine = doc.GetXmlElement("spine"); XNamespace ns = oldSpine.Name.Namespace; List<XElement> newItems = new List<XElement>(); foreach (XElement item in oldSpine.Elements()) { string id = item.Attribute("idref").Value; if (Ids.Values.Contains(id)) { List<string> IdsToAdd = (from i in Ids where i.Value == id select i.Key).ToList(); foreach (string ids in IdsToAdd) { XElement newEl = new XElement(ns + "itemref", new XAttribute("idref", ids)); newItems.Add(newEl); } } else { newItems.Add(item); } } IEnumerable<XAttribute> spine = oldSpine.Attributes(); XElement newSpine = null; if (spine.Count() > 0) { newSpine = new XElement(ns + "spine", spine, newItems); } else { //There is no spine elements XAttribute TocRef = new XAttribute("toc", doc.GetNCXid()); newSpine = new XElement(ns + "spine", TocRef, newItems); } doc.ReplaceSpine(newSpine); }
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 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; }
private void ReplaceManifest() { OpfDocument doc = new OpfDocument(); XElement oldManifest = doc.GetXmlElement("manifest"); XNamespace ns = oldManifest.Name.Namespace; List<XElement> newItems = new List<XElement>(); Ids = new Dictionary<string, string>(); foreach (XElement item in oldManifest.Elements()) { string href = Utils.VerifyFilenameEncoding(item.Attribute("href").Value); string id = item.Attribute("id").Value; string mediaType = item.Attribute("media-type").Value; if (FilesTodelete.Contains(href)) { List<string> filesToAdd = (from i in list where i.Key.Split('#')[0] == href select i.Value).ToList(); foreach (string files in filesToAdd) { string newID = id + "-" + filesToAdd.IndexOf(files); if (!Ids.ContainsKey(newID)) { Ids.Add(newID, id); XElement newEl = new XElement(ns + "item", new XAttribute("href", files), new XAttribute("id", newID), new XAttribute("media-type", mediaType)); newItems.Add(newEl); } } } else { Ids.Add(id, id); newItems.Add(item); } } XElement newManifest = new XElement(ns + "manifest", newItems); doc.ReplaceManifest(newManifest); }
private void tableOfContentToolStripMenuItem_Click(object sender, EventArgs e) { MyNode node = treeView1.SelectedNode.Tag as MyNode; NavDetails nav = node.Tag as NavDetails; OpfDocument doc = new OpfDocument(); doc.AddTOCContentRef(nav.File); }
protected void SaveOpfFixToFile() { List<string> list = new List<string>() { "metadata", "manifest", "spine", "guide" }; OpfDocument doc = new OpfDocument(); foreach (string item in list) { XElement meta = doc.GetXmlElement(item); if (meta != null) { doc.ReplaceSection(meta, item); } } }
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(); } }