Exemplo n.º 1
0
 public RegEdit(HKEY hkey, string address)
 {
     HKEY      = hkey;
     Address   = address;
     _regkey   = new RegKey();
     _regvalue = new RegValue();
 }
Exemplo n.º 2
0
        private IRegKey GetExistingRegistryKey(IRegKey regKey, string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(regKey);
            }

            var pos = path.IndexOf('\\');

            if (pos == -1)
            {
                var child = regKey.GetSubKey(path);
                if (child != null)
                {
                    return(child);
                }

                return(null);
            }
            else
            {
                var child = regKey.GetSubKey(path.Substring(0, pos));
                if (child == null)
                {
                    return(null);
                }

                return(this.GetExistingRegistryKey(child, path.Substring(pos + 1)));
            }
        }
Exemplo n.º 3
0
        private static void RemoveRecurse(IRegKey foundKey)
        {
            foreach (var subKeyName in foundKey.Keys.Select(k => k.Name).ToArray())
            {
                using var subKey = foundKey.GetSubKey(subKeyName);
                RemoveRecurse(subKey);
            }

            // remove all values
            foreach (var value in foundKey.Values.ToArray())
            {
                foundKey.RemoveValue(value.Name);
            }

            foundKey.Parent.RemoveSubKey(foundKey.Name);
        }
Exemplo n.º 4
0
 public RegEdit()
 {
     _regkey   = new RegKey();
     _regvalue = new RegValue();
 }
Exemplo n.º 5
0
        private void CommitEntries(IRegKey rootKey, IEnumerable <RegistryEntry> entries)
        {
            foreach (var entry in entries)
            {
                var actualKey = RegistryPathConverter.ToMsixRegistryPath(entry);

                if (entry.Name != null && entry.Value == null)
                {
                    var lastUnit = actualKey.Substring(0, actualKey.LastIndexOf('\\'));
                    var parent   = this.GetExistingRegistryKey(rootKey, lastUnit);
                    if (parent == null)
                    {
                        // don't create a key if we are just about to remove the value...
                        continue;
                    }
                }

                var key = this.GetOrCreateRegistryKey(rootKey, actualKey);

                if (entry.Name != null || entry.Value != null)
                {
                    if (!string.IsNullOrEmpty(entry.Name))
                    {
                        if (entry.Value == null)
                        {
                            key.RemoveValue(entry.Name);
                        }
                        else
                        {
                            switch (entry.Type)
                            {
                            case ValueType.Default:
                                break;

                            case ValueType.String:
                                key.SetValue(entry.Name, RegistryValueConverter.ToMsixFormat((string)entry.Value));
                                break;

                            case ValueType.DWord:
                                var val = (long)Convert.ChangeType(entry.Value, typeof(long));
                                if (val > int.MaxValue)
                                {
                                    key.SetValue(entry.Name, val);
                                }
                                else
                                {
                                    key.SetValue(entry.Name, (int)val);
                                }

                                break;

                            case ValueType.QWord:
                                key.SetValue(entry.Name, (long)Convert.ChangeType(entry.Value, typeof(long)));
                                break;

                            case ValueType.Multi:
                                key.SetValue(entry.Name, RegistryValueConverter.ToMsixFormat((string[])entry.Value));
                                break;

                            case ValueType.Expandable:
                                key.SetValue(entry.Name, RegistryValueConverter.ToMsixFormat((string)entry.Value));
                                break;

                            case ValueType.Binary:
                                key.SetValue(entry.Name, (byte[])entry.Value);
                                break;

                            case ValueType.DWordBigEndian:
                                key.SetValue(entry.Name, (int)Convert.ChangeType(entry.Value, typeof(int)));
                                break;
                            }
                        }
                    }
                    else if (entry.Value is string sourceStringValue)
                    {
                        key.SetValue(string.Empty, sourceStringValue);
                    }
                }
            }
        }