Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Check the XeLaTeX version.
        /// </summary>
        ///
        /// <returns>
        /// True if the installed version of XeLaTeX matches the expected version of Pathway.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public static bool CheckXeLaTexVersion()
        {
            object regObj;

            if (RegistryHelperLite.RegEntryExists(RegistryHelperLite.CompanyKeyLocalMachine,
                                                  "PathwayXeLaTeX", "XeLaTexVer", out regObj))
            {
                return((string)regObj == "1.15.4");
            }
            return(false);
        }
Example #2
0
        public void ExportUsxRawToUsx(List <XmlDocument> usxBooksToExport)
        {
            if (MFormat != "Go Bible")
            {
                string vrsFileDest = Common.PathCombine(MOutputLocationPath, "versification.vrs");
                string ldsFileDest = Common.PathCombine(MOutputLocationPath, "English.lds");

                string paratextProjectLocation = string.Empty;
                object paraTextprojectPath;
                if (RegistryHelperLite.RegEntryExists(RegistryHelperLite.ParatextKey,
                                                      "Settings_Directory", "", out paraTextprojectPath))
                {
                    paratextProjectLocation = (string)paraTextprojectPath;
                    paratextProjectLocation = Common.PathCombine(paratextProjectLocation, _mProjectName);
                    paratextProjectLocation = Common.PathCombine(paratextProjectLocation, "gather");

                    string vrsFileName = "eng";
                    string ldsFileName = "*"; //project file name associate file.

                    if (!Directory.Exists(paratextProjectLocation))
                    {
                        paratextProjectLocation = (string)paraTextprojectPath;
                    }
                    string      ssfFileName = Common.PathCombine(paratextProjectLocation, Common.databaseName + ".ssf");
                    XmlDocument xmlDoc      = Common.DeclareXMLDocument(false);
                    xmlDoc.Load(ssfFileName);
                    string  xPath = "//Language";
                    XmlNode list  = xmlDoc.SelectSingleNode(xPath);
                    if (list != null)
                    {
                        ldsFileName = list.InnerText;
                    }

                    if (File.Exists(Common.PathCombine(paratextProjectLocation, vrsFileName + ".vrs")))
                    {
                        File.Copy(Common.PathCombine(paratextProjectLocation, vrsFileName + ".vrs"), vrsFileDest);
                    }

                    if (File.Exists(Common.PathCombine(paratextProjectLocation, ldsFileName + ".lds")))
                    {
                        File.Copy(Common.PathCombine(paratextProjectLocation, ldsFileName + ".lds"), ldsFileDest);
                    }
                }

                MOutputLocationPath = Common.PathCombine(MOutputLocationPath, "USX");
            }
            else
            {
                MOutputLocationPath = Common.PathCombine(MOutputLocationPath, "SFM");
            }


            if (!Directory.Exists(MOutputLocationPath))
            {
                Directory.CreateDirectory(MOutputLocationPath);
            }

            for (int iDoc = 0; iDoc < usxBooksToExport.Count; iDoc++)
            {
                XmlDocument scrBooksDoc = usxBooksToExport[iDoc];
                string      usx         = scrBooksDoc.InnerXml;

                var nsmgr1 = new XmlNamespaceManager(scrBooksDoc.NameTable);
                nsmgr1.AddNamespace("style", "urn:oasis:names:tc:opendocument:xmlns:style:1.0");
                nsmgr1.AddNamespace("fo", "urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0");
                nsmgr1.AddNamespace("text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0");

                string      xpath    = "//book";
                string      bookName = string.Empty;
                XmlNodeList list     = scrBooksDoc.SelectNodes(xpath, nsmgr1);

                GetBookName(list, ref bookName);

                // Create argument list
                XsltArgumentList args = new XsltArgumentList();
                foreach (string paramName in _mXslParams.Keys)
                {
                    args.AddParam(paramName, "", _mXslParams[paramName]);
                }

                // Step 1. Separate books into their own elements for subsequent processing.
                StringBuilder separatedBooks = new StringBuilder();
                XmlWriter     htmlw1         = XmlWriter.Create(separatedBooks, _mUsxToXhtml.OutputSettings);
                _mSeparateIntoBooks.Transform(XmlReader.Create(new StringReader(usx)), null, htmlw1, null);

                // Step 2. Remove line breaks for next step (to prevent creation of empty spans).
                StringBuilder cleanUsx = new StringBuilder();
                XmlWriter     htmlw2   = XmlWriter.Create(cleanUsx, _mCleanUsx.OutputSettings);
                _mCleanUsx.Transform(XmlReader.Create(new StringReader(separatedBooks.ToString())), null, htmlw2, null);

                // Step 3. Convert the SFMs to styles recognized by Pathway. Also, change the structure of the
                //       following elements to Pathway's format: book title, chapters, figures, footnotes.
                StringBuilder html   = new StringBuilder();
                XmlWriter     htmlw3 = XmlWriter.Create(html, _mUsxToXhtml.OutputSettings);
                _mUsxToXhtml.Transform(XmlReader.Create(new StringReader(cleanUsx.ToString())), args, htmlw3, null);

                cleanUsx = cleanUsx.Replace("utf-16", "utf-8");
                cleanUsx = cleanUsx.Replace("<usfm>", "<USX>");
                cleanUsx = cleanUsx.Replace("</usfm>", "</USX>");

                string        bookFileName = Common.PathCombine(MOutputLocationPath, bookName + ".usx");
                XmlDocument   doc          = new XmlDocument();
                XmlTextWriter txtWriter    = new XmlTextWriter(bookFileName, null);
                txtWriter.Formatting = Formatting.Indented;
                txtWriter.WriteRaw(cleanUsx.ToString());
                doc.Save(txtWriter);
                txtWriter.Close();

                if (MFormat == "Go Bible")
                {
                    UsxToSFM usxToSfm   = new UsxToSFM();
                    string   targetFile = bookFileName.Replace(".usx", ".sfm");
                    usxToSfm.ConvertUsxToSFM(bookFileName, targetFile);

                    if (File.Exists(targetFile))
                    {
                        File.Delete(bookFileName);
                    }
                }
            }
        }