WikiFunctions.AWBSettings.UserPrefs.LoadPrefs C# (CSharp) Method

LoadPrefs() public static method

Loads the UserPrefs from the specified file
public static LoadPrefs ( string file ) : UserPrefs
file string File to load from
return UserPrefs
        public static UserPrefs LoadPrefs(string file)
        {
            string settings = File.ReadAllText(file, Encoding.UTF8);

            // test to see if it is an old AWB file
            if (settings.Contains("<projectlang proj="))
                throw new Exception("This file uses old settings format unsupported by this version of AWB.");

            // check for empty settings file
            if (settings.Trim().Length == 0)
            {
                MessageBox.Show("The settings file " + file + " is empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return (new UserPrefs());
            }

            settings = Regex.Replace(settings, @"<(/?)\s*SourceIndex>", "<$1SelectedProvider>");

            XmlSerializer xs = new XmlSerializer(typeof(UserPrefs), new[] { typeof(PrefsKeyPair) });
            return (UserPrefs)xs.Deserialize(new StringReader(settings));
        }