// Adds "some" of the nodes to the Tree // May need to be run more then once to process them all. This is because // children can have lower pid's then the parents. (Don't ask me how or why) // private PidList AddBranches(PidList Updates) { PidList Retry = new PidList(); // In some weird instances children // can have a lower pid then the parent // So we have to do retry's Updates.Sort(PidFields.Parent); foreach (Pid p in Updates) { TreeNode tmp = new TreeNode(p.Name); // Create the node tmp.Name = p.Id.ToString(); // Set it's key // Look for its parent process in the tree // TreeNode[] t = PidTree.Nodes.Find(p.Parent.ToString(), true); if (t.Length == 0) // Not found { Retry.Add(new Pid(p.Name, p.Id, p.Parent)); } else // Found { t[0].Nodes.Add(tmp); t[0].Expand(); // Add as a running process // Running.Add(new Pid(p.Name, p.Id, p.Parent)); } } return(Retry); }
public PidList GeneratePidList(PidList Running) { this.Running = Running; this.ReturnPids = new PidList(); CreatePidList(this.LastNode); return(this.ReturnPids); }
// Refresh the tree // private void TreeRefresh(bool FullRefresh) { int KillSwitch = 0; PidList Updates = new PidList(); Updates.GetSystemPids(true); // Load system processes Updates.Remove("idle", PidFields.Name); // Remove the Idles Running.Remove("idle", PidFields.Name); if (FullRefresh) // Clear the running processes { Running.Clear(); // so the Diff will think PidTree.Nodes.Clear(); // everything's new TreeNode Root = new TreeNode("Idle"); // Add Idle process to the tree Root.Name = "0"; PidTree.Nodes.Add(Root); } PidDiff Result = Running.Diff(Updates); // Execute a Diff PruneBranches(Result.Removed); // Kill Removed // Add nodes loop // while (Result.Added.Count != 0 && KillSwitch < 9) { Result.Added = AddBranches(Result.Added); KillSwitch++; } if (FullRefresh) // Collapse the Tree { PidTree.CollapseAll(); TreeNode[] t = PidTree.Nodes.Find("0", true); // Expand Idle t[0].Expand(); PidTree.LastNode = t[0]; txtProcessID.Text = $"Idle (0)"; // Expand Explorer // Pid tmpPid = Running.Find("explorer", PidFields.Name); // Search for explorer if (tmpPid != null) { t = PidTree.Nodes.Find(tmpPid.Id.ToString(), true); // Highlight explorer t[0].Expand(); txtProcessID.Text = $"{tmpPid.Name} ({tmpPid.Id})"; PidTree.SelectedNode = t[0]; PidTree.LastNode = t[0]; t[0].EnsureVisible(); } } txtProcessCount.Text = $"Processes: {Running.Count}"; }
private List <PidList> ParseList(string list) { List <PidList> result = new List <PidList>(); if (list == null) { return(result); } string[] data = list.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string sList in data) { string[] elements = sList.Split(new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries); PidList pidList = null; int[] tElements = new int[2] { -1, 0 }; int idx = 0; foreach (string sElement in elements) { int tmp; if (idx == 0) { pidList = new PidList(sElement); } else if (idx > 0 && idx <= tElements.Length) { if (int.TryParse(sElement, out tmp)) { tElements[idx - 1] = tmp; } if (idx == tElements.Length) { pidList.Data.Add(new Tuple <int, int>(tElements[0], tElements[1])); tElements = new int[2] { -1, 0 }; idx = 0; } } idx++; } if (pidList != null && pidList.Data.Count > 0) { result.Add(pidList); } } return(result); }
// Remove nodes from the tree // TODO: Re-parent orphans // private void PruneBranches(PidList Updates) { Updates.Reverse(); foreach (Pid p in Updates) { TreeNode[] t = PidTree.Nodes.Find(p.Id.ToString(), true); if (t.Length >= 0) { try { t[0].Remove(); } catch { } // May have killed parent fist Running.Remove(p.Id, PidFields.Id); // killing the decedents } } }
private void btnLoadSave_Click(object sender, EventArgs e) { List <PidList> pidList = null; ListBox list = null; TextBox name = null; string config = null; if (tabs.SelectedTab == tabGlobal) { pidList = global; list = listGlobal; name = nameGlobal; config = "ListPidsGlobal"; } else { pidList = local; list = listLocal; name = nameLocal; config = "ListPidsLocal"; } if (saveMode) { if (name.Text.Length == 0) { MessageBox.Show(this, "Set a name for this list.", "User error", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } foreach (char invalid in new char[] { '|', '^' }) { if (name.Text.Contains(invalid)) { MessageBox.Show(this, "Invalid character in list name: " + invalid, "User error", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } } int tmp; if (int.TryParse(name.Text, out tmp)) { MessageBox.Show(this, "List name can't be a number.", "User error", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } bool overwrite = false; foreach (PidList plist in pidList) { if (plist.Name.ToLower() == name.Text.ToLower()) { DialogResult = MessageBox.Show(this, "List with name <" + name.Text + "> already exists, overwrite?", null, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult == DialogResult.No) { return; } else { plist.Data = saveData; overwrite = true; } break; } } if (!overwrite) { PidList newList = new PidList(name.Text); newList.Data = saveData; pidList.Add(newList); } Overseer.Config.SetVariable(config, PidListString(pidList)); Overseer.Config.Save(); Close(); } else { foreach (PidList plist in pidList) { if (plist.Name.ToLower() == ((string)list.SelectedItem).ToLower()) { loadData = plist.Data; Close(); return; } } } }
private List<PidList> ParseList( string list ) { List<PidList> result = new List<PidList>(); if( list == null ) return (result); string[] data = list.Split( new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries ); foreach( string sList in data ) { string[] elements = sList.Split( new char[] { '^' }, StringSplitOptions.RemoveEmptyEntries ); PidList pidList = null; int[] tElements = new int[2] { -1, 0 }; int idx = 0; foreach( string sElement in elements ) { int tmp; if( idx == 0 ) { pidList = new PidList( sElement ); } else if( idx > 0 && idx <= tElements.Length ) { if( int.TryParse( sElement, out tmp ) ) tElements[idx - 1] = tmp; if( idx == tElements.Length ) { pidList.Data.Add( new Tuple<int, int>( tElements[0], tElements[1] ) ); tElements = new int[2] { -1, 0 }; idx = 0; } } idx++; } if( pidList != null && pidList.Data.Count > 0 ) result.Add( pidList ); } return (result); }
private void btnLoadSave_Click( object sender, EventArgs e ) { List<PidList> pidList = null; ListBox list = null; TextBox name = null; string config = null; if( tabs.SelectedTab == tabGlobal ) { pidList = global; list = listGlobal; name = nameGlobal; config = "ListPidsGlobal"; } else { pidList = local; list = listLocal; name = nameLocal; config = "ListPidsLocal"; } if( saveMode ) { if( name.Text.Length == 0 ) { MessageBox.Show( this, "Set a name for this list.", "User error", MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } foreach( char invalid in new char[] { '|', '^' } ) { if( name.Text.Contains( invalid ) ) { MessageBox.Show( this, "Invalid character in list name: " + invalid, "User error", MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } } int tmp; if( int.TryParse( name.Text, out tmp ) ) { MessageBox.Show( this, "List name can't be a number.", "User error", MessageBoxButtons.OK, MessageBoxIcon.Information ); return; } bool overwrite = false; foreach( PidList plist in pidList ) { if( plist.Name.ToLower() == name.Text.ToLower() ) { DialogResult = MessageBox.Show( this, "List with name <" + name.Text + "> already exists, overwrite?", null, MessageBoxButtons.YesNo, MessageBoxIcon.Question ); if( DialogResult == DialogResult.No ) return; else { plist.Data = saveData; overwrite = true; } break; } } if( !overwrite ) { PidList newList = new PidList( name.Text ); newList.Data = saveData; pidList.Add( newList ); } Overseer.Config.SetVariable( config, PidListString( pidList ) ); Overseer.Config.Save(); Close(); } else { foreach( PidList plist in pidList ) { if( plist.Name.ToLower() == ((string)list.SelectedItem).ToLower() ) { loadData = plist.Data; Close(); return; } } } }