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

SavePrefs() public static method

Saves the UserPrefs to the specified file
public static SavePrefs ( UserPrefs prefs, string file ) : void
prefs UserPrefs UserPrefs object to save
file string File to save to
return void
        public static void SavePrefs(UserPrefs prefs, string file)
        {
            try
            {
                using (StreamWriter fStream = new StreamWriter(file, false, Encoding.UTF8))
                {
                    List<Type> types = SavePluginSettings(prefs);

                    XmlSerializer xs = new XmlSerializer(typeof(UserPrefs), types.ToArray());
                    xs.Serialize(fStream, prefs);
                }
            }
            catch (Exception ex)
            {
                // https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Bugs/Archive_22#InvalidOperationException_in_UserPrefs.LoadPrefs_.2F_UserPrefs.SavePrefs
                // Saving settings will fail if permissions problems, so handle this
                if (ex is InvalidOperationException && ex.Message.Contains("CS0016"))
                {
                    MessageBox.Show("Saving settings failed due to insufficient permissions.", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                    ErrorHandler.HandleException(ex);
            }
        }