Example #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Install the control.
        /// </summary>
        /// <param name="dockHost">The control that hosts the browser</param>
        /// <param name="cache">The cache (needed in case we have to create the English LDS file
        /// on the fly)</param>
        /// <param name="normalStyle">The normal style (needed in case we have to create the
        /// English LDS file on the fly)</param>
        /// <returns>
        ///     <c>true</c> if the browser was installed successfully; <c>false</c>
        /// otherwise.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public bool Install(Control dockHost, FdoCache cache, IStStyle normalStyle)
        {
            while (true)
            {
                try
                {
                    RegistrationInfo.AllowP6RegistrationCode = true;
                    RegistrationInfo.AllowAccessToResources();
                    string paratextProjectDir = ScrImportP6Project.ProjectDir;

                    if (!String.IsNullOrEmpty(paratextProjectDir))
                    {
                        string englishLdsPathname = Path.Combine(paratextProjectDir, "English.lds");
                        if (!File.Exists(englishLdsPathname))
                        {
                            ParatextLdsFileAccessor ldsAccessor     = new ParatextLdsFileAccessor(cache);
                            UsfmStyEntry            normalUsfmStyle = new UsfmStyEntry();
                            StyleInfoTable          styleTable      = new StyleInfoTable(normalStyle.Name,
                                                                                         cache.LanguageWritingSystemFactoryAccessor);
                            normalUsfmStyle.SetPropertiesBasedOnStyle(normalStyle);
                            styleTable.Add(normalStyle.Name, normalUsfmStyle);
                            styleTable.ConnectStyles();
                            ldsAccessor.WriteParatextLdsFile(englishLdsPathname,
                                                             cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en"), normalUsfmStyle);
                        }
                    }
                    ScrTextCollection.Initialize();
                    break;
                }
                catch (Exception e)
                {
                    try
                    {
                        ReflectionHelper.SetField(typeof(ScrTextCollection), "initialized", false);
                    }
                    catch (Exception reflectionHelperException)
                    {
                        throw new ContinuableErrorException("Paratext resource browser failed to initialize." +
                                                            Environment.NewLine + reflectionHelperException.Message, e);
                    }
                    if (MessageBox.Show(dockHost.FindForm(), String.Format(
                                            Properties.Resources.kstidCannotDisplayResourcePane,
                                            Application.ProductName, e.Message), Application.ProductName,
                                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button2) != DialogResult.Retry)
                    {
                        return(false);
                    }
                }
            }
            m_toolStrip.Text = "USFM Resource Browser";
            m_extender       = new DockExtender(dockHost);
            dockHost.Controls.Add(this);
            m_floaty = m_extender.Attach(this, m_toolStrip, true);
            this.SendToBack();
            return(true);
        }
        public void UpdateParatextLdsFile_FileMissing()
        {
            FileWriter writer = new FileWriter();

            ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);

            Assert.IsFalse(ReflectionHelper.GetBoolResult(ldsAccessor, "UpdateLdsFile",
                                                          "c:\\whatever\\wherever\\whenever\\yeah.lds", new DummyUsfmStyEntry(),
                                                          Cache.DefaultVernWs, writer));
        }
        public void UpdateParatextLdsFile_GeneralSectionMissing()
        {
            if (File.Exists("test.lds"))
            {
                File.Delete("test.lds");
            }

            int             wsHvo  = Cache.DefaultVernWs;
            LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo);

            vernWs.Name.UserDefaultWritingSystem = "French";

            DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
            StyleInfoTable    styleTable  = new StyleInfoTable("Normal",
                                                               Cache.LanguageWritingSystemFactoryAccessor);

            styleTable.Add("Normal", normalEntry);
            normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
            normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

            string ldsContentsOrig =
                "[OtherStuff]";

            DummyFileWriter writer = new DummyFileWriter();

            writer.Open("test.lds");
            ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);

            ReflectionHelper.CallMethod(ldsAccessor, "UpdateLdsContents",
                                        ldsContentsOrig, normalEntry, Cache.DefaultVernWs, writer);

            // Verify the .lds file
            string[] expectedLdsContents =
            {
                "[OtherStuff]",
                //Environment.NewLine +
                "[General]",
                "codepage=65001",
                "font=Wingdings",
                "size=14",
                "name=French",
                "RTL=F"
            };

            writer.VerifyOutput(expectedLdsContents);
        }
        public void WriteParatextLdsFile()
        {
            if (File.Exists("test.lds"))
            {
                File.Delete("test.lds");
            }

            int             wsHvo  = Cache.DefaultVernWs;
            LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo);

            vernWs.Name.UserDefaultWritingSystem = "French";

            DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
            StyleInfoTable    styleTable  = new StyleInfoTable("Normal",
                                                               Cache.LanguageWritingSystemFactoryAccessor);

            styleTable.Add("Normal", normalEntry);
            normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
            normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

            ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
            DummyFileWriter         actualLds   = new DummyFileWriter();

            ReflectionHelper.CallMethod(ldsAccessor, "WriteParatextLdsFile", "test.lds",
                                        Cache.DefaultVernWs, normalEntry, actualLds);

            // Verify the .lds file
            string[] expectedLds =
            {
                "[General]",
                "codepage=65001",
                "RTL=F",
                "font=Wingdings",
                "name=French",
                "size=14",
                string.Empty,
                "[Checking]",
                string.Empty,
                "[Characters]",
                string.Empty,
                "[Punctuation]"
            };

            actualLds.VerifyOutput(expectedLds);
        }
        public void WriteParatextLdsFile_BT()
        {
            if (File.Exists("test.lds"))
            {
                File.Delete("test.lds");
            }

            int            wsUrduBT = InMemoryFdoCache.s_wsHvos.Ur;
            IWritingSystem btWs     = Cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(wsUrduBT);
            string         btWsName = btWs.get_UiName(Cache.DefaultUserWs);

            DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
            StyleInfoTable    styleTable  = new StyleInfoTable("Normal",
                                                               Cache.LanguageWritingSystemFactoryAccessor);

            styleTable.Add("Normal", normalEntry);
            normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
            normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

            DummyFileWriter         fileWriterLDS = new DummyFileWriter();
            ParatextLdsFileAccessor ldsAccessor   = new ParatextLdsFileAccessor(Cache);

            ReflectionHelper.CallMethod(ldsAccessor, "WriteParatextLdsFile", "test.lds",
                                        wsUrduBT, normalEntry, fileWriterLDS);

            // Verify the .lds file
            string[] expectedLds =
            {
                "[General]",
                "codepage=65001",
                "RTL=T",
                "font=Wingdings",
                "name=" + btWs.get_UiName(Cache.DefaultUserWs),
                "size=14",
                string.Empty,
                "[Checking]",
                string.Empty,
                "[Characters]",
                string.Empty,
                "[Punctuation]"
            };

            fileWriterLDS.VerifyOutput(expectedLds);
        }
        public void UpdateParatextLdsFile_UpdateFontAndSizeAndAddRTL()
        {
            if (File.Exists("test.lds"))
            {
                File.Delete("test.lds");
            }

            int             wsHvo  = Cache.DefaultVernWs;
            LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo);

            vernWs.Name.UserDefaultWritingSystem = "French";

            DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
            StyleInfoTable    styleTable  = new StyleInfoTable("Normal",
                                                               Cache.LanguageWritingSystemFactoryAccessor);

            styleTable.Add("Normal", normalEntry);
            normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
            normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

            string ldsContentsOrig =
                "[General]" + Environment.NewLine +
                "codepage=65001" + Environment.NewLine +
                "DialogFontsize=0" + Environment.NewLine +
                "LowerCaseLetters=" + Environment.NewLine +
                "NoCaseLetters=" + Environment.NewLine +
                "UpperCaseLetters=" + Environment.NewLine +
                "errors=" + Environment.NewLine +
                "font=Arial" + Environment.NewLine +
                "name=French" + Environment.NewLine +
                "separator=" + Environment.NewLine +
                "size=32" + Environment.NewLine +
                Environment.NewLine +
                "[Checking]" + Environment.NewLine +
                Environment.NewLine +
                "[Characters]" + Environment.NewLine +
                Environment.NewLine +
                "[Punctuation]" + Environment.NewLine +
                "diacritics=" + Environment.NewLine +
                "medial=";

            DummyFileWriter writer = new DummyFileWriter();

            writer.Open("test.lds");
            ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);

            ReflectionHelper.CallMethod(ldsAccessor, "UpdateLdsContents",
                                        ldsContentsOrig, normalEntry, Cache.DefaultVernWs, writer);

            // Verify the .lds file
            string[] expectedLdsContents =
            {
                "[General]",
                "codepage=65001",
                "DialogFontsize=0",
                "LowerCaseLetters=",
                "NoCaseLetters=",
                "UpperCaseLetters=",
                "errors=",
                "font=Wingdings",
                "name=French",
                "separator=",
                "size=14",
                "RTL=F",
                //Environment.NewLine, string.Empty
                "[Checking]",
                //Environment.NewLine, string.Empty
                "[Characters]",
                //Environment.NewLine, string.Empty
                "[Punctuation]",
                "diacritics=",
                "medial="
            };
            ((DummyFileWriter)writer).VerifyOutput(expectedLdsContents);
        }
Example #7
0
		private void EnsureEnglishLdsExists()
		{
			string paratextProjectDir = ParatextHelper.ProjectsDirectory;

			if (!String.IsNullOrEmpty(paratextProjectDir))
			{
				string englishLdsPathname = Path.Combine(paratextProjectDir, "English.lds");
				if (!File.Exists(englishLdsPathname))
				{
					IStStyle normalStyle = m_StyleSheet.FindStyle(ScrStyleNames.Normal);
					ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
					UsfmStyEntry normalUsfmStyle = new UsfmStyEntry();
					StyleInfoTable styleTable = new StyleInfoTable(normalStyle.Name,
						Cache.ServiceLocator.WritingSystemManager);
					normalUsfmStyle.SetPropertiesBasedOnStyle(normalStyle);
					styleTable.Add(normalStyle.Name, normalUsfmStyle);
					styleTable.ConnectStyles();
					ldsAccessor.WriteParatextLdsFile(englishLdsPathname,
						Cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en"), normalUsfmStyle);
					// We pass the directory (rather than passing no arguments, and letting the paratext dll figure
					// it out) because the figuring out goes wrong on Linux, where both programs are simulating
					// the registry.
					ScrTextCollection.Initialize(ParatextHelper.ProjectsDirectory, false);
				}
			}
		}
		public void UpdateParatextLdsFile_GeneralSectionMissing()
		{
			if (File.Exists("test.lds"))
				File.Delete("test.lds");

			int wsHvo = Cache.DefaultVernWs;
			LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo);
			vernWs.Name.UserDefaultWritingSystem = "French";

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			StyleInfoTable styleTable = new StyleInfoTable("Normal",
				Cache.LanguageWritingSystemFactoryAccessor);
			styleTable.Add("Normal", normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			string ldsContentsOrig =
				"[OtherStuff]";

			DummyFileWriter writer = new DummyFileWriter();
			writer.Open("test.lds");
			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			ReflectionHelper.CallMethod(ldsAccessor, "UpdateLdsContents",
				ldsContentsOrig, normalEntry, Cache.DefaultVernWs, writer);

			// Verify the .lds file
			string[] expectedLdsContents =
			{
				"[OtherStuff]",
				//Environment.NewLine +
				"[General]",
				"codepage=65001",
				"font=Wingdings",
				"size=14",
				"name=French",
				"RTL=F"
			};

			writer.VerifyOutput(expectedLdsContents);
		}
		public void WriteParatextLdsFile()
		{
			if (File.Exists("test.lds"))
				File.Delete("test.lds");

			int wsHvo = Cache.DefaultVernWs;
			LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo);
			vernWs.Name.UserDefaultWritingSystem = "French";

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			StyleInfoTable styleTable = new StyleInfoTable("Normal",
				Cache.LanguageWritingSystemFactoryAccessor);
			styleTable.Add("Normal", normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			DummyFileWriter actualLds = new DummyFileWriter();
			ReflectionHelper.CallMethod(ldsAccessor, "WriteParatextLdsFile", "test.lds",
				Cache.DefaultVernWs, normalEntry, actualLds);

			// Verify the .lds file
			string[] expectedLds =
			{
				"[General]",
				"codepage=65001",
				"RTL=F",
				"font=Wingdings",
				"name=French",
				"size=14",
				string.Empty,
				"[Checking]",
				string.Empty,
				"[Characters]",
				string.Empty,
				"[Punctuation]"
			};

			actualLds.VerifyOutput(expectedLds);
		}
		public void UpdateParatextLdsFile_UpdateFontAndSizeAndAddRTL()
		{
			if (File.Exists("test.lds"))
				File.Delete("test.lds");

			int wsHvo = Cache.DefaultVernWs;
			LgWritingSystem vernWs = new LgWritingSystem(Cache, wsHvo);
			vernWs.Name.UserDefaultWritingSystem = "French";

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			StyleInfoTable styleTable = new StyleInfoTable("Normal",
				Cache.LanguageWritingSystemFactoryAccessor);
			styleTable.Add("Normal", normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			string ldsContentsOrig =
				"[General]" + Environment.NewLine +
				"codepage=65001" + Environment.NewLine +
				"DialogFontsize=0" + Environment.NewLine +
				"LowerCaseLetters=" + Environment.NewLine +
				"NoCaseLetters=" + Environment.NewLine +
				"UpperCaseLetters=" + Environment.NewLine +
				"errors=" + Environment.NewLine +
				"font=Arial" + Environment.NewLine +
				"name=French" + Environment.NewLine +
				"separator=" + Environment.NewLine +
				"size=32" + Environment.NewLine +
				Environment.NewLine +
				"[Checking]" + Environment.NewLine +
				Environment.NewLine +
				"[Characters]" + Environment.NewLine +
				Environment.NewLine +
				"[Punctuation]" + Environment.NewLine +
				"diacritics=" + Environment.NewLine +
				"medial=";

			DummyFileWriter writer = new DummyFileWriter();
			writer.Open("test.lds");
			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			ReflectionHelper.CallMethod(ldsAccessor, "UpdateLdsContents",
				ldsContentsOrig, normalEntry, Cache.DefaultVernWs, writer);

			// Verify the .lds file
			string[] expectedLdsContents =
			{
				"[General]",
				"codepage=65001",
				"DialogFontsize=0",
				"LowerCaseLetters=",
				"NoCaseLetters=",
				"UpperCaseLetters=",
				"errors=",
				"font=Wingdings",
				"name=French",
				"separator=",
				"size=14",
				"RTL=F",
				//Environment.NewLine, string.Empty
				"[Checking]",
				//Environment.NewLine, string.Empty
				"[Characters]",
				//Environment.NewLine, string.Empty
				"[Punctuation]",
				"diacritics=",
				"medial="
			};
		   ((DummyFileWriter)writer).VerifyOutput(expectedLdsContents);
		}
		public void UpdateParatextLdsFile_FileMissing()
		{
			FileWriter writer = new FileWriter();

			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			Assert.IsFalse(ReflectionHelper.GetBoolResult(ldsAccessor, "UpdateLdsFile",
				"c:\\whatever\\wherever\\whenever\\yeah.lds", new DummyUsfmStyEntry(),
				Cache.DefaultVernWs, writer));
		}
		public void WriteParatextLdsFile_BT()
		{
			if (File.Exists("test.lds"))
				File.Delete("test.lds");

			int wsUrduBT = InMemoryFdoCache.s_wsHvos.Ur;
			IWritingSystem btWs = Cache.LanguageWritingSystemFactoryAccessor.get_EngineOrNull(wsUrduBT);
			string btWsName = btWs.get_UiName(Cache.DefaultUserWs);

			DummyUsfmStyEntry normalEntry = new DummyUsfmStyEntry();
			StyleInfoTable styleTable = new StyleInfoTable("Normal",
				Cache.LanguageWritingSystemFactoryAccessor);
			styleTable.Add("Normal", normalEntry);
			normalEntry.DefaultFontInfo.m_fontSize.ExplicitValue = 14000;
			normalEntry.DefaultFontInfo.m_fontName.ExplicitValue = "Wingdings";

			DummyFileWriter fileWriterLDS = new DummyFileWriter();
			ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(Cache);
			ReflectionHelper.CallMethod(ldsAccessor, "WriteParatextLdsFile", "test.lds",
				wsUrduBT, normalEntry, fileWriterLDS);

			// Verify the .lds file
			string[] expectedLds =
			{
				"[General]",
				"codepage=65001",
				"RTL=T",
				"font=Wingdings",
				"name=" + btWs.get_UiName(Cache.DefaultUserWs),
				"size=14",
				string.Empty,
				"[Checking]",
				string.Empty,
				"[Characters]",
				string.Empty,
				"[Punctuation]"
			};

			fileWriterLDS.VerifyOutput(expectedLds);
		}
Example #13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Install the control.
		/// </summary>
		/// <param name="dockHost">The control that hosts the browser</param>
		/// <param name="cache">The cache (needed in case we have to create the English LDS file
		/// on the fly)</param>
		/// <param name="normalStyle">The normal style (needed in case we have to create the
		/// English LDS file on the fly)</param>
		/// <returns>
		/// 	<c>true</c> if the browser was installed successfully; <c>false</c>
		/// otherwise.
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public bool Install(Control dockHost, FdoCache cache, IStStyle normalStyle)
		{
			while (true)
			{
				try
				{
					RegistrationInfo.AllowP6RegistrationCode = true;
					RegistrationInfo.AllowAccessToResources();
					string paratextProjectDir = ScrImportP6Project.ProjectDir;

					if (!String.IsNullOrEmpty(paratextProjectDir))
					{
						string englishLdsPathname = Path.Combine(paratextProjectDir, "English.lds");
						if (!File.Exists(englishLdsPathname))
						{
							ParatextLdsFileAccessor ldsAccessor = new ParatextLdsFileAccessor(cache);
							UsfmStyEntry normalUsfmStyle = new UsfmStyEntry();
							StyleInfoTable styleTable = new StyleInfoTable(normalStyle.Name,
								cache.LanguageWritingSystemFactoryAccessor);
							normalUsfmStyle.SetPropertiesBasedOnStyle(normalStyle);
							styleTable.Add(normalStyle.Name, normalUsfmStyle);
							styleTable.ConnectStyles();
							ldsAccessor.WriteParatextLdsFile(englishLdsPathname,
								cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en"), normalUsfmStyle);
						}
					}
					ScrTextCollection.Initialize();
					break;
				}
				catch (Exception e)
				{
					try
					{
						ReflectionHelper.SetField(typeof(ScrTextCollection), "initialized", false);
					}
					catch (Exception reflectionHelperException)
					{
						throw new ContinuableErrorException("Paratext resource browser failed to initialize." +
							Environment.NewLine + reflectionHelperException.Message, e);
					}
					if (MessageBox.Show(dockHost.FindForm(), String.Format(
						Properties.Resources.kstidCannotDisplayResourcePane,
						Application.ProductName, e.Message), Application.ProductName,
						MessageBoxButtons.RetryCancel, MessageBoxIcon.Error,
						MessageBoxDefaultButton.Button2) != DialogResult.Retry)
					{
						return false;
					}
				}
			}
			m_toolStrip.Text = "USFM Resource Browser";
			m_extender = new DockExtender(dockHost);
			dockHost.Controls.Add(this);
			m_floaty = m_extender.Attach(this, m_toolStrip, true);
			this.SendToBack();
			return true;
		}
Example #14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Writes (creates or updates) a Paratext LDS file.
		/// </summary>
		/// <param name="ldsFileName">Name of the LDS file.</param>
		/// <param name="ws">The writing system which the LDS file describes.</param>
		/// ------------------------------------------------------------------------------------
		protected void WriteParatextLdsFile(string ldsFileName, int ws)
		{
			ParatextLdsFileAccessor paratextLdsFileAccessor = new ParatextLdsFileAccessor(m_cache);
			UsfmStyEntry normalStyleEntry = (UsfmStyEntry)m_UsfmStyFileAccessor[ScrStyleNames.Normal];
			paratextLdsFileAccessor.WriteParatextLdsFile(ldsFileName, ws, normalStyleEntry);
		}