예제 #1
0
        /// <summary>
        ///     Loads the user dictionary file
        /// </summary>
        private void LoadUserFile()
        {
            // load user words
            UserWords.Clear();

            // quit if user file is disabled
            if (!EnableUserFile)
            {
                return;
            }

            string userPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "NetSpell");
            string filePath = Path.Combine(userPath, UserFile);

            if (File.Exists(filePath))
            {
                TraceWriter.TraceInfo("Loading User Dictionary:{0}", filePath);

                FileStream fs = null;
                try
                {
                    fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                    using (var sr = new StreamReader(fs, Encoding.UTF8))
                    {
                        fs = null;

                        // read line by line
                        while (sr.Peek() >= 0)
                        {
                            string tempLine = sr.ReadLine().Trim();
                            if (tempLine.Length > 0)
                            {
                                UserWords.Add(tempLine, tempLine);
                            }
                        }
                    }
                }
                finally
                {
                    fs?.Dispose();
                }

                TraceWriter.TraceInfo("Loaded User Dictionary; Words:{0}", UserWords.Count);
            }
        }
 /// <summary>
 ///     Clears the user list of words
 /// </summary>
 /// <remarks>
 ///     This method is only affects the user word list
 /// </remarks>
 public void Clear()
 {
     UserWords.Clear();
     SaveUserFile();
 }