Пример #1
0
        private void exportDirectoryToParatext(string sourceDirectory, string targetDirectory)
        {
            // get Paratext settings
            var paratextSettings = new Paratext8ProjectSettings(targetDirectory);
            var projectName      = paratextSettings.GetValue("Name");
            var booksPresent     = new int[123];

            // get book information
            var bookData = Resources.Resources.GetBookData();

            // copy source usfm files
            foreach (var fileName in Directory.EnumerateFiles(sourceDirectory).Where(filename => filename.ToLower().EndsWith("sfm")))
            {
                // read the source file
                var usfm = File.ReadAllText(fileName);

                // get the book id and number for the Paratext file name
                if (!usfm.StartsWith(@"\id "))
                {
                    MessageBox.Show(string.Format("Not a valid USFM file: {0}", fileName));
                    return;
                }

                var bookID = usfm.Substring(4, 3);

                // update books present
                var bookNum = int.Parse(bookData[bookID][1]);

                if (bookNum > 40)
                {
                    bookNum--;
                }

                bookNum--;
                booksPresent[bookNum] = 1;

                // get paratext file name
                var bookName = paratextSettings.UsfmFileName(bookData[bookID][1], bookID);
                lblStatus.Text = "Exporting " + bookName;
                Application.DoEvents();

                // clean usfm
                usfm = cleanUsfm(usfm);

                // write the usfm file
                if (string.IsNullOrEmpty(usfm))
                {
                    continue;
                }

                File.WriteAllText(Path.Combine(targetDirectory, bookName), usfm);
            }

            // update Settings.xml
            paratextSettings.SetValue("BooksPresent", string.Join("", booksPresent));
            paratextSettings.Save();

            // finished
            MessageBox.Show("Finished.");
        }
Пример #2
0
        private void exportEnglishToDoor43(string sourceDirectory, string targetDirectory)
        {
            // get Paratext settings
            var paratextSettings = new Paratext8ProjectSettings(sourceDirectory);

            foreach (var usfmFile in Directory.GetFiles(sourceDirectory, "*" + paratextSettings.UsfmFileSuffix))
            {
                // get the book number and ID
                var fi  = new FileInfo(usfmFile);
                var kvp = paratextSettings.GetNumberAndID(fi.Name);
                if (string.IsNullOrEmpty(kvp.Key))
                {
                    continue;
                }
                var padding = kvp.Value == "PSA" ? 3 : 2;
                lblStatus.Text = "Exporting " + kvp.Key + "-" + kvp.Value;
                Application.DoEvents();

                Chunks chunks = chkChunkMarkers.Checked ? Resources.Resources.GetChunksV3(kvp.Value) : null;

                // door43 output directory
                var outDir = Path.Combine(targetDirectory, kvp.Key + "-" + kvp.Value);

                // split into chapters
                var chapterRegex = new Regex(@"(\\c[\u00A0\s][0-9]+(?:\s*[\r\n]+))");
                var chapters     = chapterRegex.Split(File.ReadAllText(usfmFile));
                var chapterText  = string.Empty;
                var chapterNum   = 0;

                for (var i = 0; i < chapters.Length; i++)
                {
                    var part = chapters[i];
                    if (part.StartsWith(@"\c"))
                    {
                        // write the file
                        writeDoor43File(chapterNum, chapterText, outDir, padding, chunks);

                        // reset for next chapter
                        chapterText = part;
                        chapterNum  = int.Parse(part.Substring(3));
                    }
                    else
                    {
                        chapterText += part;
                    }
                }

                // write the last chapter
                if (!string.IsNullOrEmpty(chapterText))
                {
                    writeDoor43File(chapterNum, chapterText, outDir, padding, chunks);
                }
            }

            // finished
            MessageBox.Show("Finished.");
        }
Пример #3
0
        private void exportEnglishToParatext(string sourceDirectory, string targetDirectory)
        {
            // get Paratext settings
            var paratextSettings = new Paratext8ProjectSettings(targetDirectory);
            var projectName      = paratextSettings.GetValue("Name");
            var booksPresent     = new int[123];


            // walk through the directories in the repository
            foreach (var sourceDir in Directory.GetDirectories(sourceDirectory))
            {
                var di = new DirectoryInfo(sourceDir);

                var bookDir = di.Name;

                // skip .git and .github
                if (bookDir.StartsWith("."))
                {
                    continue;
                }

                // all usfm directories are in this format, "01-GEN"
                var pos = bookDir.IndexOf("-");
                if (pos < 1)
                {
                    continue;
                }

                int bookNum;
                var success = int.TryParse(bookDir.Substring(0, pos), out bookNum);


                // check the book number
                if (!success || bookNum == 0 || bookNum == 40 || bookNum > 67)
                {
                    continue;
                }

                // update BooksPresent
                if (bookNum > 40)
                {
                    bookNum--;
                }

                bookNum--;
                booksPresent[bookNum] = 1;

                // book file name
                var bookParts = bookDir.Split('-');
                var bookName  = paratextSettings.UsfmFileName(bookParts[0], bookParts[1]);
                lblStatus.Text = "Exporting " + bookName;
                Application.DoEvents();

                // loop through the usfm files
                var usfmFiles = Directory.GetFiles(sourceDir, "*.usfm");
                Array.Sort(usfmFiles, StringComparer.InvariantCulture);
                var usfm = string.Empty;
                foreach (var usfmFile in usfmFiles)
                {
                    usfm += Environment.NewLine + File.ReadAllText(usfmFile);
                }

                // remove \s5 tags
                usfm = usfm.Replace(@"\s5", "");

                // remove extra white space
                usfm = usfm.Replace(Environment.NewLine + Environment.NewLine + Environment.NewLine + Environment.NewLine, Environment.NewLine);
                usfm = usfm.Replace(Environment.NewLine + Environment.NewLine + Environment.NewLine, Environment.NewLine);
                usfm = usfm.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
                usfm = usfm.TrimStart();

                // write the usfm file
                if (string.IsNullOrEmpty(usfm))
                {
                    continue;
                }

                File.WriteAllText(Path.Combine(targetDirectory, bookName), usfm);
            }

            // update Settings.xml
            paratextSettings.SetValue("BooksPresent", string.Join("", booksPresent));
            paratextSettings.Save();

            // finished
            MessageBox.Show("Finished.");
        }