/// ------------------------------------------------------------------------------------ /// <summary> /// Retrieve the scTag object, at the given index, from the Paratext scripture text. /// </summary> /// <param name="scText">the Paratext6 Scripture project</param> /// <param name="iTag">index of the tag to retrieve</param> /// <param name="scParatextTag">set to the tag</param> /// <param name="sMarker">set to the tag's marker</param> /// <returns>True if successful. False if there are no more tags.</returns> /// <remarks>virtual for testing purposes</remarks> /// ------------------------------------------------------------------------------------ private bool GetPTScrTextNthTag(SCRIPTUREOBJECTSLib.ISCScriptureText3 scText, int iTag, SCRIPTUREOBJECTSLib.ISCTag scParatextTag, out string sMarker) { scParatextTag = scText.NthTag(iTag); if (scParatextTag == null) { sMarker = null; return(false); } sMarker = @"\" + scParatextTag.Marker; return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the paratext short names. /// </summary> /// <param name="pTScriptureText">The Paratext Scripture Objects ScriptureText object. /// </param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public static string[] GetParatextShortNames(SCRIPTUREOBJECTSLib.ISCScriptureText3 pTScriptureText) { try { // The list of short names is returned from the scripture object in a single // string with a CR LF pair between each abbreviation. string shortTextNames = pTScriptureText.TextsPresent; if (shortTextNames == null) { return(null); } shortTextNames = shortTextNames.Trim(); if (shortTextNames == string.Empty) { return(null); } // The Split will divide the string into an array of strings, each containing // an abbreviation. string[] shortNames = shortTextNames.Split(new Char[] { '\n' }); // Since the Split method only splits using one character as the delimiter // (in this case '\n'), that still leaves a '\r' character in each of the // resulting strings. Therefore, trimming each string before returning it // will get rid of the '\r' characters. for (int i = 0; i < shortNames.Length; i++) { shortNames[i] = shortNames[i].Trim(); } return(shortNames); } catch { return(null); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the Paratext project and enumerator, preparing us to read the data files. /// </summary> /// <param name="paratextProjectId">3-letter Paratext project ID</param> /// <returns>true if the project was loaded, else false</returns> /// ------------------------------------------------------------------------------------ protected virtual void LoadParatextProject(string paratextProjectId) { try { m_scParatextText = new SCRIPTUREOBJECTSLib.SCScriptureTextClass(); m_scParatextTextSegment = new SCRIPTUREOBJECTSLib.SCTextSegmentClass(); } catch (Exception e) { // Can't load Paratext project if Paratext is not installed. throw new ParatextLoadException( TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e); } try { m_scParatextText.Load(paratextProjectId); // create ref objs of the Paratext lib SCRIPTUREOBJECTSLib.SCReference startRefPT = new SCRIPTUREOBJECTSLib.SCReference(); SCRIPTUREOBJECTSLib.SCReference endRefPT = new SCRIPTUREOBJECTSLib.SCReference(); startRefPT.Parse(m_settings.StartRef.AsString); endRefPT.Parse(m_settings.EndRef.AsString); // Now initialize the TextEnum with the range of scripture text we want m_scParatextTextEnum = m_scParatextText.TextEnum(startRefPT, endRefPT, (SCRIPTUREOBJECTSLib.SCTextType) 0, //scTitle | scSection | scVerseText | scNoteText | scOther) (SCRIPTUREOBJECTSLib.SCTextProperties) 0); } catch (Exception e) { string msg = string.Format( TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"), paratextProjectId); throw new ParatextLoadException(msg, e); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the mappings for a paratext project into the specified list. /// </summary> /// <param name="project">Paratext project ID</param> /// <param name="mappingList">ScrMappingList to which new mappings will be added</param> /// <param name="domain">The import domain for which this project is the source</param> /// <returns><c>true</c> if the Paratext mappings were loaded successfully; <c>false</c> /// otherwise</returns> /// ------------------------------------------------------------------------------------ public static bool LoadParatextMappings(string project, ScrMappingList mappingList, ImportDomain domain) { // If the new project ID is null, then do not load mappings. if (project == null) { return(false); } // Load the tags from the paratext project and create mappings for them. SCRIPTUREOBJECTSLib.ISCScriptureText3 scParatextText = null; try { scParatextText = new SCRIPTUREOBJECTSLib.SCScriptureTextClass(); scParatextText.Load(project); } catch (Exception ex) { Logger.WriteEvent(string.Format( "Got {0} exception loading paratext mappings (ScrImportP6Project.LoadParatextMappings):\n{1}", ex.GetType(), ex.Message)); return(false); } // TE-5802 try { for (int i = 0; true; i++) { SCRIPTUREOBJECTSLib.ISCTag tag = scParatextText.NthTag(i); if (tag == null) { break; } string marker = @"\" + tag.Marker; string endMarker = string.Empty; if (tag.Endmarker != string.Empty && tag.Endmarker != null) { endMarker = @"\" + tag.Endmarker; } // When the nth marker has an end marker, the nth + 1 marker will be // that end marker. Therefore, we have to skip those "end style" markers. if (tag.StyleType == SCRIPTUREOBJECTSLib.SCStyleType.scEndStyle) { continue; } // Create a new mapping for this marker. mappingList.AddDefaultMappingIfNeeded(marker, endMarker, domain, false, false); } SCRIPTUREOBJECTSLib.SCReference startRefPT = new SCRIPTUREOBJECTSLib.SCReference(); SCRIPTUREOBJECTSLib.SCReference endRefPT = new SCRIPTUREOBJECTSLib.SCReference(); startRefPT.Parse("GEN 1:0"); endRefPT.Parse("REV 22:21"); SCRIPTUREOBJECTSLib.ISCTextEnum scParatextTextEnum = scParatextText.TextEnum( (SCRIPTUREOBJECTSLib.SCReference)startRefPT, (SCRIPTUREOBJECTSLib.SCReference)endRefPT, (SCRIPTUREOBJECTSLib.SCTextType) 0, //scTitle | scSection | scVerseText | scNoteText | scOther) (SCRIPTUREOBJECTSLib.SCTextProperties) 0); SCRIPTUREOBJECTSLib.SCTextSegment scParatextTextSegment = new SCRIPTUREOBJECTSLib.SCTextSegmentClass(); mappingList.ResetInUseFlags(domain); while (scParatextTextEnum.Next(scParatextTextSegment) != 0) { string sMarker = @"\" + scParatextTextSegment.Tag.Marker; ImportMappingInfo mapping = mappingList[sMarker]; if (mapping != null) { mapping.SetIsInUse(domain, true); } // ENHANCE (TE-4408): Consider Detecting markers that occur in the data but are missing // from the STY file. How can we write a test for this? //else if (ScrImportFileInfo.IsValidMarker(sMarker)) //{ // mappingList.AddDefaultMappingIfNeeded(sMarker,domain, false, true); //} //else //{ // throw new ScriptureUtilsException(SUE_ErrorCode.InvalidCharacterInMarker, null, 0, // sMarker + sText, new ScrReference(scParatextTextSegment.FirstReference.BBCCCVVV)); //} } } catch (Exception ex) { Logger.WriteEvent(string.Format( "Got {0} exception loading paratext mappings (ScrImportP6Project.LoadParatextMappings):\n{1}", ex.GetType(), ex.Message)); return(false); } return(true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the Paratext project and enumerator, preparing us to read the data files. /// </summary> /// <param name="paratextProjectId">3-letter Paratext project ID</param> /// <returns>true if the project was loaded, else false</returns> /// ------------------------------------------------------------------------------------ protected virtual void LoadParatextProject(string paratextProjectId) { try { m_scParatextText = new SCRIPTUREOBJECTSLib.SCScriptureTextClass(); m_scParatextTextSegment = new SCRIPTUREOBJECTSLib.SCTextSegmentClass(); } catch (Exception e) { // Can't load Paratext project if Paratext is not installed. throw new ParatextLoadException( TeResourceHelper.GetResourceString("kstidCheckParatextInstallation"), e); } try { m_scParatextText.Load(paratextProjectId); // create ref objs of the Paratext lib SCRIPTUREOBJECTSLib.SCReference startRefPT = new SCRIPTUREOBJECTSLib.SCReference(); SCRIPTUREOBJECTSLib.SCReference endRefPT = new SCRIPTUREOBJECTSLib.SCReference(); startRefPT.Parse(m_settings.StartRef.AsString); endRefPT.Parse(m_settings.EndRef.AsString); // Now initialize the TextEnum with the range of scripture text we want m_scParatextTextEnum = m_scParatextText.TextEnum(startRefPT, endRefPT, (SCRIPTUREOBJECTSLib.SCTextType)0, //scTitle | scSection | scVerseText | scNoteText | scOther) (SCRIPTUREOBJECTSLib.SCTextProperties)0); } catch (Exception e) { string msg = string.Format( TeResourceHelper.GetResourceString("kstidParatextProjectLoadFailure"), paratextProjectId); throw new ParatextLoadException(msg, e); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handles the Load event of the ExportPtxDialog control. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event /// data.</param> /// ------------------------------------------------------------------------------------ protected override void OnLoad(EventArgs e) { // set up default short name ScrImportSet importSet = (ScrImportSet)m_cache.LangProject.TranslatedScriptureOA.DefaultImportSettings; m_shortName = (importSet != null) ? importSet.ParatextScrProj : null; if (m_shortName == null) { LgWritingSystem wsVern = ((LgWritingSystem)m_cache.LangProject.CurVernWssRS[0]); string abbr = wsVern.Abbr.UserDefaultWritingSystem; if (abbr != null) { m_shortName = abbr.Trim(); } else { m_shortName = wsVern.Abbreviation.Trim(); } } else { m_shortName = m_shortName.Trim(); } // Paratext 6 requires short name to be between 3 and 5 characters in length. if (m_shortName.Length < 3) { m_shortName = m_shortName.PadRight(3, '_'); } if (m_shortName.Length > 5) { m_shortName = m_shortName.Substring(0, 5); } m_BTshortName = (importSet != null && !string.IsNullOrEmpty(importSet.ParatextBTProj)) ? importSet.ParatextBTProj : (m_shortName.Substring(0, 3) + "BT"); // Set values for what to export for one domain export (Paratext). switch (m_regGroup.GetIntValue("ParatextOneDomainExportWhat", 0)) { case 0: default: // Temporarily load the BT settings, so when we "switch" to Scripture, // the BT settings will be saved in our internal object. LoadFileNameSchemeControl(base.RegistrySettingType + "BT", m_BTshortName); m_BTfileNameScheme = fileNameSchemeCtrl.FileNameFormat; rdoScripture.Select(); base.OnLoad(e); m_fileNameScheme = fileNameSchemeCtrl.FileNameFormat; break; case 1: // Temporarily load the regular (vern) settings, so when we "switch" to // back translation, the vern settings will be saved in our internal object. LoadFileNameSchemeControl(base.RegistrySettingType, m_shortName); m_fileNameScheme = fileNameSchemeCtrl.FileNameFormat; rdoBackTranslation.Select(); base.OnLoad(e); m_BTfileNameScheme = fileNameSchemeCtrl.FileNameFormat; break; } // Get the output file or folder specification. SCRIPTUREOBJECTSLib.ISCScriptureText3 paraTextSO = null; try { paraTextSO = new SCRIPTUREOBJECTSLib.SCScriptureTextClass(); } catch { // Ignore: Paratext not installed } if (paraTextSO != null) { m_paratextProjFolder = paraTextSO.SettingsDirectory; if (m_paratextProjFolder != null) { m_paratextProjFolder = m_paratextProjFolder.Trim(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); } string[] shortNames = ParatextHelper.GetParatextShortNames(paraTextSO); if (shortNames != null) { foreach (string shortName in shortNames) { bool fIsEditable = true; try { paraTextSO.Load(shortName); fIsEditable = (paraTextSO.Editable != 0); } catch { // Paratext settings file is probably bogus, so we regard it as editable (i.e., we can overwrite it). } if (fIsEditable) { cboShortName.Items.Add(shortName); } else { m_nonEditableP6Projects.Add(shortName); } } } // The following is an attempt to keep us from looking like idiots by making // the default project name a non-editable project. int i = 1; while (m_nonEditableP6Projects.Contains(m_shortName) && i < 1000) { m_shortName = "MP" + i++; } i = 1; while (m_nonEditableP6Projects.Contains(m_BTshortName) && i < 1000) { m_BTshortName = "BT" + i++; } } else { // Paratext is not installed or Paratext directory does not exist. // We default the output path to "C:\My Paratext Projects". However, this directory // might not exist and/or we might have no permissions to write there. We attempt to // create this folder now. If we fail, then we disable the Short Name control and // won't bother writing the Paratext settings files. m_paratextProjFolder = kDefaultParatextPath; } cboShortName.Text = ShortName; m_OutputFolder = m_regGroup.GetStringValue("ParatextOutputSpec", m_paratextProjFolder); m_BTOutputFolder = m_regGroup.GetStringValue("ParatextBTOutputSpec", m_paratextProjFolder); UpdateDisplay(); }