/[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 18:32:25	328
+++ trunk/RomCheater/Docking/PIDSelector.cs	2012/06/07 19:18:31	329
@@ -12,11 +12,14 @@
 using RomCheater.Logging;
 using WeifenLuo.WinFormsUI.Docking;
 using RomCheater.PluginFramework.Events;
+using System.Management;
 
 namespace RomCheater.Docking
 {
     public partial class PIDSelector : DockContent, IAcceptsPlugin<IConfigPlugin>, IAcceptsChangedProcess, IAcceptsProcessPID
     {
+        private bool isRefreshing = false;
+        private bool isAutoRefreshing = false;
         //private IConfigPlugin plugin = null;
         //bool isInError = false;
         public PIDSelector() { InitializeComponent(); this.ProcessPID = -1; OnSelectedProcessChanged = null; this.AcceptedPlugin = null; }
@@ -68,6 +71,7 @@
 
         private void PerformListViewItemSelect(ListViewItem li)
         {
+            if (isAutoRefreshing) 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);
@@ -87,14 +91,15 @@
         //}
 
         private void btnRefresh_Click(object sender, EventArgs e)
-        {
-            this.RefreshList();
+        {                      
+            this.RefreshList();            
         }
 
         private bool RefreshList()
         {
+            isRefreshing = true;
             lstProcessList.Items.Clear();
-            this.AcceptedPlugin.Reload();
+            this.AcceptedPlugin.Reload(true);
             // create a selection of PCSX2 processes
             List<ProcContainer> proc_list = AcceptedPlugin.ValidProcessesForPlugin;
 
@@ -149,7 +154,7 @@
             {
                 lstProcessList.Items[0].Selected = true;
             }
-
+            isRefreshing = false;
             return true;
         }
 
@@ -264,6 +269,44 @@
                 lstProcessList.Items[lstProcessList.Items.IndexOf(item)].Selected = true;
             }
         }
+
+        private void ProcessWatcherTimer_Tick(object sender, EventArgs e) 
+        {
+            if (isRefreshing || isAutoRefreshing) return;
+            //if (lstProcessList.Items.Count == 0) return;
+            isAutoRefreshing = true;
+            int pid = this.ProcessPID;
+            btnRefresh.PerformClick();
+            bool pid_still_exists = false;
+            int item_index = -1;
+            foreach (ListViewItem li2 in lstProcessList.Items)
+            {
+                int _pid = Convert.ToInt32(li2.SubItems[1].Text);
+                if (_pid == pid)
+                {
+                    item_index = lstProcessList.Items.IndexOf(li2);
+                    pid_still_exists = true;
+                    break;
+                }
+            }
+            if (pid_still_exists)
+            {
+                //logger.Debug.WriteLine("Pid: {0} still exists", pid);
+                if (lstProcessList.SelectedItems.Count > 0)
+                {
+                    if (lstProcessList.SelectedItems[0] != null)
+                        if (lstProcessList.SelectedItems[0].Index != -1)
+                            lstProcessList.Items[lstProcessList.SelectedItems[0].Index].Selected = false;
+                }
+                lstProcessList.Items[item_index].Selected = true;
+            }
+            else
+            {
+                if (lstProcessList.SelectedItems.Count > 0)
+                    lstProcessList.Items[0].Selected = true;
+            }
+            isAutoRefreshing = false;
+        }
     }
 }
 

 

  ViewVC Help
Powered by ViewVC 1.1.22