1 |
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 |
using System.IO; |
12 |
using RomCheater.Logging; |
13 |
|
14 |
namespace RomCheater |
15 |
{ |
16 |
public partial class PIDSelector : Form |
17 |
{ |
18 |
private IConfigPlugin plugin = null; |
19 |
//bool isInError = false; |
20 |
public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; } |
21 |
public PIDSelector(IConfigPlugin plugin) : this() { this.plugin = plugin; } |
22 |
// unsued construtor (it's not implmented, may not be) |
23 |
[Obsolete("constructor PIDSelector(int pid) is not implemented", false)] |
24 |
public PIDSelector(int pid) : this() { this.SelectedPid = pid; } |
25 |
[Obsolete("constructor PIDSelector(IConfigPlugin plugin, int pid) is not implemented", false)] |
26 |
public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.SelectedPid = pid; } |
27 |
|
28 |
private int _SelectedPid; |
29 |
public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } } |
30 |
|
31 |
|
32 |
public new void Show() { this.Show(null); } |
33 |
public new void Show(IWin32Window owner) { this.PreInitShow(owner); } |
34 |
public new DialogResult ShowDialog() { return this.ShowDialog(null); } |
35 |
public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); } |
36 |
private void PreInitShow(IWin32Window owner) |
37 |
{ |
38 |
if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}. Please start an instance of one.",plugin.ToString())); } |
39 |
else { if (owner == null) { base.Show(); } else { base.Show(owner); } } |
40 |
} |
41 |
private DialogResult PreInitDialog(IWin32Window owner) |
42 |
{ |
43 |
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; } |
44 |
else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } } |
45 |
} |
46 |
private void btnLargeIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.LargeIcon; } |
47 |
private void btnDetails_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Details; } |
48 |
private void btnSmallIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.SmallIcon; } |
49 |
private void btnList_Click(object sender, EventArgs e) { this.lstProcessList.View = View.List; } |
50 |
private void btnTile_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Tile; } |
51 |
|
52 |
private void btnOK_Click(object sender, EventArgs e) |
53 |
{ |
54 |
if (!(lstProcessList.SelectedItems.Count > 0)) return; |
55 |
this.SelectedPid = Convert.ToInt32(lstProcessList.SelectedItems[0].SubItems[1].Text); |
56 |
this.Close(); |
57 |
} |
58 |
|
59 |
private void btnCancel_Click(object sender, EventArgs e) |
60 |
{ |
61 |
this.SelectedPid = -1; |
62 |
this.Close(); |
63 |
} |
64 |
|
65 |
private void btnRefresh_Click(object sender, EventArgs e) |
66 |
{ |
67 |
this.RefreshList(); |
68 |
} |
69 |
|
70 |
private bool RefreshList() |
71 |
{ |
72 |
lstProcessList.Items.Clear(); |
73 |
this.plugin.Reload(); |
74 |
// create a selection of PCSX2 processes |
75 |
List<ProcContainer> proc_list = plugin.ValidProcessesForPlugin; |
76 |
|
77 |
if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes. Please start an instance of one."); |
78 |
return false; } |
79 |
|
80 |
List<ListViewItem> items = new List<ListViewItem>(); |
81 |
ImageList small_image_list = new ImageList(); |
82 |
ImageList large_image_list = new ImageList(); |
83 |
|
84 |
int small_width = 16; |
85 |
int large_width = 32; |
86 |
|
87 |
small_image_list.ImageSize = new Size(small_width, small_width); |
88 |
large_image_list.ImageSize = new Size(large_width, large_width); |
89 |
foreach (ProcContainer p in proc_list) |
90 |
{ |
91 |
Bitmap small_image = null; |
92 |
Bitmap large_image = null; |
93 |
string image_key = string.Empty; |
94 |
this.AddProcessItem(p, small_image_list.ImageSize, large_image_list.ImageSize, out image_key, out small_image, out large_image); |
95 |
if (image_key != string.Empty) |
96 |
{ |
97 |
if (small_image != null) { small_image_list.Images.Add(image_key, small_image); } |
98 |
if (large_image != null) { large_image_list.Images.Add(image_key, large_image); } |
99 |
ListViewItem item = new ListViewItem(); |
100 |
// process name |
101 |
item.Text = p.Name; |
102 |
// pid |
103 |
item.SubItems.Add(p.ProcessInfo.Id.ToString()); |
104 |
// FullPath |
105 |
item.SubItems.Add(p.FileName); |
106 |
// image key |
107 |
item.ImageKey = p.FileName; |
108 |
if (!items.Contains(item)) items.Add(item); |
109 |
} |
110 |
else |
111 |
{ |
112 |
logger.Error.Write("image_key is an empty string!"); |
113 |
if (small_image != null) { logger.Error.Write(" [however small_image is not null]"); } |
114 |
if (large_image != null) { logger.Error.Write(" [however large_image is not null]\n"); } |
115 |
} |
116 |
} |
117 |
lstProcessList.SmallImageList = small_image_list; |
118 |
lstProcessList.LargeImageList = large_image_list; |
119 |
this.lstProcessList.Items.AddRange(items.ToArray()); |
120 |
return true; |
121 |
} |
122 |
|
123 |
private void AddProcessItem(ProcContainer p, Size small, Size large, out string image_key, out Bitmap small_image, out Bitmap large_image) |
124 |
{ |
125 |
image_key = ""; |
126 |
small_image = null; |
127 |
large_image = null; |
128 |
////small_image_list = new ImageList(); |
129 |
////large_image_list = new ImageList(); |
130 |
//ListViewItem item = new ListViewItem(); |
131 |
//// process |
132 |
//item.Text = p.Name; |
133 |
//if (p.ProcessIcon != null) |
134 |
//{ |
135 |
// //small_image_list.Images.Add( |
136 |
// //large_image_list.Images.Add(p.FileName, p.ProcessIcon); |
137 |
// item.ImageKey = p.FileName; |
138 |
//} |
139 |
//// pid |
140 |
//item.SubItems.Add(p.ProcessInfo.Id.ToString()); |
141 |
//// FullPath |
142 |
//item.SubItems.Add(p.FileName); |
143 |
//if (!items.Contains(item)) items.Add(item); |
144 |
if (p != null) |
145 |
{ |
146 |
if (p.ProcessIcon != null) |
147 |
{ |
148 |
image_key = p.FileName; |
149 |
small_image = new Bitmap(p.ProcessIcon, small); |
150 |
large_image = new Bitmap(p.ProcessIcon, large); |
151 |
} |
152 |
} |
153 |
|
154 |
} |
155 |
} |
156 |
} |
157 |
|