Exemplo n.º 1
0
        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.SuppressKeyTermLocalizationLangs = true;
            m_userInterfaceChooser.Init(m_sUserWs);

            // Populate Plugins tab page list.
            var baseConfigPath = FwDirectoryFinder.GetCodeSubDirectory(
                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(FwDirectoryFinder.DataDirectory,
                                                    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);
            }
        }
Exemplo n.º 2
0
 private string InvokePython(string arguments)
 {
     using (Process p = new Process())
     {
         p.StartInfo.FileName = "python";
         string dir = FwDirectoryFinder.GetCodeSubDirectory("/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);
     }
 }
Exemplo n.º 3
0
        private void m_btnOK_Click(object sender, EventArgs e)
        {
            Settings.Default.Reporting.OkToPingBasicUsageData = m_okToPingCheckBox.Checked;
            Settings.Default.Save();
            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 = FwDirectoryFinder.GetCodeSubDirectory(@"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(FwDirectoryFinder.DataDirectory, @"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 = FwDirectoryFinder.CodeDirectory;
                    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;
        }
Exemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Prepares the selected files to be uploaded to REAP using RAMP.
        /// </summary>
        /// <param name="owner">RAMP dialog owner</param>
        /// <param name="dialogFont">RAMP dialog font (for localization and consistency)</param>
        /// <param name="localizationDialogIcon"></param>
        /// <param name="filesToArchive"></param>
        /// <param name="mediator"></param>
        /// <param name="thisapp"></param>
        /// <param name="cache"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public bool ArchiveNow(Form owner, Font dialogFont, Icon localizationDialogIcon,
                               IEnumerable <string> filesToArchive, Mediator mediator, FwApp thisapp, FdoCache cache)
        {
            var viProvider = new VersionInfoProvider(Assembly.LoadFile(thisapp.ProductExecutableFile), false);
            var wsMgr      = cache.ServiceLocator.GetInstance <IWritingSystemManager>();
            var appName    = thisapp.ApplicationName;
            var title      = cache.LanguageProject.ShortName;
            var uiLocale   = wsMgr.Get(cache.DefaultUserWs).IcuLocale;
            var projectId  = cache.LanguageProject.ShortName;

            var model = new RampArchivingDlgViewModel(Application.ProductName, title, projectId, /*appSpecificArchivalProcessInfo:*/ string.Empty, SetFilesToArchive(filesToArchive), GetFileDescription);

            // image files should be labeled as Graphic rather than Photograph (the default).
            model.ImagesArePhotographs = false;

            // show the count of media files, not the duration
            model.ShowRecordingCountNotLength = true;

            // set the general description, in each available language
            IMultiString descr        = cache.LanguageProject.Description;
            var          descriptions = new Dictionary <string, string>();

            foreach (int wsid in descr.AvailableWritingSystemIds)
            {
                var descrText = descr.get_String(wsid).Text;
                if ((!string.IsNullOrEmpty(descrText)) && (descrText != "***"))
                {
                    descriptions[wsMgr.Get(wsid).GetIso3Code()] = descrText;
                }
            }

            if (descriptions.Count > 0)
            {
                model.SetDescription(descriptions);
            }

            AddMetsPairs(model, viProvider.ShortNumericAppVersion, cache);

            const string localizationMgrId = "Archiving";

            if (s_localizationMgr == null)
            {
                s_localizationMgr = LocalizationManager.Create(
                    uiLocale,
                    localizationMgrId, viProvider.ProductName, viProvider.NumericAppVersion,
                    FwDirectoryFinder.GetCodeSubDirectory("ArchivingLocalizations"),
                    Path.Combine(Application.CompanyName, appName),
                    localizationDialogIcon, "*****@*****.**", "SIL.Archiving");
            }
            else
            {
                LocalizationManager.SetUILanguage(uiLocale, true);
            }

            // create the dialog
            using (var dlg = new ArchivingDlg(model, localizationMgrId, dialogFont, new FormSettings()))
                using (var reportingAdapter = new PalasoErrorReportingAdapter(dlg, mediator))
                {
                    ErrorReport.SetErrorReporter(reportingAdapter);
                    dlg.ShowDialog(owner);
                    ErrorReport.SetErrorReporter(null);
                }

            return(true);
        }