Exemplo n.º 1
0
 public static Font ToFont(XmlSerializableFont xmlSerializableFont)
 {
     return(new Font(
                xmlSerializableFont.FontName,
                xmlSerializableFont.FontSize,
                xmlSerializableFont.FontStyle));
 }
Exemplo n.º 2
0
        public static void WriteConfig(bool DesktopOnly = false)
        {
            const string RegPath = RegConst.Root + RegConst.Config;

            //Returns details of setting properties from all categories, or only Desktop category
            var settings =
                from categoryProperty in typeof(Config).GetProperties()
                where DesktopOnly ? categoryProperty.Name == "desktop" : categoryProperty.CanWrite
                let categoryType = categoryProperty.PropertyType
                                   let categoryObject = categoryProperty.GetValue(LoadedConfig, null)
                                                        from settingProperty in categoryType.GetProperties()
                                                        select new {
                keyPath = RegPath + categoryType.Name.Substring(1),
                name    = settingProperty.Name,
                type    = settingProperty.PropertyType,
                value   = settingProperty.GetValue(categoryObject, null)
            };

            foreach (var setting in settings)
            {
                using (var key = Registry.CurrentUser.CreateSubKey(setting.keyPath)) {
                    Type   t     = setting.type;
                    object value = setting.value;

                    if (t == typeof(bool))
                    {
                        value = (bool)value ? 1 : 0;
                    }
                    else if (t != typeof(int) && t != typeof(string) && !t.IsEnum)
                    {
                        if (t == typeof(Font))
                        {
                            value = XmlSerializableFont.FromFont((Font)value);
                            t     = typeof(XmlSerializableFont);
                        }
                        var ser = new DataContractJsonSerializer(t);
                        using (var stream = new MemoryStream()) {
                            try {
                                ser.WriteObject(stream, value);
                            } catch (Exception e) {
                                QTUtility2.MakeErrorLog(e);
                            }
                            stream.Position = 0;
                            value           = new StreamReader(stream).ReadToEnd();
                        }
                    }

                    key.SetValue(setting.name, value);
                }
            }
        }
Exemplo n.º 3
0
 public static Font ToFont(XmlSerializableFont xmlSerializableFont)
 {
     return new Font(
             xmlSerializableFont.FontName,
             xmlSerializableFont.FontSize,
             xmlSerializableFont.FontStyle);
 }