Ejemplo n.º 1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handles the SelectedIndexChanged event of the cboShortName control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
        /// ------------------------------------------------------------------------------------
        protected void cboShortName_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            if (!m_fUserModifiedFolder && cboShortName.SelectedIndex >= 0)
            {
                try
                {
                    SCRIPTUREOBJECTSLib.ISCScriptureText3 paraTextSO = new SCRIPTUREOBJECTSLib.SCScriptureTextClass();
                    paraTextSO.Load(ShortName);
                    string folder = paraTextSO.Directory;
                    m_fAppendShortNameToFolder = (folder.EndsWith(Path.DirectorySeparatorChar + ShortName));
                    BaseOutputFolder           = folder;
                    m_fUserModifiedFolder      = false;
                    CalculateDisplayOutputFolder();

                    FileNameFormat currentFileNameScheme = ExportScriptureDomain ? m_fileNameScheme :
                                                           m_BTfileNameScheme;
                    currentFileNameScheme.m_filePrefix   = paraTextSO.FileNamePrePart;
                    currentFileNameScheme.m_schemeFormat =
                        FileNameFormat.GetSchemeFormatFromParatextForm(paraTextSO.FileNameForm);
                    m_fileNameScheme.m_fileSuffix = Path.GetFileNameWithoutExtension(paraTextSO.FileNamePostPart);
                    //if (ExportScriptureDomain)
                    //    m_BTfileNameScheme.m_fileSuffix = m_fileNameScheme.m_fileSuffix.Substring(0, 3) + "BT";
                    currentFileNameScheme.m_fileExtension = Path.GetExtension(paraTextSO.FileNamePostPart);

                    // set file name scheme control with properties that check the export domain.
                    fileNameSchemeCtrl.ClearUserModifiedNameScheme();
                    fileNameSchemeCtrl.Prefix    = FileNamePrefix;
                    fileNameSchemeCtrl.Scheme    = FileNameScheme;
                    fileNameSchemeCtrl.Suffix    = FileNameSuffix;
                    fileNameSchemeCtrl.Extension = FileNameExtension;
                }
                catch
                {
                    // Ignore Paratext Load errors. Project will be overwritten.
                }
            }
        }
Ejemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        /// <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);
        }
Ejemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <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();
        }
Ejemplo n.º 4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the SelectedIndexChanged event of the cboShortName control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
		/// ------------------------------------------------------------------------------------
		protected void cboShortName_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (!m_fUserModifiedFolder && cboShortName.SelectedIndex >= 0)
			{
				try
				{
					SCRIPTUREOBJECTSLib.ISCScriptureText3 paraTextSO = new SCRIPTUREOBJECTSLib.SCScriptureTextClass();
					paraTextSO.Load(ShortName);
					string folder = paraTextSO.Directory;
					m_fAppendShortNameToFolder = (folder.EndsWith(Path.DirectorySeparatorChar + ShortName));
					BaseOutputFolder = folder;
					m_fUserModifiedFolder = false;
					CalculateDisplayOutputFolder();

					FileNameFormat currentFileNameScheme = ExportScriptureDomain ? m_fileNameScheme :
						m_BTfileNameScheme;
					currentFileNameScheme.m_filePrefix = paraTextSO.FileNamePrePart;
					currentFileNameScheme.m_schemeFormat =
						FileNameFormat.GetSchemeFormatFromParatextForm(paraTextSO.FileNameForm);
					m_fileNameScheme.m_fileSuffix = Path.GetFileNameWithoutExtension(paraTextSO.FileNamePostPart);
					//if (ExportScriptureDomain)
					//    m_BTfileNameScheme.m_fileSuffix = m_fileNameScheme.m_fileSuffix.Substring(0, 3) + "BT";
					currentFileNameScheme.m_fileExtension = Path.GetExtension(paraTextSO.FileNamePostPart);

					// set file name scheme control with properties that check the export domain.
					fileNameSchemeCtrl.ClearUserModifiedNameScheme();
					fileNameSchemeCtrl.Prefix = FileNamePrefix;
					fileNameSchemeCtrl.Scheme = FileNameScheme;
					fileNameSchemeCtrl.Suffix = FileNameSuffix;
					fileNameSchemeCtrl.Extension = FileNameExtension;
				}
				catch
				{
					// Ignore Paratext Load errors. Project will be overwritten.
				}
			}
		}
Ejemplo n.º 5
0
		/// ------------------------------------------------------------------------------------
		/// <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();
		}
Ejemplo n.º 6
0
		/// ------------------------------------------------------------------------------------
		/// <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;
		}