Ejemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <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;
		}
Ejemplo n.º 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates or updates the paratext SSF file.
		/// </summary>
		/// <param name="paraTextSO">The Paratext Scripture Object.</param>
		/// <param name="folder">The Paratext settings folder.</param>
		/// <param name="styleFileName">Name of the style file.</param>
		/// <param name="ldsFileName">Name of the LDS file.</param>
		/// ------------------------------------------------------------------------------------
		private void WriteParatextSsfFile(SCRIPTUREOBJECTSLib.ISCScriptureText3 paraTextSO,
			string folder, string styleFileName, ref string ldsFileName)
		{
			string ssfFileName = Path.Combine(folder, m_p6ShortName + ".ssf");
			bool fUpdateExisting = File.Exists(ssfFileName);
			int hvoWs = (ExportBackTranslationDomain ? RequestedAnalysisWss[0] : m_cache.DefaultVernWs);
			if (paraTextSO != null)
			{
				string[] shortNames = ParatextHelper.GetParatextShortNames(paraTextSO);
				if (shortNames != null)
				{
					foreach (string sName in shortNames)
					{
						if (sName == m_p6ShortName)
						{
							fUpdateExisting = true;
							try
							{
								paraTextSO.Load(sName);
							}
							catch
							{
								// If Paratext considers the project settings file to be bogus, we just overwrite it.
								fUpdateExisting = false;
							}
							break;
						}
					}
				}
			}

			try
			{
				if (fUpdateExisting)
				{
					string language = m_ParatextSsfFileAccessor.UpdateSsfFile(ssfFileName,
						m_fileNameFormat, m_p6ShortName, styleFileName, m_outputSpec, hvoWs);
					// REVIEW (MikeL): Why was the ldsFileName always re(set)? During back translation export,
					// it was changing the name of the back translation to the vernacular writing system.
					if (ldsFileName == string.Empty)
						ldsFileName = Path.Combine(folder, language + ".lds");
					return;
				}
			}
			catch
			{
				// We only ignore errors during the update attempt if Paratext is not installed. While
				// this may seem bizarre and nearly brain-dead, the reason is that we suspect the
				// failure is probably due to a corrupt file. In that case, we just attempt to overwrite
				// it and get on with life. If Paratext is installed, we assume the file is not corrupt
				// since Paratext successfully loaded it.
				if (paraTextSO != null)
					throw;
			}

			using (FileWriter ssfWriter = OpenFile(ssfFileName))
			{
				m_ParatextSsfFileAccessor.SaveSsfFile(m_fileNameFormat, m_p6ShortName, styleFileName, m_outputSpec,
					ssfWriter, hvoWs);
			}
		}