/[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 16:33:41	323
+++ trunk/RomCheater/Docking/PIDSelector.cs	2012/06/07 18:29:28	327
@@ -26,7 +26,7 @@
         public PIDSelector(int pid) : this() { this.ProcessPID = pid; }
         [Obsolete("constructor PIDSelector(IConfigPlugin plugin, int pid) is not implemented", false)]
         public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.ProcessPID = pid; }
-        
+
         #region IAcceptsProcessPID
         public int ProcessPID { get; set; }
         #endregion
@@ -36,7 +36,7 @@
         #region IAcceptsChangedProcess members
         public event BaseEventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged;
         #endregion
-        
+
 
 
         public new void Show() { this.Show(null); }
@@ -67,17 +67,17 @@
         private void btnTile_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Tile; }
 
         private void PerformListViewItemSelect(ListViewItem li)
-        {            
+        {
             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));           
+                OnSelectedProcessChanged(new ProcessChangedEventArgs(this, this.ProcessPID));
         }
         private void btnOK_Click(object sender, EventArgs e)
         {
-            
+
         }
 
         //private void btnCancel_Click(object sender, EventArgs e)
@@ -98,8 +98,10 @@
             // create a selection of PCSX2 processes
             List<ProcContainer> proc_list = AcceptedPlugin.ValidProcessesForPlugin;
 
-            if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes.  Please start an instance of one."); 
-                return false; }
+            if (!(proc_list.Count > 0))
+            { //MessageBox.Show("Could not find any PCSX2 Processes.  Please start an instance of one."); 
+                return false;
+            }
 
             List<ListViewItem> items = new List<ListViewItem>();
             ImageList small_image_list = new ImageList();
@@ -110,7 +112,7 @@
 
             small_image_list.ImageSize = new Size(small_width, small_width);
             large_image_list.ImageSize = new Size(large_width, large_width);
-            foreach (ProcContainer p in proc_list) 
+            foreach (ProcContainer p in proc_list)
             {
                 Bitmap small_image = null;
                 Bitmap large_image = null;
@@ -121,6 +123,7 @@
                     if (small_image != null) { small_image_list.Images.Add(image_key, small_image); }
                     if (large_image != null) { large_image_list.Images.Add(image_key, large_image); }
                     ListViewItem item = new ListViewItem();
+                    item.Name = p.GetHashCode().ToString();
                     // process name
                     item.Text = p.Name;
                     // pid
@@ -142,7 +145,7 @@
             lstProcessList.LargeImageList = large_image_list;
             this.lstProcessList.Items.AddRange(items.ToArray());
 
-            if (lstProcessList.Items.Count > 0)
+            if (lstProcessList.Items.Count > 1)
             {
                 lstProcessList.Items[0].Selected = true;
             }
@@ -202,7 +205,63 @@
             PerformListViewItemSelect(Item);
         }
 
+        private void btnLaunchAndAttach_Click(object sender, EventArgs e)
+        {
+            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 == 1)
+            {
+                lstProcessList.Items[0].Selected = true;
+            }
+            else
+            {
+                lstProcessList.Items[lstProcessList.SelectedItems[0].Index].Selected = false;
+                lstProcessList.Items[lstProcessList.Items.IndexOf(item)].Selected = true;
+            }
+        }
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22