Exemplo n.º 1
0
        /// <summary>
        /// a slice filter is used to hide some slices.
        /// </summary>
        /// <remarks> this will set up a filter even if you do not specify a filter path, since
        /// some filtering is done by the FDO classes (CmObject.IsFieldRelevant)
        /// </remarks>
        /// <example>
        ///		to set up a slice filter,kids the relative path in the filterPath attribute of the parameters:
        ///		<control assemblyPath="xWorks.dll" class="SIL.FieldWorks.XWorks.RecordEditView">
        ///			<parameters field="Entries" templatePath="LexEd\XDEs" filterPath="LexEd\basicFilter.xml">
        ///			...
        ///</example>
        private void SetupSliceFilter()
        {
            try
            {
                string filterPath = XmlUtils.GetOptionalAttributeValue(m_configurationParameters, "filterPath");
                if (filterPath != null)
                {
#if __MonoCS__
                    // TODO-Linux: fix the data
                    filterPath = filterPath.Replace(@"\", "/");
#endif
                    var document = new XmlDocument();
                    document.Load(FwDirectoryFinder.GetCodeFile(filterPath));
                    m_dataEntryForm.SliceFilter = new SliceFilter(document);
                }
                else                 //just set up a minimal filter
                {
                    m_dataEntryForm.SliceFilter = new SliceFilter();
                }
            }
            catch (Exception e)
            {
                throw new ConfigurationException("Could not load the filter.", m_configurationParameters, e);
            }
        }
Exemplo n.º 2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Ensures the given localization is at the current version.
        /// </summary>
        /// <param name="locale">The locale representing the required localization.</param>
        /// <param name="caller">The form that is calling this method (used as the owner
        /// of the progress dialog box - can be null if progress dialog is supplied).</param>
        /// <param name="existingProgressDlg">The existing progress dialog box if any.</param>
        /// ------------------------------------------------------------------------------------
        private void EnsureCurrentLocalization(string locale, Form caller, IThreadedProgress existingProgressDlg)
        {
            string localizationFile = FwDirectoryFinder.GetKeyTermsLocFilename(locale);

            if (!FileUtils.FileExists(localizationFile))
            {
                return;                 // There is no localization available for this locale, so we're as current as we're going to get.
            }
            BiblicalTermsLocalization loc;

            try
            {
                loc = DeserializeBiblicalTermsLocFile(localizationFile);
            }
            catch (InstallationException e)
            {
                ErrorReporter.ReportException(e, m_app.SettingsKey, m_app.SupportEmailAddress, caller, false);
                return;
            }

            string resourceName = GetLocalizationResourceName(locale);

            if (IsResourceOutdated(resourceName, loc.Version))
            {
                NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(m_servLoc.GetInstance <IActionHandler>(),
                                                                   () => {
                    existingProgressDlg.RunTask(true, UpdateLocalization, loc, locale);
                    SetNewResourceVersion(resourceName, loc.Version);
                });
            }
        }
Exemplo n.º 3
0
        private string SettingsPath()
        {
            string path = FwDirectoryFinder.UserAppDataFolder(m_appName);

            Directory.CreateDirectory(path);
            path = Path.Combine(path, "DialogResponses.xml");
            return(path);
        }
Exemplo n.º 4
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.º 5
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Adds the available languages from localizations of the biblical terms file.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 private void AddAvailableLangsFromKeyTermsLocalizations()
 {
     foreach (string file in FwDirectoryFinder.KeyTermsLocalizationFiles)
     {
         if (!String.IsNullOrEmpty(file))
         {
             AddLanguage(FwDirectoryFinder.GetLocaleFromKeyTermsLocFile(file));
         }
     }
 }
Exemplo n.º 6
0
        private static void EnsureWindowConfiguration(PropertyTable propertyTable)
        {
            XmlNode xnWindow = propertyTable.GetValue <XmlNode>("WindowConfiguration");

            if (xnWindow == null)
            {
                string configFile = FwDirectoryFinder.GetCodeFile("Language Explorer/Configuration/Main.xml");
                // This can be called from TE...in that case, we don't complain about missing include
                // files (true argument) but just trust that we put enough in the installer to make it work.
                XmlDocument configuration           = XWindow.LoadConfigurationWithIncludes(configFile, true);
                XmlNode     windowConfigurationNode = configuration.SelectSingleNode("window");
                propertyTable.SetProperty("WindowConfiguration", windowConfigurationNode, true);
                propertyTable.SetPropertyPersistence("WindowConfiguration", false);
            }
        }
Exemplo n.º 7
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.º 8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new instance of the main X window
        /// </summary>
        /// <param name="progressDlg">The progress dialog to use, if needed (can be null).</param>
        /// <param name="isNewCache">Flag indicating whether one-time, application-specific
        /// initialization should be done for this cache.</param>
        /// <param name="wndCopyFrom">Must be null for creating the original app window.
        /// Otherwise, a reference to the main window whose settings we are copying.</param>
        /// <param name="fOpeningNewProject"><c>true</c> if opening a brand spankin' new
        /// project</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public override Form NewMainAppWnd(IProgress progressDlg, bool isNewCache,
                                           Form wndCopyFrom, bool fOpeningNewProject)
        {
            if (isNewCache)
            {
                // TODO: Do any needed initialization here.
            }
            Stream iconStream = ApplicationIconStream;

            Debug.Assert(iconStream != null, "Couldn't find the specified application icon as a resource.");
            string configFile;

            if (m_appArgs.ConfigFile != string.Empty)
            {
                configFile = m_appArgs.ConfigFile;
            }
            else
            {
                configFile = FwDirectoryFinder.GetCodeFile(DefaultConfigurationPathname);
                //					configFile = (string)SettingsKey.GetValue("LatestConfigurationFile",
                //						Path.Combine(FwDirectoryFinder.CodeDirectory,
                //						DefaultConfigurationPathname));
                if (!File.Exists(configFile))
                {
                    configFile = null;
                }
            }
            if (configFile == null)             // try to load from stream
            {
                return(new FwXWindow(this, wndCopyFrom, iconStream, ConfigurationStream));
            }

            // We pass a copy of the link information because it doesn't get used until after the following line
            // removes the information we need.
            FwXWindow result = new FwXWindow(this, wndCopyFrom, iconStream, configFile,
                                             m_appArgs.HasLinkInformation ? m_appArgs.CopyLinkArgs() : null);

            m_appArgs.ClearLinkInformation();             // Make sure the next window that is opened doesn't default to the same place
            return(result);
        }
Exemplo n.º 9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets all the available Key Terms localizations.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected virtual List <BiblicalTermsLocalization> GetLocalizations()
        {
            int defaultUserWs = m_scr.Cache.DefaultUserWs;

            string[] locFiles = FwDirectoryFinder.KeyTermsLocalizationFiles;
            List <BiblicalTermsLocalization> localizations =
                new List <BiblicalTermsLocalization>(locFiles.Length);
            bool fFoundDefaultLoc = false;

            foreach (string localizationFile in locFiles)
            {
                int hvoWs = GetWsFromLocFile(m_wsf, localizationFile);
                if (hvoWs > 0)
                {
                    BiblicalTermsLocalization loc = DeserializeBiblicalTermsLocFile(localizationFile);
                    if (loc != null)
                    {
                        fFoundDefaultLoc    |= (hvoWs == defaultUserWs);
                        loc.WritingSystemHvo = hvoWs;
                        localizations.Add(loc);
                    }
                }
            }
            if (!fFoundDefaultLoc || localizations.Count == 0)
            {
                string icuLocale = m_wsf.GetStrFromWs(defaultUserWs);
                string message   = String.Format("File {0} is missing", FwDirectoryFinder.GetKeyTermsLocFilename(icuLocale));
                Debug.Fail(message);
                Logger.WriteEvent(message);
                if (icuLocale == "en" || localizations.Count == 0)
                {
#if !DEBUG
                    message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
#endif
                    throw new InstallationException(message, null);
                }
            }
            return(localizations);
        }
Exemplo n.º 10
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.º 11
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);
        }
Exemplo n.º 12
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Gets the ws from loc file.
 /// </summary>
 /// <param name="wsf">The Writing System factory.</param>
 /// <param name="localizationFile">The localization file path.</param>
 /// <returns>The HVO of the writing system</returns>
 /// ------------------------------------------------------------------------------------
 public static int GetWsFromLocFile(ILgWritingSystemFactory wsf, string localizationFile)
 {
     return(wsf.GetWsFromStr(FwDirectoryFinder.GetLocaleFromKeyTermsLocFile(localizationFile)));
 }