/[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/PIDSelector.cs revision 107 by william, Thu May 10 11:16:03 2012 UTC trunk/RomCheater/Docking/PIDSelector.cs revision 296 by william, Tue Jun 5 10:52:57 2012 UTC
# Line 8  using System.Windows.Forms; Line 8  using System.Windows.Forms;
8  using System.Diagnostics;  using System.Diagnostics;
9  using RomCheater.PluginFramework.Interfaces;  using RomCheater.PluginFramework.Interfaces;
10  using RomCheater.PluginFramework.Core;  using RomCheater.PluginFramework.Core;
11    using System.IO;
12    using RomCheater.Logging;
13    using WeifenLuo.WinFormsUI.Docking;
14    using RomCheater.PluginFramework.Events;
15    
16  namespace RomCheater  namespace RomCheater.Docking
17  {  {
18      public partial class PIDSelector : Form      public partial class PIDSelector : DockContent, IAcceptsPlugin<IConfigPlugin>, IAcceptsChangedProcess, IAcceptsProcessPID
19      {      {
20          private IConfigPlugin plugin = null;          //private IConfigPlugin plugin = null;
21          //bool isInError = false;          //bool isInError = false;
22          public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; }          public PIDSelector() { InitializeComponent(); this.ProcessPID = -1; OnSelectedProcessChanged = null; this.AcceptedPlugin = null; }
23          public PIDSelector(IConfigPlugin plugin) : this() { this.plugin = plugin; }          public PIDSelector(IConfigPlugin plugin) : this() { this.AcceptedPlugin = plugin; }
24          // unsued construtor (it's not implmented, may not be)          // unsued construtor (it's not implmented, may not be)
25          [Obsolete("constructor PIDSelector(int pid) is not implemented", false)]          [Obsolete("constructor PIDSelector(int pid) is not implemented", false)]
26          public PIDSelector(int pid) : this() { this.SelectedPid = pid; }          public PIDSelector(int pid) : this() { this.ProcessPID = pid; }
27          [Obsolete("constructor PIDSelector(IConfigPlugin plugin, int pid) is not implemented", false)]          [Obsolete("constructor PIDSelector(IConfigPlugin plugin, int pid) is not implemented", false)]
28          public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.SelectedPid = pid; }          public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.ProcessPID = pid; }
29    
         private int _SelectedPid;  
         public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } }  
30    
31            private void OnProcessChanged(ProcessChangedEventArgs e)
         public new void Show() { this.Show(null); }  
         public new void Show(IWin32Window owner) { this.PreInitShow(owner); }  
         public new DialogResult ShowDialog() { return this.ShowDialog(null); }  
         public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); }  
         private void PreInitShow(IWin32Window owner)  
         {  
             if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.",plugin.ToString())); }  
             else { if (owner == null) { base.Show(); } else { base.Show(owner); } }  
         }  
         private DialogResult PreInitDialog(IWin32Window owner)  
32          {          {
             if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.", plugin.ToString())); return DialogResult.Cancel; }  
             else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } }  
33          }          }
34    
35            #region IAcceptsProcessPID
36            public int ProcessPID { get; set; }
37            #endregion
38            #region IAcceptsPlugin<IConfigPlugin> members
39            public IConfigPlugin AcceptedPlugin { get; set; }
40            #endregion
41            #region IAcceptsChangedProcess members
42            public event BaseEventHandler<ProcessChangedEventArgs> OnSelectedProcessChanged;
43            #endregion
44            
45    
46    
47            public new void Show() { this.Show(null); }
48            //public new void Show(IWin32Window owner) { this.PreInitShow(owner); }
49            public new void Show(DockPanel panel) { this.PreInitShow(panel); }
50            //public new DialogResult ShowDialog() { return this.ShowDialog(null); }
51            //public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); }
52            //private void PreInitShow(IWin32Window owner)
53            //{
54            //    if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.",plugin.ToString())); }
55            //    else { if (owner == null) { base.Show(); } else { base.Show(owner); } }
56            //}
57            private void PreInitShow(DockPanel panel)
58            {
59                //if (panel == null) return;
60                if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.", AcceptedPlugin.ToString())); }
61                else { if (panel == null) { base.Show(); } else { base.Show(panel); } }
62            }
63            //private DialogResult PreInitDialog(IWin32Window owner)
64            //{
65            //    if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}.  Please start an instance of one.", plugin.ToString())); return DialogResult.Cancel; }
66            //    else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } }
67            //}
68          private void btnLargeIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.LargeIcon; }          private void btnLargeIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.LargeIcon; }
69          private void btnDetails_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Details; }          private void btnDetails_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Details; }
70          private void btnSmallIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.SmallIcon; }          private void btnSmallIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.SmallIcon; }
71          private void btnList_Click(object sender, EventArgs e) { this.lstProcessList.View = View.List; }          private void btnList_Click(object sender, EventArgs e) { this.lstProcessList.View = View.List; }
72          private void btnTile_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Tile; }          private void btnTile_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Tile; }
73    
74            private void PerformListViewItemSelect(ListViewItem li)
75            {            
76                this.ProcessPID = Convert.ToInt32(li.SubItems[1].Text);
77                Process SelectedProcess = Process.GetProcessById(this.ProcessPID);
78                logger.Debug.WriteLine("Using Process: ({0} : {1})", SelectedProcess.Id, SelectedProcess.ProcessName);
79                //this.Close();
80                if (OnSelectedProcessChanged != null)
81                    OnSelectedProcessChanged(new ProcessChangedEventArgs(this.ProcessPID));          
82            }
83          private void btnOK_Click(object sender, EventArgs e)          private void btnOK_Click(object sender, EventArgs e)
84          {          {
85              if (!(lstProcessList.SelectedItems.Count > 0)) return;              
             this.SelectedPid = Convert.ToInt32(lstProcessList.SelectedItems[0].SubItems[1].Text);  
             this.Close();  
86          }          }
87    
88          private void btnCancel_Click(object sender, EventArgs e)          //private void btnCancel_Click(object sender, EventArgs e)
89          {          //{
90              this.SelectedPid = -1;          //    this.SelectedPid = -1;
91              this.Close();          //    //this.Close();
92          }          //}
93    
94          private void btnRefresh_Click(object sender, EventArgs e)          private void btnRefresh_Click(object sender, EventArgs e)
95          {          {
# Line 68  namespace RomCheater Line 99  namespace RomCheater
99          private bool RefreshList()          private bool RefreshList()
100          {          {
101              lstProcessList.Items.Clear();              lstProcessList.Items.Clear();
102              this.plugin.Reload();              this.AcceptedPlugin.Reload();
103              // create a selection of PCSX2 processes              // create a selection of PCSX2 processes
104              List<ProcContainer> proc_list = plugin.ValidProcessesForPlugin;              List<ProcContainer> proc_list = AcceptedPlugin.ValidProcessesForPlugin;
105    
106              if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes.  Please start an instance of one.");              if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes.  Please start an instance of one.");
107                  return false; }                  return false; }
# Line 78  namespace RomCheater Line 109  namespace RomCheater
109              List<ListViewItem> items = new List<ListViewItem>();              List<ListViewItem> items = new List<ListViewItem>();
110              ImageList small_image_list = new ImageList();              ImageList small_image_list = new ImageList();
111              ImageList large_image_list = new ImageList();              ImageList large_image_list = new ImageList();
112              foreach (ProcContainer p in proc_list) { this.AddProcessItem(p, ref items, out small_image_list, out large_image_list); }  
113                int small_width = 32;
114                int large_width = 48;
115    
116                small_image_list.ImageSize = new Size(small_width, small_width);
117                large_image_list.ImageSize = new Size(large_width, large_width);
118                foreach (ProcContainer p in proc_list)
119                {
120                    Bitmap small_image = null;
121                    Bitmap large_image = null;
122                    string image_key = string.Empty;
123                    this.AddProcessItem(p, small_image_list.ImageSize, large_image_list.ImageSize, out image_key, out small_image, out large_image);
124                    if (image_key != string.Empty)
125                    {
126                        if (small_image != null) { small_image_list.Images.Add(image_key, small_image); }
127                        if (large_image != null) { large_image_list.Images.Add(image_key, large_image); }
128                        ListViewItem item = new ListViewItem();
129                        // process name
130                        item.Text = p.Name;
131                        // pid
132                        item.SubItems.Add(p.ProcessInfo.Id.ToString());
133                        // FullPath
134                        item.SubItems.Add(p.FileName);
135                        // image key
136                        item.ImageKey = p.FileName;
137                        if (!items.Contains(item)) items.Add(item);
138                    }
139                    else
140                    {
141                        //logger.Error.WriteLine("image_key is an empty string!");
142                        //if (small_image != null) { logger.Error.WriteLine(" [however small_image is not null]"); }
143                        //if (large_image != null) { logger.Error.WriteLine(" [however large_image is not null]\n"); }
144                    }
145                }
146              lstProcessList.SmallImageList = small_image_list;              lstProcessList.SmallImageList = small_image_list;
147              lstProcessList.LargeImageList = large_image_list;              lstProcessList.LargeImageList = large_image_list;
148              this.lstProcessList.Items.AddRange(items.ToArray());              this.lstProcessList.Items.AddRange(items.ToArray());
149    
150                if (lstProcessList.Items.Count > 0)
151                {
152                    lstProcessList.Items[0].Selected = true;
153                }
154    
155              return true;              return true;
156          }          }
157    
158          private void AddProcessItem(ProcContainer p, ref  List<ListViewItem> items, out ImageList small_image_list, out ImageList large_image_list)          private void AddProcessItem(ProcContainer p, Size small, Size large, out string image_key, out Bitmap small_image, out Bitmap large_image)
159          {          {
160              small_image_list = new ImageList();              image_key = "";
161              large_image_list = new ImageList();              small_image = null;
162              ListViewItem item = new ListViewItem();              large_image = null;
163              // process              ////small_image_list = new ImageList();
164              item.Text = p.Name;              ////large_image_list = new ImageList();
165              if (p.ProcessIcon != null)              //ListViewItem item = new ListViewItem();
166                //// process
167                //item.Text = p.Name;
168                //if (p.ProcessIcon != null)
169                //{  
170                //    //small_image_list.Images.Add(
171                //    //large_image_list.Images.Add(p.FileName, p.ProcessIcon);                
172                //    item.ImageKey = p.FileName;
173                //}
174                //// pid
175                //item.SubItems.Add(p.ProcessInfo.Id.ToString());
176                //// FullPath
177                //item.SubItems.Add(p.FileName);
178                //if (!items.Contains(item)) items.Add(item);
179                if (p != null)
180              {              {
181                  Bitmap small_image = ProcContainer.CreateIconFromProcess(p, 1);                  if (p.ProcessIcon != null)
182                  Bitmap large_image = ProcContainer.CreateIconFromProcess(p, 2);                  {
183                  small_image_list.Images.Add(p.FileName, ProcContainer.CreateIconFromProcess(p, 1));                      image_key = p.FileName;
184                  small_image_list.ImageSize = new Size(small_image.Width, small_image.Height);                      small_image = new Bitmap(p.ProcessIcon, small);
185                  large_image_list.Images.Add(p.FileName, ProcContainer.CreateIconFromProcess(p, 2));                      large_image = new Bitmap(p.ProcessIcon, large);
186                  large_image_list.ImageSize = new Size(large_image.Width, large_image.Height);                  }
                 item.ImageKey = p.FileName;  
187              }              }
188              // pid  
189              item.SubItems.Add(p.ProcessInfo.Id.ToString());          }
190              // FullPath  
191              item.SubItems.Add(p.FileName);          private void PIDSelector_Load(object sender, EventArgs e)
192              if (!items.Contains(item)) items.Add(item);          {
193                if (AcceptedPlugin == null || this.DesignMode) return;
194                btnRefresh.PerformClick();
195            }
196    
197    
198            private void lstProcessList_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
199            {
200                if (!e.IsSelected) return;
201                PerformListViewItemSelect(e.Item);
202            }
203    
204            private void lstProcessList_ItemActivate(object sender, EventArgs e)
205            {
206                ListViewItem Item = lstProcessList.SelectedItems[0];
207                PerformListViewItemSelect(Item);
208          }          }
209    
210    
211      }      }
212  }  }
213    

Legend:
Removed from v.107  
changed lines
  Added in v.296

  ViewVC Help
Powered by ViewVC 1.1.22