Esempio n. 1
0
        public override bool Equals(Object other)
        {
            if (!(other is ProcessDetails))
            {
                return(false);
            }
            ProcessDetails o = (ProcessDetails)other;

            return(o.processName.Equals(processName) &&
                   o.processExe.Equals(processExe) && // -- we could comment this out
                   o.dimensions.Equals(dimensions) &&
                   o.mainWindowTitle.Equals(mainWindowTitle));
        }
Esempio n. 2
0
        public static ProcessDetails ParseString(string s)
        {
            // Console.WriteLine("Parsing p '" + s + "'");
            Match m = Regex.Match(s, "^([0-9]+)\t(.*)\t(.*)\t(.*)$");

            if (m.Success)
            {
                ProcessDetails pd = new ProcessDetails();
                pd.id              = Convert.ToInt32(m.Groups[1].Value);
                pd.processName     = m.Groups[2].Value;
                pd.processExe      = m.Groups[3].Value;
                pd.dimensions      = m.Groups[4].Value;
                pd.mainWindowTitle = m.Groups[5].Value;
                return(pd);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 3
0
        private void showTime(DateTime dateTime)
        {
            // get desktop
            string jpgFile = dataDir + "\\" + dateTime.ToString("yyyy-MM-dd") + "\\desktop-" +
                             dateTime.ToString("HH.mm.ss") + ".1234.jpg";

            backImage = Image.FromFile(jpgFile);

            desktopView.setImage(backImage);
            // pbxScreen.Invalidate();

            shownDate = dateTime;

            // get process list / windows
            // Open the file and read it back.
            List <ProcessDetails> pds = new List <ProcessDetails>();
            List <WindowDetails>  wds = new List <WindowDetails>();
            string datafile           = dataDir + "\\" + dateTime.ToString("yyyy-MM-dd") + "\\windowList.log";

            using (System.IO.StreamReader sr = System.IO.File.OpenText(datafile)) {
                string   s           = "";
                string   country     = sr.ReadLine();
                DateTime parsingDate = new DateTime();
                Boolean  eof         = false;

                while ((!eof) && (s = sr.ReadLine()) != null)
                {
                    // s = s.Trim();
                    if (s.StartsWith("*** Begin snapshot "))
                    {
                        string      d           = s.Substring(19, 8);
                        CultureInfo cultureInfo = CultureInfo.CurrentCulture;
                        parsingDate = DateTime.ParseExact(d, "HH.mm.ss", cultureInfo);
                        parsingDate = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
                                                   parsingDate.Hour, parsingDate.Minute, parsingDate.Second);
                    }
                    else if (s.StartsWith("P + "))
                    {
                        ProcessDetails pd = ProcessDetails.ParseString(s.Substring(4));
                        if (pd != null)
                        {
                            pds.Add(pd);
                        }
                        else
                        {
                            Console.WriteLine("Could not parse P+: " + s);
                        }
                    }
                    else if (s.StartsWith("W + "))
                    {
                        WindowDetails wd = WindowDetails.ParseString(s.Substring(4));
                        if (wd != null)
                        {
                            wds.Add(wd);
                        }
                        else
                        {
                            Console.WriteLine("Could not parse w+: " + s);
                        }
                    }
                    else if (s.StartsWith("WO ! "))
                    {
                        List <int>      newOrder = new List <int>();
                        StringTokenizer st       = new StringTokenizer(s.Substring(5), " ");
                        while (st.HasMoreTokens())
                        {
                            newOrder.Add(Convert.ToInt32(st.NextToken()));
                        }
                    }

                    // read next line
                    s = sr.ReadLine();
                }
            }

            lstProcess.BeginUpdate();
            lstProcess.Items.Clear();
            foreach (WindowDetails wd in wds)
            {
                // @TODO check if window is visible
                Console.WriteLine("Adding wd '" + wd.title + "'");
                ListViewItem lvi = new ListViewItem(new string[] { wd.title }, Convert.ToString(wd.iconId));
                lvi.Text = wd.title;
                lvi.Tag  = wd;
                // lvi.ImageIndex = lstProcess.SmallImageList.Images.IndexOfKey();
                lstProcess.Items.Add(lvi);
            }
            lstProcess.EndUpdate();
        }
Esempio n. 4
0
        public Hashtable getProcessMap()
        {
            Hashtable newMap = new Hashtable();

            System.Diagnostics.Process[] myProcesses = System.Diagnostics.Process.GetProcesses();
            for (int i = 0; i < myProcesses.Length; i++)
            {
                ProcessDetails pd = new ProcessDetails();
                newMap.Add(myProcesses[i].Id, pd);
                System.Diagnostics.Process p = myProcesses[i];
                pd.id = myProcesses[i].Id;
                // cache process name ?
                pd.processName = p.ProcessName;
                if (!processMap.ContainsKey(pd.id))
                {
                    try {
                        pd.processExe = p.MainModule.FileName;
                    } catch (System.ComponentModel.Win32Exception) {
                        pd.processExe = "";
                    }
                }
                else
                {
                    // just copy the exe across from previous lookup to save time
                    pd.processExe = ((ProcessDetails)processMap[pd.id]).processExe;
                }

                pd.dimensions      = "";
                pd.mainWindowTitle = "";


                // this takes 2 secs to iterate; replaced with GetWindowText() below
                // pd.mainWindowTitle = p.MainWindowTitle;

                // this takes 0.78 secs; replaced with window enumeration below

                /*
                 * try {
                 *  Win32.RECT rc = new Win32.RECT();
                 *  IntPtr hwnd = p.MainWindowHandle;
                 *  Win32.GetWindowRect(hwnd, ref rc);
                 *  pd.dimensions = String.Format("({0},{1})-({2},{3})", rc.left, rc.top, rc.right, rc.bottom);
                 * } catch (System.ComponentModel.Win32Exception we) {
                 * }
                 */

                // this takes 2 seconds to process for all processes on my laptop (arg!);
                // replaced with WMI + getWindowModuleFilename() below

                /*
                 * try {
                 *  System.Diagnostics.ProcessModuleCollection pcm = p.Modules;
                 *  if (pcm.Count > 0) {
                 *      System.Diagnostics.ProcessModule pm = pcm[0];
                 *      pd.processExe = pm.FileName;
                 *  }
                 * } catch (System.ComponentModel.Win32Exception we) {
                 * } catch (InvalidOperationException ioe) {
                 *  // occurs if process is closed whilst process list is being iterated
                 * }
                 */
                // Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}", myProcesses[i].Id, processName, processExe, dimensions, p.MainWindowTitle);
            }
            return(newMap);
        }