Beispiel #1
0
        public SubKeyInfo GetSubKeyInfosWithNoValue()
        {
            SubKeyInfo info = new SubKeyInfo();

            ReadRegTree(ref info);

            if (info != null)
            {
                info.ClearValuePair();
            }
            return(info);
        }
Beispiel #2
0
 public bool WriteRegTree(SubKeyInfo valueInfo)
 {
     if (!validate())
     {
         return(false);
     }
     if (getRootNode() == null)
     {
         return(false);
     }
     handleRegTree(getRootNode(), entryKey, true, valueInfo, null);
     return(true);
 }
Beispiel #3
0
        public bool ExistRegTree()
        {
            if (!validate())
            {
                return(false);
            }
            if (getRootNode() == null)
            {
                return(false);
            }
            SubKeyInfo info = new SubKeyInfo();

            return(ReadRegTree(ref info));
        }
Beispiel #4
0
 public bool ReadRegTree(ref SubKeyInfo valueInfo)
 {
     if (!validate())
     {
         return(false);
     }
     if (getRootNode() == null)
     {
         return(false);
     }
     handleRegTree(getRootNode(), entryKey, false, null, valueInfo);
     if (valueInfo.GetInnerInfoCount() == 0)
     {
         valueInfo = null;
         return(false);
     }
     else
     {
         return(true);
     }
 }
Beispiel #5
0
        private void handleRegTree(XmlNode rootNode, RegistryKey currentKey, bool writeOrRead, SubKeyInfo writeValueInfo, SubKeyInfo readValueInfo)
        {
            SubKeyInfo.InnerInfo info = null;
            for (int i = 0; i < rootNode.ChildNodes.Count; i++)
            {
                XmlNode tmpNode = rootNode.ChildNodes.Item(i);
                if (tmpNode.Name == "ValuePair")
                {
                    string key   = "";
                    string value = "";
                    bool   read  = true;

                    for (int j = 0; j < tmpNode.Attributes.Count; j++)
                    {
                        XmlAttribute attr = tmpNode.Attributes[j];
                        if (attr.Name == "Key")
                        {
                            key = attr.Value;
                        }
                        else if (attr.Name == "Value")
                        {
                            value = attr.Value;
                        }
                        else if (attr.Name == "Read")
                        {
                            if (int.Parse(attr.Value) == 0)
                            {
                                read = false;
                            }
                        }
                    }

                    if (isCreateRegTree)
                    {
                        if (currentKey.GetValue(key, null) == null)
                        {
                            currentKey.SetValue(key, value);
                        }
                    }
                    else
                    {
                        if (writeOrRead)
                        {
                            if (currentKey.GetValue(key, null) != null)
                            {
                                if (writeValueInfo != null)
                                {
                                    SubKeyInfo.InnerInfo innerInfo = writeValueInfo.GetInnerInfoByPath(currentKey.Name);
                                    if (innerInfo != null)
                                    {
                                        if (innerInfo.ValuePairs.ContainsKey(key))
                                        {
                                            currentKey.SetValue(key, innerInfo.ValuePairs[key]);
                                        }
                                    }
                                }
                                else
                                {
                                    currentKey.SetValue(key, value);
                                }
                            }
                        }
                        else
                        {
                            if (read && currentKey.GetValue(key, null) != null)
                            {
                                if (info == null)
                                {
                                    info            = new SubKeyInfo.InnerInfo();
                                    info.SubKeyPath = currentKey.Name;
                                    info.SubKeyName = currentKey.Name.Substring(currentKey.Name.LastIndexOf('\\') + 1);
                                }
                                info.AddValuePair(key, currentKey.GetValue(key).ToString());
                            }
                        }
                    }
                }
                else if (tmpNode.Name == "SubKey")
                {
                    string path     = "";
                    int    loopTime = 1;
                    for (int j = 0; j < tmpNode.Attributes.Count; j++)
                    {
                        XmlAttribute attr = tmpNode.Attributes[j];
                        if (attr.Name == "Name")
                        {
                            path = attr.Value;
                        }
                        else if (attr.Name == "LoopTime")
                        {
                            if (int.TryParse(attr.Value, out loopTime) && loopTime <= 0)
                            {
                                loopTime = 1;
                            }
                        }
                    }

                    if (isCreateRegTree)
                    {
                        if (loopTime == 1)
                        {
                            handleRegTree(tmpNode, currentKey.CreateSubKey(path), writeOrRead, writeValueInfo, readValueInfo);
                        }
                        else
                        {
                            for (int k = 0; k < loopTime; k++)
                            {
                                handleRegTree(tmpNode, currentKey.CreateSubKey(path + k.ToString()), writeOrRead, writeValueInfo, readValueInfo);
                            }
                        }
                    }
                    else
                    {
                        if (loopTime == 1)
                        {
                            if (containsSubKey(currentKey, path))
                            {
                                handleRegTree(tmpNode, currentKey.OpenSubKey(path, true), writeOrRead, writeValueInfo, readValueInfo);
                            }
                        }
                        else
                        {
                            for (int k = 0; k < loopTime; k++)
                            {
                                if (containsSubKey(currentKey, path + k.ToString()))
                                {
                                    handleRegTree(tmpNode, currentKey.OpenSubKey(path + k.ToString(), true), writeOrRead, writeValueInfo, readValueInfo);
                                }
                            }
                        }
                    }
                }
            }
            if (info != null && readValueInfo != null)
            {
                readValueInfo.AddInnerInfo(info);
            }
        }