private void SelectKey(UtilsRegistryKey targetKey) { if (null == targetKey) throw new ArgumentNullException("targetKey"); pictureBoxNoResult.Visible = false; TreeNode rootNode = GetRootNode(targetKey.Root.IsLocalMachine, targetKey.Root.IsWow); if (!rootNode.IsExpanded) rootNode.Expand(); TreeNode currentNode = rootNode; string[] array = targetKey.Path.Substring(targetKey.Root.Path.Length+1).Split(new string[] { "\\" }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in array) { if (!currentNode.IsExpanded) currentNode.Expand(); foreach (TreeNode node in currentNode.Nodes) { if (node.Text == item) { currentNode = node; continue; } } } treeViewRegistry.SelectedNode = currentNode; }
private UtilsRegistryKey SearchTopKey(string expression, UtilsRegistryKey topKey) { return SearchKey(expression, topKey); }
private UtilsRegistryKey SearchTopKey(string expression, UtilsRegistryKey topKey, UtilsRegistryKey selectedSubKey) { if (selectedSubKey.Path == topKey.Path) { return SearchKey(expression, topKey); } else { UtilsRegistryKey parent = CreateParentRegistryKey(selectedSubKey); bool ignore = true; foreach (var item in parent.Keys) { if (ignore == true) { if (item.Path == selectedSubKey.Path) { ignore = false; UtilsRegistryKey res = SearchKey(expression, item); if (null != res) return res; } } else { UtilsRegistryKey res = SearchKey(expression, item); if (null != res) return res; } } return null; } }
private void toolStripCreateStringEntry_Click(object sender, EventArgs e) { try { string fullPath = GetFullNodePath(treeViewRegistry.SelectedNode); UtilsRegistryKey key = new UtilsRegistryKey(GetRegistry(treeViewRegistry.SelectedNode), fullPath); UtilsRegistryEntry entry = key.Keys.Add(RegistryValueKind.String, ""); dataGridViewRegistry.Rows.Add(); DataGridViewRow row = dataGridViewRegistry.Rows[dataGridViewRegistry.Rows.Count - 1]; Image typeImage = GetValueKindImage(entry.ValueKind); row.Cells[0].Value = typeImage; row.Cells[1].Value = entry.Name; row.Cells[2].Value = entry.ValueKind.ToString(); row.Cells[3].Value = entry.GetValue(); row.Tag = entry; } catch (Exception exception) { Forms.ErrorForm.ShowError(exception,ErrorCategory.NonCritical, Host.CurrentLanguageID); } }
private UtilsRegistryKey SearchKey(string expression, UtilsRegistryKey key) { int position = key.Name.IndexOf(expression, StringComparison.InvariantCultureIgnoreCase); if (position > -1) return key; foreach (UtilsRegistryEntry item in key.Entries) { int pos1 = item.Name.IndexOf(expression, StringComparison.InvariantCultureIgnoreCase); if (pos1 > -1) return key; string valueString = item.Value.ToString(); int pos2 = valueString.IndexOf(expression, StringComparison.InvariantCultureIgnoreCase); if (pos2 > -1) return key; } foreach (UtilsRegistryKey item in key.Keys) { UtilsRegistryKey resKey = SearchKey(expression, item); if (null != resKey) return resKey; } return null; }
internal UtilsRegistryEntry(UtilsRegistryKey parent, string valueName) { _parent = parent; _valueName = valueName; _type = UtilsRegistryEntryType.Normal; }
internal UtilsRegistryEntry(UtilsRegistryKey parent, string valueName) { _parent = parent; _valueName = valueName; _type = UtilsRegistryEntryType.Normal; }
private void treeViewRegistry_BeforeExpand(object sender, TreeViewCancelEventArgs e) { try { if ((e.Node.Nodes.Count > 0) && ("#stub" == e.Node.Nodes[0].Text)) { e.Node.Nodes.Clear(); string fullPath = GetFullNodePath(e.Node); UtilsRegistryKey key = new UtilsRegistryKey(GetRegistry(e.Node), fullPath); ShowRegNodeChilds(key, e.Node); } else if (null != e.Node.Tag) { e.Node.Nodes.Clear(); string fullPath = GetFullNodePath(e.Node); UtilsRegistryKey key = new UtilsRegistryKey(GetRegistry(e.Node), fullPath); ShowRegNodeChilds(key, e.Node); } } catch (Exception exception) { Forms.ErrorForm.ShowError(exception,ErrorCategory.NonCritical, Host.CurrentLanguageID); } }
private UtilsRegistryKey CreateParentRegistryKey(UtilsRegistryKey key) { int position = key.Path.LastIndexOf("\\"); string path = key.Path.Substring(0, position); return new UtilsRegistryKey(key.Root, path); }
private void treeViewRegistry_AfterLabelEdit(object sender, NodeLabelEditEventArgs e) { try { string fullPath = GetFullNodePath(treeViewRegistry.SelectedNode); UtilsRegistryKey key = new UtilsRegistryKey(GetRegistry(treeViewRegistry.SelectedNode), fullPath); key.Name = e.Label; treeViewRegistry.LabelEdit = false; } catch (Exception exception) { Forms.ErrorForm.ShowError(exception,ErrorCategory.NonCritical, Host.CurrentLanguageID); } }
private void treeViewRegistry_AfterSelect(object sender, TreeViewEventArgs e) { try { TreeNode rootNode = GetRootNode(e.Node); UtilsRegistry regRoot = rootNode.Tag as UtilsRegistry; if ((regRoot.HiveKey == Registry.LocalMachine) && (!_userIsAdmin)) treeViewRegistry.ContextMenuStrip = contextMenuStripNoAdmin; else treeViewRegistry.ContextMenuStrip = contextMenuStripKeys; toolStripKeyEdit.Enabled = (treeViewRegistry.SelectedNode != null) && (treeViewRegistry.SelectedNode.Parent != null); toolStripKeyDelete.Enabled = (treeViewRegistry.SelectedNode != null) && (treeViewRegistry.SelectedNode.Parent != null); toolStripKeyExport.Enabled = (treeViewRegistry.SelectedNode != null) && (treeViewRegistry.SelectedNode.Parent != null); dataGridViewRegistry.Rows.Clear(); if (null == e.Node.Tag) { labelCurrentPath.Text = e.Node.Text; return; } string fullNodePath = GetFullNodePath(treeViewRegistry.SelectedNode); UtilsRegistryKey key = new UtilsRegistryKey(GetRegistry(e.Node), fullNodePath); bool foundDefault = false; foreach (UtilsRegistryEntry item in key.Entries) { if (item.Type == UtilsRegistryEntryType.Default) foundDefault = true; string name = item.Name; string valueType = item.ValueKind.ToString(); object value = item.GetValue(); Image typeImage = GetValueKindImage(item.ValueKind); dataGridViewRegistry.Rows.Add(typeImage, name, valueType, value); DataGridViewRow newRow = dataGridViewRegistry.Rows[dataGridViewRegistry.Rows.Count - 1]; newRow.Tag = item; } if (!foundDefault) { UtilsRegistryEntry fakedKey = key.Entries.FakedDefaultKey; string name = fakedKey.Name; string valueType = fakedKey.ValueKind.ToString(); object value = fakedKey.GetValue(Host.CurrentLanguageID); Image typeImage = GetValueKindImage(fakedKey.ValueKind); dataGridViewRegistry.Rows.Insert(0, typeImage, name, valueType, value); DataGridViewRow newRow = dataGridViewRegistry.Rows[0]; newRow.Tag = fakedKey; } labelCurrentPath.Text = (key.Root.IsLocalMachine == true ? "[Local_Machine] " : "[Current_User] ") + key.Path; } catch (Exception exception) { Forms.ErrorForm.ShowError(exception,ErrorCategory.NonCritical, Host.CurrentLanguageID); } }
private void toolStripKeyExport_Click(object sender, EventArgs e) { try { if (null != treeViewRegistry.SelectedNode && (!(treeViewRegistry.SelectedNode.Tag is UtilsRegistry))) { SaveFileDialog dlg = new SaveFileDialog(); dlg.Filter = "*.reg|*.reg"; if (DialogResult.OK == dlg.ShowDialog(this)) { string fullPath = GetFullNodePath(treeViewRegistry.SelectedNode); UtilsRegistry reg = GetRegistry(treeViewRegistry.SelectedNode); UtilsRegistryKey key = new UtilsRegistryKey(reg, fullPath); UtilsRegistryKeyExporter.Export(dlg.FileName, reg.InnerKey.ToString() + "\\" + key.Path); } } } catch (Exception exception) { Forms.ErrorForm.ShowError(exception,ErrorCategory.NonCritical, Host.CurrentLanguageID); } }
private void toolStripKeyDelete_Click(object sender, EventArgs e) { try { if (0 == treeViewRegistry.SelectedNodes.Count) return; string[] fullPathSelectedNodes = GetNodePaths(treeViewRegistry.SelectedNodes); TreeNode parentNode = null; if( (null != treeViewRegistry.SelectedNode.PrevNode) && (treeViewRegistry.SelectedNodes.Count == 1)) parentNode = treeViewRegistry.SelectedNode.PrevNode; else parentNode = treeViewRegistry.SelectedNode.Parent; if (checkBoxDeleteQuestion.Checked) { string nodeNames = GetNodeNames(treeViewRegistry.SelectedNodes); string message = null; string caption = null; if (Host.CurrentLanguageID == 1031) { caption = "Löschen bestätigen"; message = string.Format("Möchten Sie den Schlüssel löschen?{1}{1}{0}", nodeNames, Environment.NewLine); } else { caption = "Confirm"; message = string.Format("Delete?{1}{1}{0}", nodeNames, Environment.NewLine); } DialogResult dr = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.No) return; } UtilsRegistry registryRoot = GetRegistry(treeViewRegistry.SelectedNode); foreach (string fullPath in fullPathSelectedNodes) { UtilsRegistryKey key = new UtilsRegistryKey(registryRoot, fullPath); key.Delete(); } treeViewRegistry.SelectedNode = parentNode; buttonRefresh_Click(this, new EventArgs()); } catch (Exception exception) { Forms.ErrorForm.ShowError(exception,ErrorCategory.NonCritical, Host.CurrentLanguageID); } }
private void toolStripKeyCreate_Click(object sender, EventArgs e) { try { string fullPath = GetFullNodePath(treeViewRegistry.SelectedNode); UtilsRegistryKey key = new UtilsRegistryKey(GetRegistry(treeViewRegistry.SelectedNode), fullPath); key.CreateNewSubKey(); buttonRefresh_Click(this, new EventArgs()); } catch (Exception exception) { Forms.ErrorForm.ShowError(exception,ErrorCategory.NonCritical, Host.CurrentLanguageID); } }
private void ShowRegNode(UtilsRegistryKey key, TreeNode node) { node = node.Nodes.Add(key.Name); node.Tag = true; if(key.Keys.Count > 0) node.Nodes.Add("#stub"); }
private void DoSearch(string expression) { UtilsRegistryKey key = null; UtilsRegistryKey result = null; if (null == treeViewRegistry.SelectedNode) { if (treeViewRegistry.Nodes.Count > 0) treeViewRegistry.SelectedNode = treeViewRegistry.Nodes[0]; else return; } TreeNode targetNode = GetNextPossibleNode(treeViewRegistry.SelectedNode); string fullNodePath = GetFullNodePath(targetNode); key = new UtilsRegistryKey(GetRegistry(targetNode), fullNodePath); result = SearchHive(expression, key.Root, key); if (null != result) SelectKey(result); else { if (key.Root.IsLocalMachine && false == key.Root.IsWow) { // localmachine32 result = SearchHive(expression, _currentUser32, null); if (null != result) { SelectKey(result); return; } result = SearchHive(expression, _localMachine64, null); if (null != result) { SelectKey(result); return; } result = SearchHive(expression, _currentUser64, null); if (null != result) { SelectKey(result); return; } else ShowNoResult(); } else if (key.Root.IsLocalMachine && true == key.Root.IsWow) { // localmachine64 result = SearchHive(expression, _currentUser64, null); if (null != result) { SelectKey(result); return; } result = SearchHive(expression, _localMachine32, null); if (null != result) { SelectKey(result); return; } result = SearchHive(expression, _currentUser32, null); if (null != result) { SelectKey(result); return; } else ShowNoResult(); } else if (false == key.Root.IsLocalMachine && false == key.Root.IsWow) { // currentuser32 result = SearchHive(expression, _localMachine64, null); if (null != result) { SelectKey(result); return; } result = SearchHive(expression, _currentUser64, null); if (null != result) { SelectKey(result); return; } result = SearchHive(expression, _localMachine32, null); if (null != result) { SelectKey(result); return; } else ShowNoResult(); } else { // currentuser64 result = SearchHive(expression, _localMachine32, null); if (null != result) { SelectKey(result); return; } result = SearchHive(expression, _currentUser32, null); if (null != result) { SelectKey(result); return; } result = SearchHive(expression, _localMachine64, null); if (null != result) { SelectKey(result); return; } else ShowNoResult(); } } }
private void ShowRegNodeChilds(UtilsRegistryKey key, TreeNode node) { foreach (UtilsRegistryKey subKey in key.Keys) ShowRegNode(subKey,node); }
private UtilsRegistryKey GetTopParent(UtilsRegistryKey key, List<UtilsRegistryKey> searchList, out int indexPosition) { string search = key.Path; int i = 0; foreach (var item in searchList) { string itemFull = item.Path; if (search.StartsWith(itemFull, StringComparison.InvariantCultureIgnoreCase)) { indexPosition = i; return item; } i++; } throw new ArgumentOutOfRangeException("key"); }
internal UtilsRegistryEntry(UtilsRegistryKey parent, string valueName, UtilsRegistryEntryType type) { _parent = parent; _valueName = valueName; _type = type; }
private UtilsRegistryKey SearchHive(string expression, UtilsRegistry hive, UtilsRegistryKey selectedKeyInHive) { if (null == hive) return null; TreeNode testNode = GetRootNode(hive.IsLocalMachine, hive.IsWow); if(null == testNode) return null; List<UtilsRegistryKey> rootKeys = new List<UtilsRegistryKey>(); foreach (UtilsRegistryKey item in hive.Key.Keys) rootKeys.Add(item); if ((null != selectedKeyInHive && hive.Path.Equals(selectedKeyInHive.Path, StringComparison.InvariantCultureIgnoreCase)) || null == selectedKeyInHive) { // selected key is one the 2 roots or not selected foreach (var item in rootKeys) { UtilsRegistryKey resultKey = SearchTopKey(expression, item); if(null != resultKey) return resultKey; } } else { // selected key is a descendent int topParentIndex = 0; UtilsRegistryKey topParentKey = GetTopParent(selectedKeyInHive, rootKeys, out topParentIndex); // same top key UtilsRegistryKey topKeyResult = SearchTopKey(expression, topParentKey, selectedKeyInHive); if (null != topKeyResult) return topKeyResult; // bottom keys bool ignore = true; foreach (var item in hive.Key.Keys) { if (true == ignore) { if (item.Path == topParentKey.Path) ignore = false; } else { UtilsRegistryKey bottomKeyResult = SearchTopKey(expression, item); if (null != bottomKeyResult) return bottomKeyResult; } } } return null; }
internal UtilsRegistryEntry(UtilsRegistryKey parent, string valueName, UtilsRegistryEntryType type) { _parent = parent; _valueName = valueName; _type = type; }
internal UtilsRegistryEntries(UtilsRegistryKey parent) { _parent = parent; }