Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        protected void Delete(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (CanWrite)
            {
                using (var _registryKey = RegistryNodeHelpers.GetRegistryKey(_nodePathInfo))
                {
                    _registryKey.DeleteValue(name, false);
                }
            }
            else if (!IsDeleted)
            {
                if (!_innerRepository.ContainsKey(name))
                {
                    _innerRepository[name].SetDeleted();
                    return;
                }

                _innerRepository.Add(name, new RegistryNameValuePair(name, null));
            }
        }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pathProvider"></param>
 /// <returns></returns>
 public static RegistryKey GetRegistryKey(IRegistryPathInfo pathProvider)
 {
     using (var _registryKey = RegistryNodeHelpers.GetRegistryKey(pathProvider.RootType))
     {
         return(_registryKey.CreateSubKey(pathProvider.NodeName, RegistryKeyPermissionCheck.ReadWriteSubTree));
     }
 }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="valueType"></param>
        protected void SetValue(string name, object value, RegistryValueKind valueType = RegistryValueKind.String)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (!IsDeleted && !_childNodeName.IsCompiled)
            {
                var _stackFrame   = StackTraceHelpers.GetStackFrameByIndex(1);
                var _propertyName = _stackFrame.Method.Name.Replace("get_", string.Empty).Replace("set_", string.Empty);

                _childNodeName.Replace(_propertyName, value);

                if (!_childNodeName.IsCompiled)
                {
                    _innerRepository.Add(name, new RegistryNameValuePair(name, value, valueType));
                    return;
                }
                else
                {
                    _nodePathInfo = RegistryNodePath.Parse(_nodePathInfo.RootType, _childNodeName);

                    using (var _registryKey = RegistryNodeHelpers.GetRegistryKey(_nodePathInfo))
                    {
                        if (0 < _innerRepository.Count)
                        {
                            foreach (var _value in _innerRepository.Values)
                            {
                                if (!_value.IsDeleted)
                                {
                                    _registryKey.SetValue(_value.Name, _value.Value, _value.ValueType);
                                    continue;
                                }

                                _registryKey.DeleteValue(_value.Name, false);
                            }

                            _innerRepository.Clear();
                        }
                    }
                }
            }

            if (CanWrite)
            {
                using (var _registryKey = RegistryNodeHelpers.GetRegistryKey(_nodePathInfo))
                {
                    if (null == value)
                    {
                        _registryKey.DeleteValue(name, false);
                        return;
                    }

                    _registryKey.SetValue(name, value);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        ///
        /// </summary>
        public RegistryEntry()
        {
            _nodePathInfo = RegistryNodeHelpers.ExtractRegistryPathProvider(this);

            if (null == _nodePathInfo)
            {
                throw new ArgumentNullException("The definition of registry node could not be found.");
            }

            _childNodeName = new RegistryNodeName(_nodePathInfo.NodeName);
        }
Esempio n. 5
0
        /// <summary>
        ///
        /// </summary>
        public virtual void Delete()
        {
            if (CanWrite)
            {
                using (var _registryKey = RegistryNodeHelpers.GetRegistryKey(_nodePathInfo.RootType))
                {
                    _registryKey.DeleteSubKeyTree(_nodePathInfo.NodeName, false);
                }

                SetDeleted();
            }
        }
Esempio n. 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nodeName"></param>
        /// <returns></returns>
        public static IRegistryPathInfo Parse(string nodeName)
        {
            if (string.IsNullOrEmpty(nodeName))
            {
                throw new ArgumentNullException("nodeName");
            }

            var _split    = nodeName.Split('\\');
            var _rootNode = _split.GetValueOrDefault(0, string.Empty);

            if (string.IsNullOrEmpty(_rootNode))
            {
                throw new ArgumentNullException("A root node cannot be empty.");
            }

            var _childNode = nodeName.Substring(_rootNode.Length, nodeName.Length - _rootNode.Length).TrimStart('\\');

            if (_rootNode.ToUpper().Equals(RegistryNodeHelpers.GetRegistryNodeName(RegistryRootType.CLASSES_ROOT)))
            {
                return(new RegistryNodePath(RegistryRootType.CLASSES_ROOT, _childNode));
            }

            else if (_rootNode.ToUpper().Equals(RegistryNodeHelpers.GetRegistryNodeName(RegistryRootType.CURRENT_USER)))
            {
                return(new RegistryNodePath(RegistryRootType.CURRENT_USER, _childNode));
            }

            else if (_rootNode.ToUpper().Equals(RegistryNodeHelpers.GetRegistryNodeName(RegistryRootType.LOCAL_MACHINE)))
            {
                return(new RegistryNodePath(RegistryRootType.LOCAL_MACHINE, _childNode));
            }

            else if (_rootNode.ToUpper().Equals(RegistryNodeHelpers.GetRegistryNodeName(RegistryRootType.USERS)))
            {
                return(new RegistryNodePath(RegistryRootType.USERS, _childNode));
            }

            else if (_rootNode.ToUpper().Equals(RegistryNodeHelpers.GetRegistryNodeName(RegistryRootType.CURRENT_CONFIG)))
            {
                return(new RegistryNodePath(RegistryRootType.CURRENT_CONFIG, _childNode));
            }

            throw new InvalidOperationException(string.Format("The '{0}' node name is invalid.", nodeName));
        }
Esempio n. 7
0
        /// <summary>
        ///
        /// </summary>
        protected internal IRegistryPathInfo[] GetChildNodePaths()
        {
            if (CanRead)
            {
                if (null == _childNodePaths || IsDirty)
                {
                    using (var _registryKey = RegistryNodeHelpers.GetRegistryKey(_nodePathInfo))
                    {
                        _childNodePaths = _registryKey.GetSubKeyNames().Select(n => RegistryNodePath.Combine(_nodePathInfo, n)).ToArray();
                    }

                    _isDirty = false;
                }

                return(_childNodePaths);
            }

            return(new IRegistryPathInfo[0]);
        }
Esempio n. 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        protected object GetValue(string name, object defaultValue)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (CanRead)
            {
                using (var _registryKey = RegistryNodeHelpers.GetRegistryKey(_nodePathInfo))
                {
                    return(_registryKey.GetValue(name, defaultValue));
                }
            }
            else if (!IsDeleted)
            {
                return(_innerRepository.ContainsKey(name)
                    ? _innerRepository[name].Value : defaultValue);
            }

            return(null);
        }