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