/// <summary> /// Returns language Script(font-name) used in dictionary /// </summary> /// <returns></returns> public static string GetLanguageScriptList(string xhtmlFileNameWithPath, string projectInputType) { if (Path.GetFileName(xhtmlFileNameWithPath).IndexOf("Preserve") == 0) { xhtmlFileNameWithPath = xhtmlFileNameWithPath.Replace(Path.GetFileName(xhtmlFileNameWithPath), Path.GetFileName(xhtmlFileNameWithPath).Replace( "Preserve", "")); } string languageCode = string.Empty; if (projectInputType.ToLower() == "dictionary") { List<string> langCodeList = new List<string>(); XmlDocument xDoc = Common.DeclareXMLDocument(true); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xDoc.NameTable); namespaceManager.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml"); xDoc.Load(xhtmlFileNameWithPath); XmlNodeList fontList = xDoc.GetElementsByTagName("meta"); for (int i = 0; i < fontList.Count; i++) { string langName = fontList[i].Attributes["name"].Value; string langContent = fontList[i].Attributes["content"].Value; if (langName.ToLower().IndexOf("dc.language") != 0) continue; if (langContent.IndexOf(':') > 0 && langContent.IndexOf('-') > 0) { if (!langCodeList.Contains(langContent)) { langCodeList.Add(langContent); languageCode = languageCode + langContent; if (i < fontList.Count) { languageCode = languageCode + ","; } } } } } else { languageCode = Common.ParaTextEthnologueCodeName(); if (languageCode.Length > 0 && languageCode.IndexOf('-') > 0) { string[] val = languageCode.Split('-'); languageCode = val[1]; } } return languageCode; }
public static string GetFontList(string xhtmlFileNameWithPath, string projectInputType, string finalOutput) { if (Path.GetFileName(xhtmlFileNameWithPath).IndexOf("Preserve") == 0) { xhtmlFileNameWithPath = xhtmlFileNameWithPath.Replace(Path.GetFileName(xhtmlFileNameWithPath), Path.GetFileName(xhtmlFileNameWithPath).Replace( "Preserve", "")); } string fontList = string.Empty; if (finalOutput == ".epub") { List<string> langCodeList = new List<string>(); string[] epubFile = Directory.GetFiles(Path.GetDirectoryName(xhtmlFileNameWithPath), "*.epub"); string epubFileName = epubFile[0]; string extractFolder = Common.PathCombine(Path.GetDirectoryName(epubFileName), "Test"); if (File.Exists(epubFileName)) { ZipUtil.UnZipFiles(epubFileName, extractFolder, "", false); if (Directory.Exists(Common.PathCombine(extractFolder, "OEBPS"))) { string[] ttfFiles = Directory.GetFiles(Common.PathCombine(extractFolder, "OEBPS"), "*.ttf"); if (ttfFiles.Length > 0) { for (int i = 0; i < ttfFiles.Length; i++) { string filename = Path.GetFileNameWithoutExtension(ttfFiles[i]); if (filename.IndexOf('-') > 0) { filename = filename.Substring(0, filename.IndexOf('-')); } if (!langCodeList.Contains(filename)) { langCodeList.Add(filename); fontList = fontList + filename; if (i < ttfFiles.Length - 1) { fontList = fontList + ";"; } } } } } } if (Directory.Exists(extractFolder)) { DirectoryInfo di = new DirectoryInfo(extractFolder); Common.CleanDirectory(di); } } else { List<string> langCodeList = new List<string>(); XmlDocument xDoc = Common.DeclareXMLDocument(true); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xDoc.NameTable); namespaceManager.AddNamespace("xhtml", "http://www.w3.org/1999/xhtml"); xDoc.Load(xhtmlFileNameWithPath); XmlNodeList fontNodeList = xDoc.GetElementsByTagName("meta"); for (int i = 0; i < fontNodeList.Count; i++) { if (fontNodeList[i].Attributes["scheme"] == null) continue; string langScheme = fontNodeList[i].Attributes["scheme"].Value; string langContent = fontNodeList[i].Attributes["content"].Value; if (langScheme.ToLower().IndexOf("language to font") != 0) continue; if (!langCodeList.Contains(langContent)) { langCodeList.Add(langContent); fontList = fontList + langContent; if (i < fontNodeList.Count - 1) { fontList = fontList + ";"; } } } } return fontList; }
public static string GetLanguageCode(string xhtmlFileNameWithPath, string projectInputType, bool vernagular) { string languageCode = string.Empty; if (File.Exists(xhtmlFileNameWithPath)) { if (Path.GetFileName(xhtmlFileNameWithPath).IndexOf("Preserve") == 0) { xhtmlFileNameWithPath = xhtmlFileNameWithPath.Replace(Path.GetFileName(xhtmlFileNameWithPath), Path.GetFileName(xhtmlFileNameWithPath) .Replace( "Preserve", "")); } List<string> langCodeList = new List<string>(); XmlDocument xDoc = Common.DeclareXMLDocument(true); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xDoc.NameTable); namespaceManager.AddNamespace("x", "http://www.w3.org/1999/xhtml"); xDoc.Load(xhtmlFileNameWithPath); XmlNode node; var vernacularLang = string.Empty; if (vernagular) { node = xDoc.SelectSingleNode("//*[@class='headword']/@*[local-name()='lang']"); if (node != null) { vernacularLang = node.InnerText; } else { node = xDoc.SelectSingleNode("//*[@class='headref']/@*[local-name()='lang']"); if (node != null) { vernacularLang = node.InnerText; } else { node = xDoc.SelectSingleNode("//*[@class='Paragraph']//@*[local-name()='lang']"); if (node != null) { vernacularLang = node.InnerText; } } } } XmlNodeList fontList = xDoc.GetElementsByTagName("meta"); for (int i = 0; i < fontList.Count; i++) { string langName = fontList[i].Attributes["name"].Value; string langContent = fontList[i].Attributes["content"].Value; if (langName.ToLower() == "dc.language") { if (vernagular) { if (langContent.Length < vernacularLang.Length || langContent.Substring(0, vernacularLang.Length) != vernacularLang) { continue; } if (langContent.Length >= vernacularLang.Length && langContent.Substring(vernacularLang.Length, 1) != ":") { continue; } } if (!langCodeList.Contains(langContent)) { langCodeList.Add(langContent); languageCode = languageCode + langContent; if (i < fontList.Count - 1) { languageCode = languageCode + ";"; } } } } } else { languageCode = "eng"; } return languageCode; }
public static string[] GetnamespacestoLocalize() { var namespacestoLocalize = new List<string>(); var pathwayDirectory = PathwayPath.GetPathwayDir(); if (pathwayDirectory == null || !Directory.Exists(pathwayDirectory)) return new[] { "SIL.PublishingSolution" }; foreach (var file in Directory.GetFiles(pathwayDirectory, "*.*").Where(f => Regex.IsMatch(f, @"^.+\.(dll|exe)$")) ) { var fileInfo = new FileInfo(file); if ((fileInfo.Name == "PsTool.dll") || (fileInfo.Name.Contains("Convert")) || (fileInfo.Name.Contains("Writer")) || (fileInfo.Name.Contains("Validator"))) { using (var epubinstalleddirectory = File.OpenRead(Common.FromRegistry(fileInfo.FullName))) { var sAssembly = Assembly.LoadFrom(epubinstalleddirectory.Name); foreach ( var stype in sAssembly.GetTypes() .Where(type => type.GetConstructors().Any(s => s.GetParameters().Length == 0))) { if (!namespacestoLocalize.Contains(stype.Namespace)) namespacestoLocalize.Add(stype.Namespace); } } } } return namespacestoLocalize.Distinct().ToArray(); }
/// <summary> /// Delete all files in the folder except output /// </summary> /// <param name="outputFolder">Export folder path</param> /// <param name="extension"> </param> /// <param name="nameLike"> </param> /// <param name="directory"> </param> public static void CleanupExportFolder(string outputFolder, string extension, string nameLike, string directory) { //#if (DEBUG) // return; //#endif List<string> lstExtn = new List<string>(); List<string> lstNamelike = new List<string>(); List<string> lstDirecorylike = new List<string>(); if (extension.Trim().Length > 0) { string[] extn = extension.Split(','); lstExtn.AddRange(extn); } if (nameLike.Trim().Length > 0) { string[] name = nameLike.Split(','); lstNamelike.AddRange(name); } if (directory.Trim().Length > 0) { string[] folder = directory.Split(','); lstDirecorylike.AddRange(folder); } outputFolder = Path.GetDirectoryName(outputFolder); string[] filePath = Directory.GetFiles(outputFolder); foreach (string file in filePath) { try { string type = Path.GetExtension(file).ToLower(); if (lstExtn.Contains(type)) { File.Delete(file); } string fi = Path.GetFileNameWithoutExtension(file).ToLower(); foreach (string filelike in lstNamelike) { if (fi.Contains(filelike.Trim().ToLower())) { File.Delete(file); } } if (type == ".css" && !fi.ToLower().Contains("merged")) { File.Delete(file); } } catch { } } string[] FolderList = Directory.GetDirectories(outputFolder); foreach (string folderName in FolderList) { if (lstDirecorylike.Contains(Path.GetFileName(folderName))) { try { Directory.Delete(folderName, true); } catch { } } } }
private void button5_Click(object sender, EventArgs e) { FileNames.Clear(); sourceFolder = "c:\\temp"; GetFilesFromFolder(sourceFolder); // Get files from Xml List<string> fileNamesXml = new List<string>(); XmlNode returnValue = null; XmlDocument LoadedDoc = new XmlDocument(); LoadedDoc.Load("c:\\FileLibrary.xml"); const string xPath = "//FileLibrary"; XmlElement root = LoadedDoc.DocumentElement; if (root != null) { returnValue = root.SelectSingleNode(xPath); foreach (XmlNode xmlNode in returnValue.ChildNodes) { string path = xmlNode.Attributes.GetNamedItem("Path").Value; fileNamesXml.Add(path); } } //Find missing files in xml foreach (string file in FileNames) { if (!fileNamesXml.Contains(file)) { string newGuid = Guid.NewGuid().ToString(); //Add a File Node XmlNode newNode = LoadedDoc.CreateNode("element", "File", ""); XmlAttribute xmlAttrib = LoadedDoc.CreateAttribute("Path"); xmlAttrib.Value = file; newNode.Attributes.Append(xmlAttrib); xmlAttrib = LoadedDoc.CreateAttribute("ComponentGuid"); xmlAttrib.Value = newGuid; newNode.Attributes.Append(xmlAttrib); root.LastChild.AppendChild(newNode); } } LoadedDoc.Save("c:\\FileLibrary.xml"); }