Esempio n. 1
0
        /// <summary>
        /// Renames the .fwdictconfig files in the ReversalIndex Folder
        /// For ex. english.fwdictconfig to en.fwdictconfig
        /// </summary>
        /// <param name="configSettingsDir"></param>
        private static void RenameReversalConfigFiles(string configSettingsDir)
        {
            var    reversalIndexConfigLoc = Path.Combine(configSettingsDir, DictionaryConfigurationListener.ReversalIndexConfigurationDirectoryName);
            var    dictConfigFiles        = new List <string>(DCM.ConfigFilesInDir(reversalIndexConfigLoc));
            string newFName = string.Empty;
            string wsValue  = string.Empty;
            int    version  = 0;

            // Rename all the reversals based on the ws id (the user's  name for copies is still stored inside the file)
            foreach (string fName in dictConfigFiles)
            {
                wsValue = GetWritingSystemNameAndVersion(fName, out version);
                if (!string.IsNullOrEmpty(wsValue) && version < DCM.VersionCurrent)
                {
                    newFName = Path.Combine(Path.GetDirectoryName(fName), wsValue + DictionaryConfigurationModel.FileExtension);

                    if (wsValue == Path.GetFileNameWithoutExtension(fName))
                    {
                        continue;
                    }

                    newFName = FwUtils.GetUniqueFilename(Path.GetDirectoryName(fName), newFName);
                    File.Move(fName, newFName);
                }
            }
        }
Esempio n. 2
0
        /// <summary></summary>
        public ConverterTest()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();
            ofDlg            = new OpenFileDialogAdapter();
            ofDlg.DefaultExt = "txt";
            ofDlg.Filter     = FileUtils.FileDialogFilterCaseInsensitiveCombinations(FwCoreDlgs.ofDlg_Filter);

            saveFileDialog                  = new SaveFileDialogAdapter();
            saveFileDialog.DefaultExt       = "txt";
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.Filter           = ofDlg.Filter;

            if (DesignMode)
            {
                return;
            }

            InputArgsChanged();                 // set the initial state of the Convert button

            // Set view properties.
            m_fHasOutput = false;
            m_svOutput   = new SampleView();
            m_svOutput.WritingSystemFactory = FwUtils.CreateWritingSystemManager();
            m_svOutput.Dock      = DockStyle.Fill;
            m_svOutput.Visible   = true;
            m_svOutput.Enabled   = false;
            m_svOutput.BackColor = OutputPanel.BackColor;
            m_svOutput.TabIndex  = 1;
            m_svOutput.TabStop   = true;
            OutputPanel.Controls.Add(m_svOutput);
        }
Esempio n. 3
0
        static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                WriteHelp();
                return(0);
            }

            if (!File.Exists(args[0]))
            {
                Console.WriteLine("The FieldWorks project file could not be found.");
                return(1);
            }

            FwRegistryHelper.Initialize();
            FwUtils.InitializeIcu();
            Sldr.Initialize();
            var synchronizeInvoke = new SingleThreadedSynchronizeInvoke();
            var spanFactory       = new ShapeSpanFactory();

            var projectId = new ProjectIdentifier(args[0]);
            var logger    = new ConsoleLogger(synchronizeInvoke);
            var dirs      = new NullFdoDirectories();
            var settings  = new LcmSettings {
                DisableDataMigration = true
            };
            var progress = new NullThreadedProgress(synchronizeInvoke);

            Console.WriteLine("Loading FieldWorks project...");
            try
            {
                using (LcmCache cache = LcmCache.CreateCacheFromExistingData(projectId, "en", logger, dirs, settings, progress))
                {
                    Language language = HCLoader.Load(spanFactory, cache, logger);
                    Console.WriteLine("Loading completed.");
                    Console.WriteLine("Writing HC configuration file...");
                    XmlLanguageWriter.Save(language, args[1]);
                    Console.WriteLine("Writing completed.");
                }
                return(0);
            }
            catch (LcmFileLockedException)
            {
                Console.WriteLine("Loading failed.");
                Console.WriteLine("The FieldWorks project is currently open in another application.");
                Console.WriteLine("Close the application and try to run this command again.");
                return(1);
            }
            catch (LcmDataMigrationForbiddenException)
            {
                Console.WriteLine("Loading failed.");
                Console.WriteLine("The FieldWorks project was created with an older version of FLEx.");
                Console.WriteLine("Migrate the project to the latest version by opening it in FLEx.");
                return(1);
            }
        }
Esempio n. 4
0
 private static void HandleKeyPress(KeyPressEventArgs e)
 {
     if (e.KeyChar != (int)Keys.Back && e.KeyChar != (int)Keys.Return && e.KeyChar != (int)Keys.Delete &&
         !IsValidAbbrChar(e.KeyChar))
     {
         // Stop the character from being entered into the control since it is not valid.
         e.Handled = true;
         FwUtils.ErrorBeep();
     }
 }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the location for the provider for the specified project and provider type.
        /// If the providerType is not supported, return null for the Uri.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public Uri GetProviderLocation(string projhandle, string providerType)
        {
            LexicalProviderManager.ResetLexicalProviderTimer();

            if (providerType == kLexicalProviderType)
            {
                Uri projUri = new Uri("net.pipe://localhost/" + FwUtils.GeneratePipeHandle(projhandle) + ":LP");
                LexicalProviderManager.StartProvider(projUri, new LexicalProviderImpl(m_cache), typeof(ILexicalProvider));
                return(projUri);
            }

            return(null);
        }
Esempio n. 6
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            FwRegistryHelper.Initialize();
            FwUtils.InitializeIcu();
            Sldr.Initialize();
            using (var form = new LCMBrowserForm())
            {
                Application.Run(form);
            }

            Sldr.Cleanup();
        }
Esempio n. 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FwLexiconPlugin"/> class.
        /// </summary>
        public FwLexiconPlugin()
        {
            FwRegistryHelper.Initialize();

            // setup necessary environment variables on Linux
            if (MiscUtils.IsUnix)
            {
                // update ICU_DATA to location of ICU data files
                if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("ICU_DATA")))
                {
                    string codeIcuDataPath = Path.Combine(ParatextLexiconPluginDirectoryFinder.CodeDirectory, "Icu" + CustomIcu.Version);
#if DEBUG
                    string icuDataPath = codeIcuDataPath;
#else
                    string icuDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), ".config/fieldworks/Icu" + CustomIcu.Version);
                    if (!Directory.Exists(icuDataPath))
                    {
                        icuDataPath = codeIcuDataPath;
                    }
#endif
                    Environment.SetEnvironmentVariable("ICU_DATA", icuDataPath);
                }
                // update COMPONENTS_MAP_PATH to point to code directory so that COM objects can be loaded properly
                if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("COMPONENTS_MAP_PATH")))
                {
                    string compMapPath = Path.GetDirectoryName(FileUtils.StripFilePrefix(Assembly.GetExecutingAssembly().CodeBase));
                    Environment.SetEnvironmentVariable("COMPONENTS_MAP_PATH", compMapPath);
                }
                // update FW_ROOTCODE so that strings-en.txt file can be found
                if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("FW_ROOTCODE")))
                {
                    Environment.SetEnvironmentVariable("FW_ROOTCODE", ParatextLexiconPluginDirectoryFinder.CodeDirectory);
                }
            }
            FwUtils.InitializeIcu();
            if (!Sldr.IsInitialized)
            {
                Sldr.Initialize();
            }

            m_syncRoot     = new object();
            m_lexiconCache = new FdoLexiconCollection();
            m_cacheCache   = new LcmCacheCollection();
            m_ui           = new ParatextLexiconPluginLcmUI();
        }
Esempio n. 8
0
 private void m_destinationFolder_TextChanged(object sender, EventArgs e)
 {
     if (m_destinationFolder.Text.IndexOfAny(Path.GetInvalidPathChars()) != -1)
     {
         FwUtils.ErrorBeep();
         var fixText = m_destinationFolder.Text;
         for (; ;)
         {
             int index = fixText.IndexOfAny(Path.GetInvalidPathChars());
             if (index == -1)
             {
                 break;
             }
             fixText = fixText.Remove(index, 1);
         }
         m_destinationFolder.Text = fixText;
     }
     m_backUp.Enabled = (m_destinationFolder.Text.Trim().Length > 0);
 }
Esempio n. 9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Displays a dialog that allows the user to choose an FW language project.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public bool ShowOpenProject(Form owner, ref Rectangle dialogBounds,
                                    ref int dialogSplitterPos, out string name, out string server)
        {
            FwRegistryHelper.Initialize();
            FwUtils.InitializeIcu();

            using (var dlg = new ChooseLangProjectDialog(dialogBounds, dialogSplitterPos))
            {
                if (dlg.ShowDialog(owner) == DialogResult.OK)
                {
                    name              = dlg.Project;
                    server            = null;
                    dialogBounds      = dlg.Bounds;
                    dialogSplitterPos = dlg.SplitterPosition;
                    return(true);
                }
            }

            name   = null;
            server = null;
            return(false);
        }
Esempio n. 10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// This method is called just before this form is shown in undocked mode. It will
        /// read the registry to determine it's undocked size and location.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void PlaceUndockedWindow()
        {
            RegistryKey key = SettingsKey;

            if (key == null)
            {
                return;
            }

            string bounds = key.GetValue(ModifiedRegValue("UndockedBounds"), null) as string;

            if (bounds == null)
            {
                key.SetValue(ModifiedRegValue("UndockedBounds"), DesktopBounds);
            }
            else
            {
                Rectangle rc = FwUtils.GetRcFromString(bounds);
                if (rc != Rectangle.Empty)
                {
                    DesktopBounds = rc;
                }
            }
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            Form window      = null;
            var  needCleanup = true;

            try
            {
                // needed to access proper registry values
                FwRegistryHelper.Initialize();
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                switch (args.FirstOrDefault())
                {
                case "-i":
                case "-install":
                case "--install":
                    // If we have any custom character data, install it!
                    FwUtils.InitializeIcu();
                    var customCharsFile = CharEditorWindow.CustomCharsFile;
                    if (File.Exists(customCharsFile))
                    {
                        new PUAInstaller().InstallPUACharacters(customCharsFile);
                    }
                    break;

                case "--cleanup":
                    // If the second argument is a Process ID (int), wait up to five minutes for the proces to exit and then clean up;
                    // otherwise, silently do nothing.
                    needCleanup = false;
                    int pid;
                    if (int.TryParse(args.LastOrDefault(), out pid))
                    {
                        var iterationCount = 0;
                        while (Process.GetProcesses().Any(p => p.Id == pid) && iterationCount < 300)
                        {
                            // wait 1s then try again
                            Thread.Sleep(1000);
                            iterationCount++;
                        }

                        if (iterationCount < 300)
                        {
                            DeleteTemporaryFiles();
                        }
                    }
                    break;

                case null:
                    // There were no arguments (the program was double-clicked or opened through the Start menu); run the graphical interface
                    FwUtils.InitializeIcu();
                    window = new CharEditorWindow();
                    Application.Run(window);
                    break;

                default:
                    // An unrecognized argument was passed
                    MessageBox.Show("Only one command line argument is recognized:" + Environment.NewLine +
                                    "\t-i means to install the custom character definitions (as a command line program).",
                                    "Unicode Character Editor");
                    break;
                }
            }
            catch (ApplicationException ex)
            {
                MessageBox.Show(ex.Message, "Unicode Character Properties Editor");
            }
            catch (Exception ex)
            {
                // Be very, very careful about changing stuff here. Code here MUST not throw exceptions,
                // even when the application is in a crashed state.
                try
                {
                    ErrorReporter.ReportException(ex, null, null, window, true);
                }
                catch
                {
                    MessageBox.Show(ex.Message, "Unicode Character Properties Editor");
                }
            }
            finally
            {
                window?.Dispose();
                LogFile.Release();
                if (needCleanup)
                {
                    StartCleanup();
                }
            }
        }
Esempio n. 12
0
        private static void VerifyNewlyCreatedChars()
        {
            FwUtils.InitializeIcu();

            // The commented out methods below use u_getIntPropertyValue(), which doesn't
            // work reliably with the limited number of data files that we modify.
            //Assert.IsTrue(Icu.Character.IsAlphabetic(kChar1));	// now true
            //Assert.IsTrue(Icu.Character.IsAlphabetic(kChar2));	// now true
            //Assert.IsFalse(Icu.Character.IsAlphabetic(kChar3));
            //Assert.IsFalse(Icu.Character.IsAlphabetic(kChar4));
            Assert.IsFalse(Icu.Character.IsControl(kChar1));
            Assert.IsFalse(Icu.Character.IsControl(kChar2));
            Assert.IsFalse(Icu.Character.IsControl(kChar3));
            Assert.IsFalse(Icu.Character.IsControl(kChar4));
            //Assert.IsFalse(Icu.Character.IsDiacritic(kChar1));
            //Assert.IsFalse(Icu.Character.IsDiacritic(kChar2));
            //Assert.IsFalse(Icu.Character.IsDiacritic(kChar3));
            //Assert.IsFalse(Icu.Character.IsDiacritic(kChar4));
            //Assert.IsFalse(Icu.Character.IsIdeographic(kChar1));
            //Assert.IsFalse(Icu.Character.IsIdeographic(kChar2));
            //Assert.IsFalse(Icu.Character.IsIdeographic(kChar3));
            //Assert.IsFalse(Icu.Character.IsIdeographic(kChar4));
            //Assert.IsFalse(Icu.Character.IsNumeric(kChar1));
            //Assert.IsFalse(Icu.Character.IsNumeric(kChar2));
            //Assert.IsFalse(Icu.Character.IsNumeric(kChar3));
            //Assert.IsTrue(Icu.Character.IsNumeric(kChar4));		// now true
            Assert.IsFalse(Icu.Character.IsPunct(kChar1));
            Assert.IsFalse(Icu.Character.IsPunct(kChar2));
            Assert.IsTrue(Icu.Character.IsPunct(kChar3));                               // now true
            Assert.IsFalse(Icu.Character.IsPunct(kChar4));
            Assert.IsFalse(Icu.Character.IsSpace(kChar1));
            Assert.IsFalse(Icu.Character.IsSpace(kChar2));
            Assert.IsFalse(Icu.Character.IsSpace(kChar3));
            Assert.IsFalse(Icu.Character.IsSpace(kChar4));
            Assert.IsFalse(Icu.Character.IsSymbol(kChar1));
            Assert.IsFalse(Icu.Character.IsSymbol(kChar2));
            Assert.IsFalse(Icu.Character.IsSymbol(kChar3));
            Assert.IsFalse(Icu.Character.IsSymbol(kChar4));

            var cat = Icu.Character.GetCharType(kChar1);

            Assert.AreEqual(Icu.Character.UCharCategory.LOWERCASE_LETTER, cat);
            cat = Icu.Character.GetCharType(kChar2);
            Assert.AreEqual(Icu.Character.UCharCategory.UPPERCASE_LETTER, cat);
            cat = Icu.Character.GetCharType(kChar3);
            Assert.AreEqual(Icu.Character.UCharCategory.OTHER_PUNCTUATION, cat);
            cat = Icu.Character.GetCharType(kChar4);
            Assert.AreEqual(Icu.Character.UCharCategory.DECIMAL_DIGIT_NUMBER, cat);
            var decompositionType = CustomIcu.GetDecompositionTypeInfo(kChar1);

            Assert.AreEqual("[none]", decompositionType.Description);
            decompositionType = CustomIcu.GetDecompositionTypeInfo(kChar2);
            Assert.AreEqual("[none]", decompositionType.Description);
            decompositionType = CustomIcu.GetDecompositionTypeInfo(kChar3);
            Assert.AreEqual("[none]", decompositionType.Description);
            decompositionType = CustomIcu.GetDecompositionTypeInfo(kChar4);
            Assert.AreEqual("[none]", decompositionType.Description);
            var numericType = CustomIcu.GetNumericTypeInfo(kChar1);

            Assert.AreEqual("[none]", numericType.Description);
            numericType = CustomIcu.GetNumericTypeInfo(kChar2);
            Assert.AreEqual("[none]", numericType.Description);
            numericType = CustomIcu.GetNumericTypeInfo(kChar3);
            Assert.AreEqual("[none]", numericType.Description);

            // Current implementation (as of ICU50) is not overriding numeric type since we don't use it anywhere.
            // Enhance silmods.c in icu patch if needed.
            //numericType = Icu.GetNumericType(kChar4);
            //Assert.AreEqual("Decimal Digit", numericType.Description);

            // Current implementation (as of ICU50) is not overriding character names since we don't use them anywhere.
            // Enhance silmods.c in icu patch if needed.
            //var prettyName = Icu.GetPrettyICUCharName("\xE000");
            //Assert.AreEqual("My Special Character", prettyName);
            //prettyName = Icu.GetPrettyICUCharName("\xE001");
            //Assert.AreEqual("My Uppercase Character", prettyName);
            //prettyName = Icu.GetPrettyICUCharName(kChar3S);
            //Assert.AreEqual("New Punctuation Mark", prettyName);
            //var rawName = Icu.GetCharName(kChar4);	// can't pass large character code as 16-bit char.
            //Assert.AreEqual("NEW DIGIT NINE", rawName);
        }
Esempio n. 13
0
        private static void VerifyNonexistentChars()
        {
            FwUtils.InitializeIcu();

            Assert.IsFalse(Icu.Character.IsAlphabetic(kChar1));
            Assert.IsFalse(Icu.Character.IsAlphabetic(kChar2));
            Assert.IsFalse(Icu.Character.IsAlphabetic(kChar3));
            Assert.IsFalse(Icu.Character.IsAlphabetic(kChar4));
            Assert.IsFalse(Icu.Character.IsControl(kChar1));
            Assert.IsFalse(Icu.Character.IsControl(kChar2));
            Assert.IsFalse(Icu.Character.IsControl(kChar3));
            Assert.IsFalse(Icu.Character.IsControl(kChar4));
            Assert.IsFalse(Icu.Character.IsDiacritic(kChar1));
            Assert.IsFalse(Icu.Character.IsDiacritic(kChar2));
            Assert.IsFalse(Icu.Character.IsDiacritic(kChar3));
            Assert.IsFalse(Icu.Character.IsDiacritic(kChar4));
            Assert.IsFalse(Icu.Character.IsIdeographic(kChar1));
            Assert.IsFalse(Icu.Character.IsIdeographic(kChar2));
            Assert.IsFalse(Icu.Character.IsIdeographic(kChar3));
            Assert.IsFalse(Icu.Character.IsIdeographic(kChar4));
            Assert.IsFalse(Icu.Character.IsNumeric(kChar1));
            Assert.IsFalse(Icu.Character.IsNumeric(kChar2));
            Assert.IsFalse(Icu.Character.IsNumeric(kChar3));
            Assert.IsFalse(Icu.Character.IsNumeric(kChar4));
            Assert.IsFalse(Icu.Character.IsPunct(kChar1));
            Assert.IsFalse(Icu.Character.IsPunct(kChar2));
            Assert.IsFalse(Icu.Character.IsPunct(kChar3));
            Assert.IsFalse(Icu.Character.IsPunct(kChar4));
            Assert.IsFalse(Icu.Character.IsSpace(kChar1));
            Assert.IsFalse(Icu.Character.IsSpace(kChar2));
            Assert.IsFalse(Icu.Character.IsSpace(kChar3));
            Assert.IsFalse(Icu.Character.IsSpace(kChar4));
            Assert.IsFalse(Icu.Character.IsSymbol(kChar1));
            Assert.IsFalse(Icu.Character.IsSymbol(kChar2));
            Assert.IsFalse(Icu.Character.IsSymbol(kChar3));
            Assert.IsFalse(Icu.Character.IsSymbol(kChar4));

            Assert.AreEqual(Icu.Character.UCharCategory.PRIVATE_USE_CHAR, Icu.Character.GetCharType(kChar1));
            Assert.AreEqual(Icu.Character.UCharCategory.PRIVATE_USE_CHAR, Icu.Character.GetCharType(kChar2));
            Assert.AreEqual(Icu.Character.UCharCategory.UNASSIGNED, Icu.Character.GetCharType(kChar3));
            Assert.AreEqual(Icu.Character.UCharCategory.UNASSIGNED, Icu.Character.GetCharType(kChar4));
            var decompositionType = CustomIcu.GetDecompositionTypeInfo(kChar1);

            Assert.AreEqual("[none]", decompositionType.Description);
            decompositionType = CustomIcu.GetDecompositionTypeInfo(kChar2);
            Assert.AreEqual("[none]", decompositionType.Description);
            decompositionType = CustomIcu.GetDecompositionTypeInfo(kChar3);
            Assert.AreEqual("[none]", decompositionType.Description);
            decompositionType = CustomIcu.GetDecompositionTypeInfo(kChar4);
            Assert.AreEqual("[none]", decompositionType.Description);
            var numericType = CustomIcu.GetNumericTypeInfo(kChar1);

            Assert.AreEqual("[none]", numericType.Description);
            numericType = CustomIcu.GetNumericTypeInfo(kChar2);
            Assert.AreEqual("[none]", numericType.Description);
            numericType = CustomIcu.GetNumericTypeInfo(kChar3);
            Assert.AreEqual("[none]", numericType.Description);
            numericType = CustomIcu.GetNumericTypeInfo(kChar4);
            Assert.AreEqual("[none]", numericType.Description);
            var prettyName = Icu.Character.GetPrettyICUCharName("\xE000");

            Assert.IsNull(prettyName);
            prettyName = Icu.Character.GetPrettyICUCharName("\xE001");
            Assert.IsNull(prettyName);
            prettyName = Icu.Character.GetPrettyICUCharName(kChar3S);
            Assert.IsNull(prettyName);
            prettyName = Icu.Character.GetPrettyICUCharName("\xDDDDD");
            Assert.IsNull(prettyName);
        }
Esempio n. 14
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets the location for the provider for the specified project and provider type.
        /// If the providerType is not supported, return null for the Uri.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public Uri GetProviderLocation(string projhandle, string providerType)
        {
            LexicalProviderManager.ResetLexicalProviderTimer();

            if (providerType == kLexicalProviderType)
            {
                var url     = LexicalProviderManager.UrlPrefix + LexicalProviderManager.FixPipeHandle(FwUtils.GeneratePipeHandle(projhandle + ":LP"));
                Uri projUri = new Uri(url);
                LexicalProviderManager.StartProvider(projUri, new LexicalProviderImpl(m_cache), typeof(ILexicalProvider));
                return(projUri);
            }

            return(null);
        }
Esempio n. 15
0
 public string GetPostData()
 {
     return(FwUtils.XMLSerializer <FwPurchaseOutinorderAddRequest>(this));
 }