public MainUI() { InitializeComponent(); SetDllDirectoryW(EventManager.InstallPath); EventManager.NotifyNewEvent += DisplayNewEvent; EventManager.Initialize(); MonitoredProcesses.Initialize(); RealtimeLog.NewLogEntryMethod += DisplayRealtimeLogEvent; RealtimeLog.Initialize(); }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("Do you wish to exit Crystal AEP? Unless disabled, protection will continue even if the application is closed.", "Exit Program?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == System.Windows.Forms.DialogResult.Yes) { MonitoredProcesses.TerminateThread(); RealtimeLog.TerminateThread(); MainUI.ShuttingDownProcess = true; Application.Exit(); } }
private void RefreshProcesses(object sender, EventArgs args) { try { WatchedProcess wp = null; List <TreeNode> removeTn = new List <TreeNode>(); foreach (TreeNode tn in tvMonProc.Nodes) { if (!MonitoredProcesses.Processes.TryGetValue((string)tn.Tag, out wp)) { removeTn.Add(tn); break; } } if (removeTn.Count != 0) { foreach (TreeNode tn in removeTn) { tvMonProc.Nodes.Remove(tn); tvMonProc.ImageList.Images.RemoveByKey((string)tn.Tag); if (tn.Tag != null) { try { string strPid = (string)tn.Tag; int idx = strPid.IndexOf("]["); strPid = strPid.Substring(checked (idx + 2)); idx = strPid.IndexOf("]"); strPid = strPid.Substring(0, idx); int pid = int.Parse(strPid); if (perProcessRtLogs.ContainsKey(pid)) { perProcessRtLogs.Remove(pid); } } catch { continue; } } } } foreach (KeyValuePair <string, WatchedProcess> kvp in MonitoredProcesses.Processes) { bool found = false; TreeNode refTn = null; foreach (TreeNode tn in tvMonProc.Nodes) { if (String.Compare((string)tn.Tag, kvp.Key, true) == 0) { refTn = tn; found = true; break; } } string displayStr = null; string windowTitle = kvp.Value.MainWindowTitle; string strDesc = ""; if (kvp.Value.FileVersion == null || kvp.Value.FileVersion.FileDescription == null) { strDesc = "No description"; } else { strDesc = kvp.Value.FileVersion.FileDescription; } string strVer = null; if (kvp.Value.FileVersion == null || kvp.Value.FileVersion.FileVersion == null) { strVer = "No version"; } else { strVer = kvp.Value.FileVersion.FileVersion; } if (String.IsNullOrEmpty(kvp.Value.MainWindowTitle)) { displayStr = string.Format("{0} ({1})", strDesc, kvp.Value.ExecutableName); } else { int fitsChars = tvMonProc.Width / 7; if (windowTitle.Length >= fitsChars) { displayStr = windowTitle.Substring(0, fitsChars) + "..."; } else { displayStr = windowTitle; } } string tooltipStr = string.Format("Title: {0}\nDescription: {1}\nVersion: {2}\nProcess ID: {3}\n", kvp.Value.MainWindowTitle ?? "(no title)", strDesc, strVer, kvp.Value.PID); if (found) { if (String.Compare(refTn.Text, displayStr, true) != 0) { refTn.Text = displayStr; refTn.ToolTipText = tooltipStr; } } else { TreeNode tn = tvMonProc.Nodes.Add(displayStr); Icon icon = kvp.Value.AssociatedIcon; if (icon != null) { tvMonProc.ImageList.Images.Add(kvp.Key, icon); tn.ImageKey = kvp.Key; } tn.ToolTipText = tooltipStr; tn.Tag = kvp.Key; } } MonitoredProcesses.Resume(); } catch (Exception ex) { //MessageBox.Show(ex.ToString()); //throw; } }