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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 323 - (hide annotations) (download)
Thu Jun 7 16:33:41 2012 UTC (8 years, 11 months ago) by william
File size: 9453 byte(s)
+ add event for being able to subscribe to PEReader updates

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

  ViewVC Help
Powered by ViewVC 1.1.22