示例#1
0
        /// <summary>
        /// Run the algorithm on all non-backup files in the source directory.
        /// </summary>
        public void Run()
        {
            DateTime fileDate;

            if (m_tablePaths == null)
            {
                // Use the default
                m_tablePaths = new string[] {
                    // remove spaces at end of line. They can end up between end of sentence and note marker.
                    Utils.GetUtilityFile("cleanup_EOL_spaces.cct"),
                    // removes btX fields, which (when converted to \note: btX....\note* by current OW_to_PT cause
                    // Nathan's USFM->OSIS to drop the rest of the verse after a footnote.
                    //Utils.GetUtilityFile("remove_bt_from_OW.cct"),
                    "bt",
                    // removes \ov fields, which otherwise tend to result in a newline before various notes,
                    // which becomes an unwanted space after following stages.
                    //Utils.GetUtilityFile("remove_ov_from_OW.cct"),
                    "ov",
                    // Strip all the \ntX fields. JohnD's file makes of all these markers that don't translate into \note.
                    // The OSIS converter discards them, but the resulting blank lines mess up spacing of note markers.
                    //Utils.GetUtilityFile("remove_nt_from_OW.cct"),
                    "nt",
                    // Several more fields that are not wanted and not handled by the OW_to_PT.
                    "al ",
                    "e",
                    "chk2",
                    "bnvt",
                    "nq",

                    // Consider using this...if so, must be BEFORE we convert angle brackets to quotes!
                    //Utils.GetUtilityFile("fix_glottal.cct"),

                    // The main tables don't do well with multiple foonotes in a block. Now we've got rid of the \bts, we can break those up.
                    "footnotes.process",

                    // OW_to_PT.cct does not seem to get the quotes quite right. Kupang makes use of <<< and >>> which
                    // are ambiguous; OW_to_PT converts << and >> and < and >, but >>> is therefore interpreted as >> >
                    // and closes the double first, which is (usually) wrong.
                    // This version removes any space in >> > etc, and interprets >>> as > >>.
                    // This change may be redundant with the latest version of JohnD's OW_to_PT.cct
                    //Utils.GetUtilityFile("fix_quotes.cct"),
                    // Main conversion by John Duerkson implemented in these two files.
                    Utils.GetUtilityFile("OW_to_PT.cct"),
                    Utils.GetUtilityFile("move_footnote_to_fn.cct"),
                    // Strip all the \note fields that JohnD's file makes of all the markers that don't translate.
                    // The OSIS converter discards them, but the resulting blank lines mess up spacing of note markers.
                    // Didn't work...strips the whole file content after the first \note. Also not needed, now have
                    // \nt being deleted properly.
                    //Utils.GetUtilityFile("remove_note_from_USFM.cct"),
                    // Final cleanup strips remnants of s2 markers at end of field, and puts cross-ref notes inline so
                    // we don't get a spurious space before the <note> in the OSIS and beyond.
                    Utils.GetUtilityFile("cleanup_OW_to_USFM.cct")
                };
            }
            // Reset problem records, in case ever used repeatedly.
            m_ProblemMarkers.Clear();
            m_problemReports.Remove(0, m_problemReports.Length);
            m_seriousErrorCount = 0;

            // Input is typically db files from OurWord, sfm from TE, or ptx from ParaText.
            // It may also be from Bibledit or another USFM tool. Many archived input files
            // do not have consistent file extensions. Some are named for the language as a
            // suffix. Some use a book abbreviation as an extension.
            // Bibledit uses .usfm on its exports.
            string[] inputFileNames = Directory.GetFiles(m_inputDirName);
            if (inputFileNames.Length == 0)
            {
                MessageBox.Show("No files found in input directory " + m_inputDirName);
                return;
            }
//			Progress status = new Progress(inputFileNames.Length);
//			status.Show();
            Utils.DeleteDirectory(m_outputDirName);
            Utils.EnsureDirectory(m_outputDirName);
            int count = 0;

            foreach (string inputFile in inputFileNames)
            {
                string filename = Path.GetFileName(inputFile);
                string fileType = Path.GetExtension(filename).ToUpper();
                if ((fileType != ".BAK") && (fileType != ".LDS") &&
                    (fileType != ".SSF") && (fileType != ".DBG") &&
                    (fileType != ".WDL") && (fileType != ".STY") &&
                    (!inputFile.EndsWith("~")))
                {
//					status.File = filename;
                    fileDate = File.GetLastWriteTimeUtc(inputFile);
                    if (fileDate > sourceDate)
                    {
                        sourceDate = fileDate;
                    }
                    if (!Convert(inputFile))
                    {
                        break;
                    }
                }
                count++;
//                status.Value = count;
            }

//			status.Close();

            if (m_ProblemMarkers.Count > 0 || m_seriousErrorCount > 0)
            {
                StringBuilder report = new StringBuilder();
                if (m_seriousErrorCount > 0)
                {
                    report.Append("Serious problems occurred while processing at least one file, indicated by lines beginning **** ERROR in the output\n");
                    report.Append("These errors result in the output being an incomplete conversion of the input\n\n");
                }
                if (m_ProblemMarkers.Count > 0)
                {
                    List <string> keys = new List <string>(m_ProblemMarkers.Keys);
                    keys.Sort();
                    report.Append("The conversion process encountered some markers it could not handle.\n");
                    report.Append("These are indicated in the output files by lines starting ***\\.\n");
                    report.Append("The problem markers are these: ");
                    bool fFirst = true;
                    foreach (string key in keys)
                    {
                        if (fFirst)
                        {
                            fFirst = false;
                        }
                        else
                        {
                            report.Append("; ");
                        }
                        report.Append(String.Format("{0} ({1})", key, m_ProblemMarkers[key].ToString()));
                    }
                    report.Append(".\n\n");
                }
                report.Append("Here are the lines where the problems were found:\n");
                report.Append(m_problemReports.ToString());
                ProblemReport reportDlg = new ProblemReport();
                reportDlg.ReportContents = report.ToString();
                reportDlg.ShowDialog();
            }
        }
示例#2
0
        /// <summary>
        /// Run the algorithm (on all files).
        /// </summary>
        public void Run(IList files)
        {
            Init();
            m_toolPath = ToolPath;
            if (CheckToolPresent && !File.Exists(m_toolPath))
            {
                MessageBox.Show("The program needed for this conversion was not found: " + m_toolPath, "Error");
                return;
            }
            Utils.EnsureDirectory(m_outputDirName);
            string extension = null;

            foreach (string pattern in Extensions)
            {
                if (Directory.GetFiles(m_inputDirName, pattern).Length != 0)
                {
                    extension = Path.GetExtension(pattern);
                    break;
                }
            }
            if (extension == null)
            {
                MessageBox.Show("No matching input files");
            }
            List <string> inputFilePaths = new List <string>();

            foreach (string patternFile in files)
            {
                string mainFilePath = Path.Combine(m_inputDirName, Path.ChangeExtension(patternFile, extension));
                foreach (string filepath in GetActualFileNames(mainFilePath))
                {
                    if (!CheckFileExists(filepath))
                    {
                        return;
                    }
                    inputFilePaths.Add(filepath);
                }
            }
            int count = 0;

            m_reportPath = Path.Combine(m_inputDirName, "ConversionReports.txt");
            File.Delete(m_reportPath);             // get rid of any old reports
            m_errorInfo    = null;
            m_outputWriter = new StreamWriter(m_reportPath, true, Encoding.UTF8);
            Progress status = new Progress(inputFilePaths.Count * 2);

            status.Show();

            foreach (string inputFile in inputFilePaths)
            {
                PreProcess(inputFile);
            }
            foreach (string inputFile in inputFilePaths)
            {
                string filename = Path.GetFileName(inputFile);
                status.File = filename;
                ConvertFile(inputFile);
                count++;
                status.Value = count;
            }
            // PostProcessing is done separately after all the files are created. This is important for OSIS_to_HTML
            // in chapter-per-file mode, which needs to look ahead to the next book to determine what the first chapter
            // file should be to link to.
            foreach (string inputFile in inputFilePaths)
            {
                string filename = Path.GetFileName(inputFile);
                status.File = filename;
                PostProcess(inputFile);
                count++;
                status.Value = count;
            }

            status.Close();
            m_outputWriter.Close();
            if (m_errorInfo != null)
            {
                ProblemReport reportDlg = new ProblemReport();
                reportDlg.ReportContents = m_errorInfo.ToString();
                reportDlg.Show();
            }
        }