private static FieldInfo GetFieldInfo(string name, Type type, out ProfileValueAttribute attr) { foreach (FieldInfo field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { if (ProfileValueAttribute.IsProfileKey(field, out attr) && String.Compare(attr.Name, name, true) == 0) { return(field); } } attr = null; return(null); }
private void SavePreset(ProfilePreset preset, ProfilePreset defPreset, XmlNode node) { bool bDefPreset = (preset == defPreset); Type type = typeof(ProfilePreset); foreach (FieldInfo field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { ProfileValueAttribute attr = null; if (ProfileValueAttribute.IsProfileKey(field, out attr)) { bool bSetValue = false; bool bRemoveValue = false; if (bDefPreset) { bSetValue = !attr.UserProfilesOnly; } else if (!attr.BaseProfileOnly) { if (defPreset == null) { bSetValue = true; } else { bSetValue = !IsEqual(field.GetValue(preset), field.GetValue(defPreset)); bRemoveValue = true; } } if (bSetValue) { SetValue(node, attr.Name, field.GetValue(preset)); } else if (bRemoveValue) { RemoveValue(node, attr.Name); } } } }
private void SaveKeys(ProfileKeys profile, XmlNode node) { XmlNode InsideNode = FindNode(node.ChildNodes, "Keys"); ProfileKeys defaultKeys = DefaultProfile.Keys; bool bDefProfile = (profile == defaultKeys); Type type = typeof(ProfileKeys); foreach (FieldInfo field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { ProfileValueAttribute attr = null; if (ProfileValueAttribute.IsProfileKey(field, out attr)) { bool bSetValue = false; bool bRemoveValue = false; if (bDefProfile) { bSetValue = !attr.UserProfilesOnly; } else if (!attr.BaseProfileOnly) { bSetValue = !IsEqual(field.GetValue(profile), field.GetValue(defaultKeys)); bRemoveValue = true; } if (bSetValue) { SetKey(node, ref InsideNode, attr.Name, field.GetValue(profile)); } else if (bRemoveValue) { RemoveKey(InsideNode, attr.Name); } } } }
private void SaveProfile(Profile profile, XmlNode node) { bool bDefProfile = (profile == DefaultProfile); XmlDocument doc = node.OwnerDocument; if (profile.PreviousName != profile.Name) { if (!bDefProfile) { node.Attributes["Name"].Value = profile.Name; } profile.PreviousName = profile.Name; profile.UserChangeProfileName = true; } if (profile.Files.Count > 0) { XmlElement child = FindNode(node.ChildNodes, "File"); if (child == null) { child = CreateChildNodeWithAttribute(node, "File", "Name"); } // TODO: Support multiple files child.Attributes[0].Value = profile.Files[0].filename; if (profile.Files[0].cmdLine != null) { child.SetAttribute("CmdLine", profile.Files[0].cmdLine); } } Type type = typeof(Profile); foreach (FieldInfo field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { ProfileValueAttribute attr = null; if (ProfileValueAttribute.IsProfileKey(field, out attr)) { bool bSetValue = false; bool bRemoveValue = false; if (bDefProfile) { bSetValue = !attr.UserProfilesOnly; } else if (!attr.BaseProfileOnly) { bSetValue = !IsEqual(field.GetValue(profile), field.GetValue(DefaultProfile)); bRemoveValue = true; } if (bSetValue) { SetValue(node, attr.Name, field.GetValue(profile)); } else if (bRemoveValue) { RemoveValue(node, attr.Name); } } } // PRESETS SECTION SavePresets(profile.Presets, DefaultProfile.Presets, node); // KEYS SECTION SaveKeys(profile.Keys, node); }
public void ApplyValues(Profile profile) { Type type = typeof(Profile); foreach (FieldInfo field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { ProfileValueAttribute attr = null; if (ProfileValueAttribute.IsProfileKey(field, out attr)) { object thisValue = field.GetValue(this); object defValue = field.GetValue(profile); //Debug.Assert(defValue == null); if (defValue != null && thisValue == null) { field.SetValue(this, defValue); } } } // PRESETS SECTION for (int i = 0; i < 3; i++) { if (i >= profile.Presets.Count) { break; } if (i >= _Presets.Count) { ProfilePreset preset = new ProfilePreset(); _Presets.Add(preset); } bool bDefPreset = (_Presets[i] == profile.Presets[i]); type = typeof(ProfilePreset); foreach (FieldInfo field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { ProfileValueAttribute attr = null; if (ProfileValueAttribute.IsProfileKey(field, out attr)) { object thisValue = field.GetValue(_Presets[i]); object defValue = field.GetValue(profile.Presets[i]); //Debug.Assert(defValue == null); if (defValue != null && thisValue == null) { field.SetValue(_Presets[i], defValue); } } } } // KEYS SECTION ProfileKeys defaultKeys = profile.Keys; bool bDefProfile = (profile.Keys == defaultKeys); type = typeof(ProfileKeys); foreach (FieldInfo field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { ProfileValueAttribute attr = null; if (ProfileValueAttribute.IsProfileKey(field, out attr)) { object thisValue = field.GetValue(Keys); object defValue = field.GetValue(defaultKeys); //Debug.Assert(defValue == null); if (defValue != null && thisValue == null) { field.SetValue(Keys, defValue); } } } }