Ejemplo n.º 1
0
        internal NotifyKind CheckChangedSubKeys(ref RegistryChangeInfo changeInfo)
        {
            RegistryKey key = _rootKey.OpenSubKey(_registryPath);

            if (null != key)
            {
                string[] subKeyNames = key.GetSubKeyNames();
                int      subKeyCount = key.SubKeyCount;
                if (subKeyCount != _subKeyCount)
                {
                    int oldSubKeyCount = _subKeyCount;
                    _subKeyCount = subKeyCount;
                    key.Close();
                    _parent.RaisePropertyChanged(this);

                    NotifyKind returnKind = NotifyKind.Nothing;
                    if ((subKeyCount > oldSubKeyCount) && (!_parent.FirstRun))
                    {
                        AddinSubkeysIncrementInfo newKeyInfo = new AddinSubkeysIncrementInfo();
                        newKeyInfo.RootKey = _rootKey;
                        newKeyInfo.KeyPath = _registryPath;
                        newKeyInfo.KeyName = GetNewValueName(subKeyNames, _subKeyNames);
                        changeInfo         = newKeyInfo;
                        _subKeyNames       = subKeyNames;
                        returnKind         = NotifyKind.AddinSubKeysIncrement;
                    }
                    else if (!_parent.FirstRun)
                    {
                        AddinSubkeysDecrementInfo deleteKeyInfo = new AddinSubkeysDecrementInfo();
                        deleteKeyInfo.RootKey = _rootKey;
                        deleteKeyInfo.KeyPath = _registryPath;
                        deleteKeyInfo.KeyName = GetDeletedValueName(subKeyNames, _subKeyNames);
                        changeInfo            = deleteKeyInfo;
                        _subKeyNames          = subKeyNames;
                        returnKind            = NotifyKind.AddinSubKeysDecrement;
                    }
                    return(returnKind);
                }
                else
                {
                    NotifyKind returnKind = NotifyKind.Nothing;
                    foreach (string item in subKeyNames)
                    {
                        if (!Contains(_subKeyNames, item))
                        {
                            _parent.RaisePropertyChanged(this);
                            if (!_parent.FirstRun)
                            {
                                AddinSubkeyNameChangedInfo nameInfo = new AddinSubkeyNameChangedInfo();
                                nameInfo.RootKey    = _rootKey;
                                nameInfo.KeyPath    = _registryPath;
                                nameInfo.OldKeyName = item;
                                nameInfo.NewKeyName = GetChangedValueName(subKeyNames, _subKeyNames);
                                changeInfo          = nameInfo;
                                _subKeyNames        = subKeyNames;
                                returnKind          = NotifyKind.AddinSubKeyNameChanged;
                            }
                            break;
                        }
                    }
                    _subKeyNames = subKeyNames;
                    key.Close();
                    return(returnKind);
                }
            }
            return(NotifyKind.Nothing);
        }
Ejemplo n.º 2
0
        internal NotifyKind CheckChangedValues(ref RegistryChangeInfo changeInfos)
        {
            try
            {
                bool openModeWrite = true;
                if ((_parent.RootKey == Registry.LocalMachine) && (_root.ReadOnlyModeForMachineKeys))
                {
                    openModeWrite = false;
                }

                RegistryKey key = _parent.RootKey.OpenSubKey(_registryPath, openModeWrite);
                if (null != key)
                {
                    string[] valueNames = key.GetValueNames();
                    int      valueCount = key.ValueCount;
                    if (valueCount != _valueCount)
                    {
                        _root.RaisePropertyChanged(Parent);
                        NotifyKind returnKind;
                        if (valueCount > _valueCount)
                        {
                            AddinValuesIncrementInfo incrementInfo = new AddinValuesIncrementInfo();
                            incrementInfo.RootKey   = _parent.RootKey;
                            incrementInfo.KeyPath   = _registryPath;
                            incrementInfo.KeyName   = _parent.Name;
                            incrementInfo.ValueName = GetNewValueName(valueNames, _valueNames);
                            _valueNames             = valueNames;
                            _valueKinds.Add(incrementInfo.ValueName, key.GetValueKind(incrementInfo.ValueName));
                            _values.Add(incrementInfo.ValueName, key.GetValue(incrementInfo.ValueName));
                            changeInfos = incrementInfo;
                            returnKind  = NotifyKind.AddinValuesIncrement;
                        }
                        else
                        {
                            AddinValuesDecrementInfo decrementInfo = new AddinValuesDecrementInfo();
                            decrementInfo.RootKey   = _parent.RootKey;
                            decrementInfo.KeyPath   = _registryPath;
                            decrementInfo.KeyName   = _parent.Name;
                            decrementInfo.ValueName = GetDeletedValueName(valueNames, _valueNames);
                            _valueKinds.Remove(decrementInfo.ValueName);
                            _values.Remove(decrementInfo.ValueName);
                            changeInfos = decrementInfo;
                            returnKind  = NotifyKind.AddinValuesDecrement;
                        }
                        _valueNames = valueNames;
                        _valueCount = valueCount;
                        key.Close();
                        return(returnKind);
                    }
                    else
                    {
                        foreach (string item in valueNames)
                        {
                            // name changed
                            if (!AddinsKey.Contains(_valueNames, item))
                            {
                                _root.RaisePropertyChanged(_parent);

                                key.Close();
                                AddinValueNameChangedInfo nameInfo = new AddinValueNameChangedInfo();
                                nameInfo.RootKey      = _parent.RootKey;
                                nameInfo.KeyPath      = _registryPath;
                                nameInfo.KeyName      = _parent.Name;
                                nameInfo.NewValueName = item;
                                nameInfo.OldValueName = GetChangedValueName(valueNames, _valueNames);
                                _valueNames           = valueNames;
                                RegistryValueKind refreshKind;
                                object            refreshValue = null;
                                _valueKinds.TryGetValue(nameInfo.OldValueName, out refreshKind);
                                _values.TryGetValue(nameInfo.OldValueName, out refreshValue);
                                _valueKinds.Remove(nameInfo.OldValueName);
                                _values.Remove(nameInfo.OldValueName);
                                _valueKinds.Add(nameInfo.NewValueName, refreshKind);
                                _values.Add(nameInfo.NewValueName, refreshValue);
                                changeInfos = nameInfo;

                                return(NotifyKind.AddinValueNameIsChanged);
                            }

                            // value changed
                            object value    = key.GetValue(item, null);
                            object oldValue = null;
                            _values.TryGetValue(item, out oldValue);
                            if (!AddinsKey.IsEqual(value, oldValue))
                            {
                                if ((_root.RestoreLastLoadBehavior) && (item == "LoadBehavior") && (!_root.FirstRun) && (true == openModeWrite) && (true == IsRestoreSituation(oldValue, value)))
                                {
                                    key.SetValue("LoadBehavior", oldValue);
                                    key.Close();
                                    AddinValueValueRestoredInfo restoredInfo = new AddinValueValueRestoredInfo();
                                    restoredInfo.RootKey       = _parent.RootKey;
                                    restoredInfo.KeyPath       = _registryPath;
                                    restoredInfo.KeyName       = _parent.Name;
                                    restoredInfo.ValueName     = item;
                                    restoredInfo.OldValue      = value;
                                    restoredInfo.RestoredValue = oldValue;
                                    changeInfos = restoredInfo;
                                    return(NotifyKind.AddinLoadBehaviorRestored);
                                }
                                else
                                {
                                    _root.RaisePropertyChanged(_parent);
                                    _values[item] = value;
                                    key.Close();
                                    AddinValueValueChangedInfo valueInfo = new AddinValueValueChangedInfo();
                                    valueInfo.RootKey   = _parent.RootKey;
                                    valueInfo.KeyPath   = _registryPath;
                                    valueInfo.KeyName   = _parent.Name;
                                    valueInfo.ValueName = item;
                                    valueInfo.NewValue  = value;
                                    valueInfo.OldValue  = oldValue;
                                    changeInfos         = valueInfo;
                                    return(NotifyKind.AddinValueIsChanged);
                                }
                            }

                            // kind changed
                            RegistryValueKind kind = key.GetValueKind(item);
                            RegistryValueKind oldkind;
                            _valueKinds.TryGetValue(item, out oldkind);
                            if (!AddinsKey.IsEqual(kind, oldkind))
                            {
                                _root.RaisePropertyChanged(_parent);
                                _valueKinds[item] = kind;
                                key.Close();

                                AddinValueKindChangedInfo kindInfo = new AddinValueKindChangedInfo();
                                kindInfo.RootKey      = _parent.RootKey;
                                kindInfo.KeyPath      = _registryPath;
                                kindInfo.KeyName      = _parent.Name;
                                kindInfo.ValueName    = item;
                                kindInfo.NewValueKind = kind;
                                kindInfo.OldValueKind = oldkind;
                                changeInfos           = kindInfo;
                                return(NotifyKind.AddinValueKindIsChanged);
                            }
                        }
                        key.Close();
                    }
                }
                return(NotifyKind.Nothing);
            }
            catch (System.Security.SecurityException exception)
            {
                throw new Exception("", exception);
            }
        }
Ejemplo n.º 3
0
        internal NotifyKind CheckChangedValueCount(ref RegistryChangeInfo changeInfos)
        {
            RegistryKey key = _rootKey.OpenSubKey(_registryPath);

            if (null == key)
            {
                bool found = false;
                foreach (string keyExists in _keyExists)
                {
                    if (keyExists == (RootKey.ToString() + "\\" + _registryPath))
                    {
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    _parent.RaisePropertyChanged(this);
                    _keyExists.Remove(RootKey.ToString() + "\\" + _registryPath);
                }
            }
            else
            {
                bool found = false;
                foreach (string keyExists in _keyExists)
                {
                    if (keyExists == (RootKey.ToString() + "\\" + _registryPath))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    _keyExists.Add(RootKey.ToString() + "\\" + _registryPath);
                }

                string[] valueNames = key.GetValueNames();
                int      valueCount = key.ValueCount;
                if (valueCount != _lastValueCount)
                {
                    _parent.RaisePropertyChanged(this);

                    NotifyKind returnKind;
                    if ((valueCount > _lastValueCount) && (!_parent.FirstRun))
                    {
                        NewDeactivatedElementInfo newElementInfo = new NewDeactivatedElementInfo();
                        newElementInfo.RootKey = _rootKey;
                        newElementInfo.KeyPath = _registryPath;

                        string newValueName = GetNewValueName(valueNames, _valueNames);
                        object regValue     = key.GetValue(newValueName, null);
                        regValue            = DisabledValue.ConvertDisabledItemValueName(regValue, newValueName);
                        newElementInfo.Name = regValue as string;
                        newElementInfo.OfficeProductVersion = OfficeProductVersion;
                        changeInfos = newElementInfo;
                        _valueNames = valueNames;
                        returnKind  = NotifyKind.DisabledItemNew;
                    }
                    else if (!_parent.FirstRun)
                    {
                        DeleteDeactivatedElementInfo deleteElementInfo = new DeleteDeactivatedElementInfo();
                        deleteElementInfo.RootKey = _rootKey;
                        deleteElementInfo.KeyPath = _registryPath;
                        deleteElementInfo.Name    = GetDeletedValueName(valueNames, _valueNames);

                        string convertedName = null;
                        _convertedNames.TryGetValue(deleteElementInfo.Name, out convertedName);
                        _convertedNames.Remove(deleteElementInfo.Name);
                        deleteElementInfo.Name = convertedName;

                        deleteElementInfo.OfficeProductVersion = OfficeProductVersion;
                        changeInfos = deleteElementInfo;
                        _valueNames = valueNames;
                        returnKind  = NotifyKind.DisabledItemDelete;
                    }
                    else
                    {
                        foreach (string name in valueNames)
                        {
                            string existingName = null;
                            _convertedNames.TryGetValue(name, out existingName);
                            if (null == existingName)
                            {
                                object regValue = key.GetValue(name, null);
                                regValue = DisabledValue.ConvertDisabledItemValueName(regValue, name);
                                _convertedNames.Add(name, regValue as string);
                            }
                        }
                        returnKind = NotifyKind.Nothing;
                    }


                    _lastValueCount = valueCount;
                    return(returnKind);
                }
                _valueNames = valueNames;
                key.Close();
            }
            return(NotifyKind.Nothing);
        }