/[RomCheater]/trunk/RomCheater/Docking/PIDSelector.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/PIDSelector.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater/Docking/PIDSelector.cs	2012/06/07 19:20:44	330
+++ trunk/RomCheater/Docking/PIDSelector.cs	2012/06/07 19:32:13	331
@@ -20,6 +20,7 @@
     {
         private bool isRefreshing = false;
         private bool isAutoRefreshing = false;
+        private bool isAttachingToProcess = false;
         //private IConfigPlugin plugin = null;
         //bool isInError = false;
         public PIDSelector() { InitializeComponent(); this.ProcessPID = -1; OnSelectedProcessChanged = null; this.AcceptedPlugin = null; }
@@ -71,13 +72,15 @@
 
         private void PerformListViewItemSelect(ListViewItem li)
         {
-            if (isAutoRefreshing) return;
+            if (isAutoRefreshing && !isAttachingToProcess) return;
             this.ProcessPID = Convert.ToInt32(li.SubItems[1].Text);
             Process SelectedProcess = Process.GetProcessById(this.ProcessPID);
             logger.Debug.WriteLine("Using Process: ({0} : {1})", SelectedProcess.Id, SelectedProcess.ProcessName);
             //this.Close();
             if (OnSelectedProcessChanged != null)
                 OnSelectedProcessChanged(new ProcessChangedEventArgs(this, this.ProcessPID));
+            if (isAttachingToProcess)
+                isAttachingToProcess = false;
         }
         private void btnOK_Click(object sender, EventArgs e)
         {
@@ -150,7 +153,7 @@
             lstProcessList.LargeImageList = large_image_list;
             this.lstProcessList.Items.AddRange(items.ToArray());
 
-            if (lstProcessList.Items.Count > 1)
+            if (lstProcessList.Items.Count > 1 && !isAttachingToProcess)
             {
                 lstProcessList.Items[0].Selected = true;
             }
@@ -214,60 +217,11 @@
         {
             DialogResult result = EXESelector.ShowDialog();
             if (result != DialogResult.OK) return;
-
             FileInfo fi = new FileInfo(EXESelector.FileName);
             if (!fi.Exists) { logger.Warn.WriteLine("Cannot load and attach to non-existing exe file: {0}", fi.FullName); return; }
-
-            Process p = Process.Start(fi.FullName);            
-            ProcContainer container = null;
-            try
-            {
-                container = new ProcContainer(p);
-            }
-            catch (FileNotFoundException) { }
-            catch (Exception) { }
-            ListViewItem item = new ListViewItem();
-            ImageList small_image_list = new ImageList();
-            ImageList large_image_list = new ImageList();
-
-            int small_width = 32;
-            int large_width = 48;
-
-            small_image_list.ImageSize = new Size(small_width, small_width);
-            large_image_list.ImageSize = new Size(large_width, large_width);
-            //foreach (ProcContainer pc in proc_list)
-            //{
-            Bitmap small_image = null;
-            Bitmap large_image = null;
-            string image_key = string.Empty;
-            this.AddProcessItem(container, small_image_list.ImageSize, large_image_list.ImageSize, out image_key, out small_image, out large_image);
-            if (image_key != string.Empty)
-            {
-                if (small_image != null) { lstProcessList.SmallImageList.Images.Add(image_key, small_image); }
-                if (large_image != null) { lstProcessList.LargeImageList.Images.Add(image_key, large_image); }
-                item.Name = container.GetHashCode().ToString();
-                // process name
-                item.Text = container.Name;
-                // pid
-                item.SubItems.Add(container.ProcessInfo.Id.ToString());
-                // FullPath
-                item.SubItems.Add(container.FileName);
-                // image key
-                item.ImageKey = container.FileName;
-                //if (!items.Contains(item)) items.Add(item);
-            }
-            this.lstProcessList.Items.Add(item);
-            if (lstProcessList.Items.Count == 2)
-            {
-                lstProcessList.Items[0].Selected = false;
-                lstProcessList.Items[1].Selected = true;
-            }
-            else
-            {
-                if (lstProcessList.SelectedItems.Count > 0)
-                    lstProcessList.Items[lstProcessList.SelectedItems[0].Index].Selected = false;
-                lstProcessList.Items[lstProcessList.Items.IndexOf(item)].Selected = true;
-            }
+            Process p = Process.Start(fi.FullName);
+            this.ProcessPID = p.Id;
+            isAttachingToProcess = true;          
         }
 
         private void ProcessWatcherTimer_Tick(object sender, EventArgs e) 
@@ -291,7 +245,7 @@
             }
             if (pid_still_exists)
             {
-                //logger.Debug.WriteLine("Pid: {0} still exists", pid);
+                //logger.Debug.WriteLine("Pid: {0} still exists", pid);                
                 if (lstProcessList.SelectedItems.Count > 0)
                 {
                     if (lstProcessList.SelectedItems[0] != null)

 

  ViewVC Help
Powered by ViewVC 1.1.22