/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the available FLEx UI languages. /// </summary> /// ------------------------------------------------------------------------------------ private void AddAvailableFLExUILanguages() { // Now, find which languages have a localized strings-{locale}.xml file. // Allow only those languages which have valid .NET locales to be displayed. string sConfigDir = DirectoryFinder.GetFWCodeSubDirectory(@"Language Explorer\Configuration"); if (!Directory.Exists(sConfigDir)) { return; } string[] rgsFiles = Directory.GetFiles(sConfigDir, "strings-*.xml"); foreach (string file in rgsFiles) { string locale = Path.GetFileNameWithoutExtension(file); int i = locale.LastIndexOf('-'); if (i >= 0) { locale = locale.Substring(i + 1); if (MiscUtils.WsHasValidCulture(locale)) { AddLanguage(locale); } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Read the TEStyles.xml file to get the default marker mappings /// </summary> /// ------------------------------------------------------------------------------------ private static void ReadDefaultMappings() { XmlDocument doc = new XmlDocument(); doc.Load(Path.Combine(DirectoryFinder.GetFWCodeSubDirectory("Translation Editor"), "TEStyles.xml")); XmlNode mappingNode = doc.SelectSingleNode("Styles/ImportMappingSets/ImportMapping[@name='TE Default']"); foreach (XmlNode mapNode in mappingNode.SelectNodes("mapping")) { string marker = @"\" + mapNode.Attributes["id"].Value; string type = mapNode.Attributes["type"].Value; if (type == "style") { string styleName = mapNode.Attributes["styleName"].Value.Replace("_", " "); s_defaultMappings.Add(marker, styleName); } else if (type == "property") { s_defaultProperties.Add(marker, mapNode.Attributes["propertyName"].Value); } else if (type == "excluded") { s_defaultExclusions.Add(marker, string.Empty); } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Create the mediator if it doesn't already exist. Ensure that the string table in /// the mediator is loaded from the Flex string table. /// </summary> /// <param name="mediator"></param> /// <param name="fRestoreStringTable">output flag that we should restore the original string table</param> /// <param name="stOrig">output is the original string table</param> /// ------------------------------------------------------------------------------------ protected static Mediator EnsureValidMediator(Mediator mediator, out bool fRestoreStringTable, out StringTable stOrig) { if (mediator == null) { mediator = new Mediator(); fRestoreStringTable = false; stOrig = null; } else { try { stOrig = mediator.StringTbl; // Check whether this is the Flex string table: look for a lexicon type // string and compare the value with what is produced when it's not found. string s = stOrig.GetString("MoCompoundRule-Plural", "AlternativeTitles"); fRestoreStringTable = (s == "*MoCompoundRule-Plural*"); } catch { stOrig = null; fRestoreStringTable = true; } } if (fRestoreStringTable || stOrig == null) { string dir = DirectoryFinder.GetFWCodeSubDirectory("Language Explorer\\Configuration"); mediator.StringTbl = new SIL.Utils.StringTable(dir); } return(mediator); }
void IFwExtension.Init(FdoCache cache, Mediator mediator) { updateGlobalWS.Checked = !CoreImpl.Properties.Settings.Default.UpdateGlobalWSStore; m_mediator = mediator; m_cache = cache; m_helpTopicProvider = mediator.HelpTopicProvider; m_sUserWs = m_cache.ServiceLocator.WritingSystemManager.UserWritingSystem.Id; m_sNewUserWs = m_sUserWs; m_userInterfaceChooser.Init(m_sUserWs); // Populate Plugins tab page list. var baseConfigPath = DirectoryFinder.GetFWCodeSubDirectory( Path.Combine("Language Explorer", "Configuration")); string basePluginPath = Path.Combine(baseConfigPath, "Available Plugins"); // The extension XML files should be stored in the data area, not in the code area. // This reduces the need for users to have administrative privileges. string baseExtensionPath = Path.Combine(DirectoryFinder.FWDataDirectory, Path.Combine("Language Explorer", "Configuration")); foreach (string dir in Directory.GetDirectories(basePluginPath)) { Debug.WriteLine(dir); // Currently not offering Concorder plugin in FW7, therefore, we // can remove the feature until we need to implement. (FWNX-755) if (MiscUtils.IsUnix && dir == Path.Combine(basePluginPath, "Concorder")) { continue; } string managerPath = Path.Combine(dir, "ExtensionManager.xml"); if (File.Exists(managerPath)) { XmlDocument managerDoc = new XmlDocument(); managerDoc.Load(managerPath); XmlNode managerNode = managerDoc.SelectSingleNode("/manager"); m_lvPlugins.SuspendLayout(); ListViewItem lvi = new ListViewItem(); lvi.Tag = managerDoc; lvi.Text = managerNode.Attributes["name"].Value; lvi.SubItems.Add(managerNode.Attributes["description"].Value); // See if it is installed and check the lvi if it is. XmlNode configfilesNode = managerNode.SelectSingleNode("configfiles"); string extensionPath = Path.Combine(baseExtensionPath, configfilesNode.Attributes["targetdir"].Value); lvi.Checked = Directory.Exists(extensionPath); m_plugins.Add(lvi.Text, lvi.Checked); // Remember original installed state. m_lvPlugins.Items.Add(lvi); m_lvPlugins.ResumeLayout(); } } if (m_helpTopicProvider != null) // Will be null when running tests { helpProvider = new HelpProvider(); helpProvider.HelpNamespace = m_helpTopicProvider.HelpFile; helpProvider.SetHelpKeyword(this, m_helpTopicProvider.GetHelpString(s_helpTopic)); helpProvider.SetHelpNavigator(this, HelpNavigator.Topic); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Use this for slow operations that should happen during the splash screen instead of /// during app construction /// </summary> /// ------------------------------------------------------------------------------------ protected override void DoApplicationInitialization() { base.DoApplicationInitialization(); CleanupRegistry(); CleanupOldFiles(); //InitializeMessageDialogs(); ScrReference.InitializeVersification(DirectoryFinder.GetFWCodeSubDirectory( "Translation Editor"), false); }
protected override void DoApplicationInitialization() { base.DoApplicationInitialization(); if (IsTEInstalled) { ScrReference.InitializeVersification(DirectoryFinder.GetFWCodeSubDirectory( "Translation Editor"), false); } //usage report SIL.Utils.UsageEmailDialog.DoTrivialUsageReport("*****@*****.**", xWorksStrings.ThankYouForCheckingOutFlex, new int[] { 1 }); SIL.Utils.UsageEmailDialog.DoTrivialUsageReport("*****@*****.**", xWorksStrings.HaveLaunchedFLEXTenTimes, new int[] { 10 }); SIL.Utils.UsageEmailDialog.DoTrivialUsageReport("*****@*****.**", xWorksStrings.HaveLaunchedFLEXFortyTimes, new int[] { 40 }); }
private string InvokePython(string arguments) { using (Process p = new Process()) { p.StartInfo.FileName = "python"; string dir = DirectoryFinder.GetFWCodeSubDirectory("/Language Explorer/UserScripts"); p.StartInfo.Arguments = System.IO.Path.Combine(dir, "TransduceCitationForms.py ") + " " + arguments; p.StartInfo.RedirectStandardOutput = true; p.StartInfo.UseShellExecute = false; p.StartInfo.CreateNoWindow = true; p.Start(); p.WaitForExit(1000); string output = p.StandardOutput.ReadToEnd(); return(output); } }
private void ExportTE() { m_xhtml.WriteXhtmlHeading(m_fileName, m_sDescription, "scrBody"); ExportScripture(); m_xhtml.WriteXhtmlEnding(); m_writer.Close(); string sXsltFile = Path.Combine(DirectoryFinder.GetFWCodeSubDirectory("Translation Editor"), "XhtmlExport.xsl"); string sTempFile1 = m_fileName + "-1"; if (File.Exists(sTempFile1)) { File.Delete(sTempFile1); } File.Move(m_fileName, sTempFile1); XslCompiledTransform xsl = new XslCompiledTransform(); xsl.Load(sXsltFile); xsl.Transform(sTempFile1, m_fileName); //#if DEBUG // string sSave = m_fileName + "-Phase1"; // File.Delete(sSave); // File.Copy(sTempFile1, sSave); //#endif File.Delete(sTempFile1); string sTempFile2 = m_fileName + "-2"; if (File.Exists(sTempFile2)) { File.Delete(sTempFile2); } File.Move(m_fileName, sTempFile2); m_xhtml.FinalizeXhtml(m_fileName, sTempFile2); //#if DEBUG // sSave = m_fileName + "-Phase2"; // File.Delete(sSave); // File.Copy(sTempFile2, sSave); //#endif File.Delete(sTempFile2); m_xhtml.WriteCssFile(Path.ChangeExtension(m_fileName, ".css"), m_styleSheet, XhtmlHelper.CssType.Scripture, m_pub); }
void IFwExtension.Init(SIL.FieldWorks.FDO.FdoCache cache, XCore.Mediator mediator) { m_mediator = mediator; m_cache = cache; m_sUserWs = SIL.FieldWorks.Common.Framework.FwApp.UserWs; m_sNewUserWs = m_sUserWs; m_userInterfaceChooser.Init(m_sUserWs); //PopulateLanguagesCombo(); // Populate Plugins tab page list. string baseConfigPath = DirectoryFinder.GetFWCodeSubDirectory(@"Language Explorer\Configuration"); string basePluginPath = Path.Combine(baseConfigPath, "Available Plugins"); // The extension XML files should be stored in the data area, not in the code area. // This reduces the need for users to have administrative privileges. string baseExtensionPath = Path.Combine(DirectoryFinder.FWDataDirectory, @"Language Explorer\Configuration"); foreach (string dir in Directory.GetDirectories(basePluginPath)) { Debug.WriteLine(dir); string managerPath = Path.Combine(dir, "ExtensionManager.xml"); if (File.Exists(managerPath)) { XmlDocument managerDoc = new XmlDocument(); managerDoc.Load(managerPath); XmlNode managerNode = managerDoc.SelectSingleNode("/manager"); m_lvPlugins.SuspendLayout(); ListViewItem lvi = new ListViewItem(); lvi.Tag = managerDoc; lvi.Text = managerNode.Attributes["name"].Value; lvi.SubItems.Add(managerNode.Attributes["description"].Value); // See if it is installed and check the lvi if it is. XmlNode configfilesNode = managerNode.SelectSingleNode("configfiles"); string extensionPath = Path.Combine(baseExtensionPath, configfilesNode.Attributes["targetdir"].Value); lvi.Checked = Directory.Exists(extensionPath); m_plugins.Add(lvi.Text, lvi.Checked); // Remember original installed state. m_lvPlugins.Items.Add(lvi); m_lvPlugins.ResumeLayout(); } } }
public void GetFWCodeSubDirectory_NoLeadingSlash() { Assert.That(DirectoryFinder.GetFWCodeSubDirectory("Translation Editor/Configuration"), Is.SamePath(Path.Combine(DirectoryFinder.FWCodeDirectory, "Translation Editor/Configuration"))); }
public void GetFWCodeSubDirectory_InvalidDir() { Assert.That(DirectoryFinder.GetFWCodeSubDirectory("NotExisting"), Is.SamePath("NotExisting")); }
private void m_btnOK_Click(object sender, EventArgs e) { m_sNewUserWs = m_userInterfaceChooser.NewUserWs; if (m_sUserWs != m_sNewUserWs) { CultureInfo ci = MiscUtils.GetCultureForWs(m_sNewUserWs); if (ci != null) { FormLanguageSwitchSingleton.Instance.ChangeCurrentThreadUICulture(ci); FormLanguageSwitchSingleton.Instance.ChangeLanguage(this); #if __MonoCS__ // Mono leaves the wait cursor on, unlike .Net itself. Cursor.Current = Cursors.Default; #endif } // This needs to be consistent with Common/FieldWorks/FieldWorks.SetUICulture(). FwRegistryHelper.FieldWorksRegistryKey.SetValue(FwRegistryHelper.UserLocaleValueName, m_sNewUserWs); //The writing system the user selects for the user interface may not be loaded yet into the project //database. Therefore we need to check this first and if it is not we need to load it. IWritingSystem ws; m_cache.ServiceLocator.WritingSystemManager.GetOrSet(m_sNewUserWs, out ws); m_cache.ServiceLocator.WritingSystemManager.UserWritingSystem = ws; // Reload the mediator's string table with the appropriate language data. m_mediator.StringTbl.Reload(m_sNewUserWs); } // Handle installing/uninstalling plugins. if (m_lvPlugins.Items.Count > 0) { List <XmlDocument> pluginsToInstall = new List <XmlDocument>(); List <XmlDocument> pluginsToUninstall = new List <XmlDocument>(); foreach (ListViewItem lvi in m_lvPlugins.Items) { string name = lvi.Text; XmlDocument managerDoc = lvi.Tag as XmlDocument; if (lvi.Checked && !m_plugins[name]) { // Remember we need to install it. pluginsToInstall.Add(managerDoc); } else if (!lvi.Checked && m_plugins[name]) { // Remember we need to uninstall it. pluginsToUninstall.Add(managerDoc); } } m_pluginsUpdated = pluginsToInstall.Count > 0 || pluginsToUninstall.Count > 0; string basePluginPath = DirectoryFinder.GetFWCodeSubDirectory(@"Language Explorer\Configuration\Available Plugins"); // The extension XML files should be stored in the data area, not in the code area. // This reduces the need for users to have administrative privileges. string baseExtensionPath = Path.Combine(DirectoryFinder.FWDataDirectory, @"Language Explorer\Configuration"); // Really do the install now. foreach (XmlDocument managerDoc in pluginsToInstall) { XmlNode managerNode = managerDoc.SelectSingleNode("/manager"); string srcDir = Path.Combine(basePluginPath, managerNode.Attributes["name"].Value); XmlNode configfilesNode = managerNode.SelectSingleNode("configfiles"); string extensionPath = Path.Combine(baseExtensionPath, configfilesNode.Attributes["targetdir"].Value); Directory.CreateDirectory(extensionPath); foreach (XmlNode fileNode in configfilesNode.SelectNodes("file")) { string filename = fileNode.Attributes["name"].Value; string extensionPathname = Path.Combine(extensionPath, filename); try { File.Copy( Path.Combine(srcDir, filename), extensionPathname, true); File.SetAttributes(extensionPathname, FileAttributes.Normal); } catch { // Eat copy exception. } } string fwInstallDir = DirectoryFinder.FWCodeDirectory; foreach (XmlNode dllNode in managerNode.SelectNodes("dlls/file")) { string filename = dllNode.Attributes["name"].Value; string dllPathname = Path.Combine(fwInstallDir, filename); try { File.Copy( Path.Combine(srcDir, filename), dllPathname, true); File.SetAttributes(dllPathname, FileAttributes.Normal); } catch { // Eat copy exception. } } } // Really do the uninstall now. foreach (XmlDocument managerDoc in pluginsToUninstall) { XmlNode managerNode = managerDoc.SelectSingleNode("/manager"); string shutdownMsg = XmlUtils.GetOptionalAttributeValue(managerNode, "shutdown"); if (!String.IsNullOrEmpty(shutdownMsg)) { m_mediator.SendMessage(shutdownMsg, null); } XmlNode configfilesNode = managerNode.SelectSingleNode("configfiles"); string extensionPath = Path.Combine(baseExtensionPath, configfilesNode.Attributes["targetdir"].Value); Directory.Delete(extensionPath, true); // Leave any dlls in place since they may be shared, or in use for the moment. } } CoreImpl.Properties.Settings.Default.UpdateGlobalWSStore = !updateGlobalWS.Checked; CoreImpl.Properties.Settings.Default.Save(); AutoOpenLastProject = m_autoOpenCheckBox.Checked; DialogResult = DialogResult.OK; }
private void m_btnOK_Click(object sender, EventArgs e) { m_sNewUserWs = m_userInterfaceChooser.NewUserWs; if (m_sUserWs != m_sNewUserWs) { CultureInfo ci = MiscUtils.GetCultureForWs(m_sNewUserWs); if (ci != null) { FormLanguageSwitchSingleton.Instance.ChangeCurrentThreadUICulture(ci); FormLanguageSwitchSingleton.Instance.ChangeLanguage(this); Microsoft.Win32.RegistryKey settingsKey = FwApp.App.SettingsKey; settingsKey.SetValue("UserWs", m_sNewUserWs); } // Reload the mediator's string table with the appropriate language data. m_mediator.StringTbl.Reload(m_sNewUserWs); } // Handle installing/uninstalling plugins. if (m_lvPlugins.Items.Count > 0) { List <XmlDocument> pluginsToInstall = new List <XmlDocument>(); List <XmlDocument> pluginsToUninstall = new List <XmlDocument>(); foreach (ListViewItem lvi in m_lvPlugins.Items) { string name = lvi.Text; XmlDocument managerDoc = lvi.Tag as XmlDocument; if (lvi.Checked && !m_plugins[name]) { // Remember we need to install it. pluginsToInstall.Add(managerDoc); } else if (!lvi.Checked && m_plugins[name]) { // Remember we need to uninstall it. pluginsToUninstall.Add(managerDoc); } } m_pluginsUpdated = pluginsToInstall.Count > 0 || pluginsToUninstall.Count > 0; string basePluginPath = DirectoryFinder.GetFWCodeSubDirectory(@"Language Explorer\Configuration\Available Plugins"); // The extension XML files should be stored in the data area, not in the code area. // This reduces the need for users to have administrative privileges. string baseExtensionPath = Path.Combine(DirectoryFinder.FWDataDirectory, @"Language Explorer\Configuration"); // Really do the install now. foreach (XmlDocument managerDoc in pluginsToInstall) { XmlNode managerNode = managerDoc.SelectSingleNode("/manager"); string srcDir = Path.Combine(basePluginPath, managerNode.Attributes["name"].Value); XmlNode configfilesNode = managerNode.SelectSingleNode("configfiles"); string extensionPath = Path.Combine(baseExtensionPath, configfilesNode.Attributes["targetdir"].Value); Directory.CreateDirectory(extensionPath); foreach (XmlNode fileNode in configfilesNode.SelectNodes("file")) { string filename = fileNode.Attributes["name"].Value; string extensionPathname = Path.Combine(extensionPath, filename); try { File.Copy( Path.Combine(srcDir, filename), extensionPathname, true); File.SetAttributes(extensionPathname, FileAttributes.Normal); } catch { // Eat copy exception. } } string fwInstallDir = DirectoryFinder.FWCodeDirectory; foreach (XmlNode dllNode in managerNode.SelectNodes("dlls/file")) { string filename = dllNode.Attributes["name"].Value; string dllPathname = Path.Combine(fwInstallDir, filename); try { File.Copy( Path.Combine(srcDir, filename), dllPathname, true); File.SetAttributes(dllPathname, FileAttributes.Normal); } catch { // Eat copy exception. } } } // Really do the uninstall now. foreach (XmlDocument managerDoc in pluginsToUninstall) { XmlNode managerNode = managerDoc.SelectSingleNode("/manager"); string shutdownMsg = XmlUtils.GetOptionalAttributeValue(managerNode, "shutdown"); if (!String.IsNullOrEmpty(shutdownMsg)) { m_mediator.SendMessage(shutdownMsg, null); } XmlNode configfilesNode = managerNode.SelectSingleNode("configfiles"); string extensionPath = Path.Combine(baseExtensionPath, configfilesNode.Attributes["targetdir"].Value); Directory.Delete(extensionPath, true); // Leave any dlls in place since they may be shared, or in use for the moment. } } //The writing system the user selects for the user interface may not be loaded yet into the project //database. Therefore we need to check this first and if it is not we need to load it. if (m_sUserWs != m_sNewUserWs) { CreateWsIfNeeded(m_sNewUserWs); m_cache.LanguageWritingSystemFactoryAccessor.UserWs = m_cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr(m_sNewUserWs); } DialogResult = DialogResult.OK; }
/// <summary> /// Check whether various FieldWorks C++ COM classes are registered, and whether the /// corresponding DLLs exist. If so, find the dumpxml.exe program, which will either be /// in the same directory (for user machines), or close by (for developer machines), and /// save its path for later use. /// Also checks that the installation is between version 5.4 and version 6.0, that the /// final SQL Migration script exists, and /// </summary> /// <returns>true if FwCellar.dll, MigrateData.dll, and dumpxml.exe all exist</returns> public bool IsValidOldFwInstalled(out string version) { version = String.Empty; try { using (var clsidKey = Registry.ClassesRoot.OpenSubKey("CLSID")) { if (clsidKey == null) { if (m_fVerboseDebug) { MessageBoxUtils.Show("Unable to open the CLSID registry subkey????", "DEBUG!"); } return(false); } // check for registered class id for FwXmlData. string cellarPath = FindComDllIfRegistered(clsidKey, "{2F0FCCC2-C160-11D3-8DA2-005004DEFEC4}", ref version); if (cellarPath == null) { if (m_fVerboseDebug) { MessageBoxUtils.Show("FwCellar.dll is not registered.", "DEBUG!"); } return(false); } // check for registered class id for MigrateData. string migratePath = FindComDllIfRegistered(clsidKey, "{461989B4-CA92-4EAB-8CAD-ADB28C3B4D10}", ref version); if (migratePath == null) { if (m_fVerboseDebug) { MessageBoxUtils.Show("MigrateData.dll is not registered.", "DEBUG!"); } return(false); } // check for registered class id for LgWritingSystemFactory. string languagePath = FindComDllIfRegistered(clsidKey, "{D96B7867-EDE6-4C0D-80C6-B929300985A6}", ref version); if (languagePath == null) { if (m_fVerboseDebug) { MessageBoxUtils.Show("Language.dll is not registered.", "DEBUG!"); } return(false); } // check for registered class id for TsStrFactory. string kernelPath = FindComDllIfRegistered(clsidKey, "{F1EF76E9-BE04-11D3-8D9A-005004DEFEC4}", ref version); if (kernelPath == null) { if (m_fVerboseDebug) { MessageBoxUtils.Show("FwKernel.dll is not registered.", "DEBUG!"); } return(false); } // check for registered class id for OleDbEncap. string dbaccessPath = FindComDllIfRegistered(clsidKey, "{AAB4A4A3-3C83-11D4-A1BB-00C04F0C9593}", ref version); if (dbaccessPath == null) { if (m_fVerboseDebug) { MessageBoxUtils.Show("DbAccess.dll is not registered.", "DEBUG!"); } return(false); } // Get (and save) the path to dumpxml.exe. string basepath = Path.GetDirectoryName(cellarPath); m_dumpxmlPath = Path.Combine(basepath, "dumpxml.exe"); if (!File.Exists(m_dumpxmlPath)) { // Not found where it should be on a user machine. Try for where it exists // on a developer machine. int idxOutput = basepath.IndexOf("\\Output\\"); if (idxOutput > 0) { basepath = basepath.Substring(0, idxOutput); m_dumpxmlPath = Path.Combine(basepath, "Bin\\dumpxml.exe"); if (!File.Exists(m_dumpxmlPath)) { if (m_fVerboseDebug) { MessageBoxUtils.Show("Cannot find dumpxml.exe in the old FieldWorks installation.", "DEBUG!"); } return(false); } } } // Check for 200259To200260.sql migration script. string scriptPath = Path.Combine(basepath, "DataMigration\\200259To200260.sql"); if (!File.Exists(scriptPath)) { // Not found where it should be on a user machine. Try for where it exists // on a developer machine. scriptPath = Path.Combine(basepath, "DistFiles\\DataMigration\\200259To200260.sql"); if (!File.Exists(scriptPath)) { if (m_fVerboseDebug) { MessageBoxUtils.Show("Cannot find DataMigration\\200259To200260.sql in the old FieldWorks installation.", "DEBUG!"); } return(false); } } m_dbPath = Path.Combine(DirectoryFinder.GetFWCodeSubDirectory("MSSQLMigration"), "db.exe"); if (!File.Exists(m_dbPath)) { if (m_fVerboseDebug) { MessageBoxUtils.Show("Cannot find MSSQLMigration\\db.exe in the FieldWorks 7.0 installation.", "DEBUG!"); } return(false); } return(true); } } catch (Exception e) { if (m_fVerboseDebug) { string msg = String.Format( "An exception was thrown while checking for an old version of FieldWorks:{1}{0}", e.Message, Environment.NewLine); MessageBoxUtils.Show(msg, "DEBUG!"); } } return(false); }