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 |
|
|
|
12 |
|
|
namespace RomCheater |
13 |
|
|
{ |
14 |
|
|
public partial class PIDSelector : Form |
15 |
|
|
{ |
16 |
|
|
private IConfigPlugin plugin = null; |
17 |
|
|
//bool isInError = false; |
18 |
|
|
public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; } |
19 |
|
|
public PIDSelector(IConfigPlugin plugin) : this() { this.plugin = plugin; } |
20 |
|
|
// unsued construtor (it's not implmented, may not be) |
21 |
|
|
[Obsolete("constructor PIDSelector(int pid) is not implemented", false)] |
22 |
|
|
public PIDSelector(int pid) : this() { this.SelectedPid = pid; } |
23 |
|
|
[Obsolete("constructor PIDSelector(IConfigPlugin plugin, int pid) is not implemented", false)] |
24 |
|
|
public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.SelectedPid = pid; } |
25 |
|
|
|
26 |
|
|
private int _SelectedPid; |
27 |
|
|
public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } } |
28 |
|
|
|
29 |
|
|
|
30 |
|
|
public new void Show() { this.Show(null); } |
31 |
|
|
public new void Show(IWin32Window owner) { this.PreInitShow(owner); } |
32 |
|
|
public new DialogResult ShowDialog() { return this.ShowDialog(null); } |
33 |
|
|
public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); } |
34 |
|
|
private void PreInitShow(IWin32Window owner) |
35 |
|
|
{ |
36 |
|
|
if (!this.RefreshList()) { MessageBox.Show("Could not find any PCSX2 Processes. Please start an instance of one."); } |
37 |
|
|
else { if (owner == null) { base.Show(); } else { base.Show(owner); } } |
38 |
|
|
} |
39 |
|
|
private DialogResult PreInitDialog(IWin32Window owner) |
40 |
|
|
{ |
41 |
|
|
if (!this.RefreshList()) { MessageBox.Show("Could not find any PCSX2 Processes. Please start an instance of one."); return DialogResult.Cancel; } |
42 |
|
|
else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } } |
43 |
|
|
} |
44 |
|
|
private void btnLargeIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.LargeIcon; } |
45 |
|
|
private void btnDetails_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Details; } |
46 |
|
|
private void btnSmallIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.SmallIcon; } |
47 |
|
|
private void btnList_Click(object sender, EventArgs e) { this.lstProcessList.View = View.List; } |
48 |
|
|
private void btnTile_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Tile; } |
49 |
|
|
|
50 |
|
|
private void btnOK_Click(object sender, EventArgs e) |
51 |
|
|
{ |
52 |
|
|
if (!(lstProcessList.SelectedItems.Count > 0)) return; |
53 |
|
|
this.SelectedPid = Convert.ToInt32(lstProcessList.SelectedItems[0].SubItems[1].Text); |
54 |
|
|
this.Close(); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
private void btnCancel_Click(object sender, EventArgs e) |
58 |
|
|
{ |
59 |
|
|
this.SelectedPid = -1; |
60 |
|
|
this.Close(); |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
private void btnRefresh_Click(object sender, EventArgs e) |
64 |
|
|
{ |
65 |
|
|
this.RefreshList(); |
66 |
|
|
} |
67 |
|
|
|
68 |
|
|
private bool RefreshList() |
69 |
|
|
{ |
70 |
|
|
lstProcessList.Items.Clear(); |
71 |
|
|
// create a selection of PCSX2 processes |
72 |
|
|
List<ProcContainer> proc_list = plugin.ValidProcessesForPlugin; |
73 |
|
|
|
74 |
|
|
if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes. Please start an instance of one."); |
75 |
|
|
return false; } |
76 |
|
|
|
77 |
|
|
List<ListViewItem> items = new List<ListViewItem>(); |
78 |
|
|
ImageList small_image_list = new ImageList(); |
79 |
|
|
ImageList large_image_list = new ImageList(); |
80 |
|
|
foreach (ProcContainer p in proc_list) { this.AddProcessItem(p, ref items, out small_image_list, out large_image_list); } |
81 |
|
|
lstProcessList.SmallImageList = small_image_list; |
82 |
|
|
lstProcessList.LargeImageList = large_image_list; |
83 |
|
|
this.lstProcessList.Items.AddRange(items.ToArray()); |
84 |
|
|
return true; |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
private void AddProcessItem(ProcContainer p, ref List<ListViewItem> items, out ImageList small_image_list, out ImageList large_image_list) |
88 |
|
|
{ |
89 |
|
|
small_image_list = new ImageList(); |
90 |
|
|
large_image_list = new ImageList(); |
91 |
|
|
ListViewItem item = new ListViewItem(); |
92 |
|
|
// process |
93 |
|
|
item.Text = p.ProcessInfo.MainModule.ModuleName; |
94 |
|
|
if (p.ProcessIcon != null) |
95 |
|
|
{ |
96 |
|
|
Bitmap small_image = ProcContainer.CreateIconFromProcess(p.ProcessInfo, 1); |
97 |
|
|
Bitmap large_image = ProcContainer.CreateIconFromProcess(p.ProcessInfo, 2); |
98 |
|
|
small_image_list.Images.Add(p.ProcessInfo.MainModule.FileName, ProcContainer.CreateIconFromProcess(p.ProcessInfo, 1)); |
99 |
|
|
small_image_list.ImageSize = new Size(small_image.Width, small_image.Height); |
100 |
|
|
large_image_list.Images.Add(p.ProcessInfo.MainModule.FileName, ProcContainer.CreateIconFromProcess(p.ProcessInfo, 2)); |
101 |
|
|
large_image_list.ImageSize = new Size(large_image.Width, large_image.Height); |
102 |
|
|
item.ImageKey = p.ProcessInfo.MainModule.FileName; |
103 |
|
|
} |
104 |
|
|
// pid |
105 |
|
|
item.SubItems.Add(p.ProcessInfo.Id.ToString()); |
106 |
|
|
// FullPath |
107 |
|
|
item.SubItems.Add(p.ProcessInfo.MainModule.FileName); |
108 |
|
|
if (!items.Contains(item)) items.Add(item); |
109 |
|
|
} |
110 |
|
|
} |
111 |
|
|
} |
112 |
|
|
|