コード例 #1
0
        public void LoadStereoState()
        {
            try
            {
                XmlTextReader reader = new XmlTextReader(GetConfigFilename());

                while (reader.Read())
                {
                    if (reader.NodeType != XmlNodeType.Element)
                    {
                        continue;
                    }

                    ProfileValueAttribute attr  = null;
                    FieldInfo             field = GetFieldInfo(reader.Name, typeof(StereoSettings), out attr);
                    if (field == null)
                    {
                        continue;
                    }
                    reader.MoveToAttribute(0);
                    field.SetValue(StereoSettings,
                                   StringToValue(reader.Value, field.FieldType));
                }

                reader.Close();
            }
            catch (Exception ex)
            {
                Debug.WriteLine("LoadStereoState: " + ex.Message);
            }
        }
コード例 #2
0
        private void ReadProfile(Profile CurrentProfile, XmlReader reader)
        {
            while (reader.Read())
            {
                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                ProfileValueAttribute attr  = null;
                FieldInfo             field = GetFieldInfo(reader.Name, typeof(Profile), out attr);
                if (field == null)
                {
                    switch (reader.Name)
                    {
                    case "Keys":
                        ReadKeys(CurrentProfile.Keys, reader.ReadSubtree());
                        break;

                    case "Presets":
                        ReadPresets(CurrentProfile.Presets, reader.ReadSubtree());
                        break;

                    case "File":
                        var rec = new FileData(reader.GetAttribute("Name"), reader.GetAttribute("CmdLine"));
                        CurrentProfile.Files.Add(rec);
                        break;
                    }
                    continue;
                }
                reader.MoveToAttribute(0);
                field.SetValue(CurrentProfile,
                               StringToValue(reader.Value, field.FieldType));
            }
        }
コード例 #3
0
 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);
 }
コード例 #4
0
ファイル: ProfileValueAttribute.cs プロジェクト: bo3b/iZ3D
 public static bool IsProfileKey(FieldInfo field, out ProfileValueAttribute attr)
 {
     foreach (object attribute in field.GetCustomAttributes(false))
     {
         attr = attribute as ProfileValueAttribute;
         if (attr != null)
         {
             return(true);
         }
     }
     attr = null;
     return(false);
 }
コード例 #5
0
 private void ReadPreset(ProfilePreset preset, XmlReader reader)
 {
     reader.Skip();
     while (reader.Read())
     {
         if (reader.NodeType != XmlNodeType.Element)
         {
             continue;
         }
         ProfileValueAttribute attr  = null;
         FieldInfo             field = GetFieldInfo(reader.Name, typeof(ProfilePreset), out attr);
         Debug.Assert(field != null);
         if (field == null)
         {
             continue;
         }
         reader.MoveToAttribute(0);
         field.SetValue(preset,
                        StringToValue(reader.Value, field.FieldType));
     }
 }
コード例 #6
0
        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);
                    }
                }
            }
        }
コード例 #7
0
        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);
                    }
                }
            }
        }
コード例 #8
0
        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);
        }
コード例 #9
0
ファイル: Profile.cs プロジェクト: bo3b/iZ3D
        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);
                    }
                }
            }
        }