Example #1
0
        public void ShowNotification(AddinKey item, NotifyKind notfiyKind, RegistryChangeInfo changeInfo)
        {
            if (_parent.FirstRun)
            {
                return;
            }
            string message = GetMessage(notfiyKind);

            switch (notfiyKind)
            {
            case NotifyKind.AddinLoadBehaviorRestored:
                AddinValueValueRestoredInfo restoredInfo = (AddinValueValueRestoredInfo)changeInfo;
                message = string.Format(message, restoredInfo.RootKey, restoredInfo.KeyPath, restoredInfo.ValueName, restoredInfo.RestoredValue, restoredInfo.OldValue, Environment.NewLine);
                break;

            case NotifyKind.AddinValueNameIsChanged:
                AddinValueNameChangedInfo nameInfo = (AddinValueNameChangedInfo)changeInfo;
                message = string.Format(message, nameInfo.RootKey, nameInfo.KeyPath, nameInfo.OldValueName, nameInfo.NewValueName, Environment.NewLine);
                break;

            case NotifyKind.AddinValueKindIsChanged:
                AddinValueKindChangedInfo kindInfo = (AddinValueKindChangedInfo)changeInfo;
                message = string.Format(message, kindInfo.RootKey, kindInfo.KeyPath, kindInfo.ValueName, kindInfo.OldValueKind, kindInfo.NewValueKind, Environment.NewLine);
                break;

            case NotifyKind.AddinValueIsChanged:
                AddinValueValueChangedInfo valueInfo = (AddinValueValueChangedInfo)changeInfo;
                message = string.Format(message, valueInfo.RootKey, valueInfo.KeyPath, valueInfo.ValueName, valueInfo.OldValue, valueInfo.NewValue, Environment.NewLine);
                break;

            case NotifyKind.AddinValuesIncrement:
                AddinValuesIncrementInfo incrementInfo = (AddinValuesIncrementInfo)changeInfo;
                message = string.Format(message, incrementInfo.RootKey, incrementInfo.KeyPath, incrementInfo.ValueName, Environment.NewLine);
                break;

            case NotifyKind.AddinValuesDecrement:
                AddinValuesDecrementInfo decrementInfo = (AddinValuesDecrementInfo)changeInfo;
                message = string.Format(message, decrementInfo.RootKey, decrementInfo.KeyPath, decrementInfo.ValueName, Environment.NewLine);
                break;

            default:
                throw new ArgumentOutOfRangeException(notfiyKind.ToString() + " is not valid in this context");
            }

            if (_parent.NotifyType == NotificationType.MessageBox)
            {
                MessageBox.Show(message, "NetOffice.DeveloperToolbox", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                _trayIcon.ShowBalloonTip(2000, message, "NetOffice.DeveloperToolbox " + notfiyKind.ToString(), ToolTipIcon.Info);
            }

            if (null != MessageFired)
            {
                MessageFired(message, new EventArgs());
            }
        }
Example #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);
            }
        }
Example #3
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);
            }
        }