ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/PIDSelector.cs
Revision: 93
Committed: Wed May 9 22:23:18 2012 UTC (11 years, 6 months ago) by william
File size: 5754 byte(s)
Log Message:

File Contents

# Content
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
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(string.Format("Could not find any Processes for plugin {0}. Please start an instance of one.",plugin.ToString())); }
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(string.Format("Could not find any Processes for plugin {0}. Please start an instance of one.", plugin.ToString())); 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 this.plugin.Reload();
72 // create a selection of PCSX2 processes
73 List<ProcContainer> proc_list = plugin.ValidProcessesForPlugin;
74
75 if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes. Please start an instance of one.");
76 return false; }
77
78 List<ListViewItem> items = new List<ListViewItem>();
79 ImageList small_image_list = new ImageList();
80 ImageList large_image_list = new ImageList();
81 foreach (ProcContainer p in proc_list) { this.AddProcessItem(p, ref items, out small_image_list, out large_image_list); }
82 lstProcessList.SmallImageList = small_image_list;
83 lstProcessList.LargeImageList = large_image_list;
84 this.lstProcessList.Items.AddRange(items.ToArray());
85 return true;
86 }
87
88 private void AddProcessItem(ProcContainer p, ref List<ListViewItem> items, out ImageList small_image_list, out ImageList large_image_list)
89 {
90 small_image_list = new ImageList();
91 large_image_list = new ImageList();
92 ListViewItem item = new ListViewItem();
93 // process
94 item.Text = p.ProcessInfo.MainModule.ModuleName;
95 if (p.ProcessIcon != null)
96 {
97 Bitmap small_image = ProcContainer.CreateIconFromProcess(p.ProcessInfo, 1);
98 Bitmap large_image = ProcContainer.CreateIconFromProcess(p.ProcessInfo, 2);
99 small_image_list.Images.Add(p.ProcessInfo.MainModule.FileName, ProcContainer.CreateIconFromProcess(p.ProcessInfo, 1));
100 small_image_list.ImageSize = new Size(small_image.Width, small_image.Height);
101 large_image_list.Images.Add(p.ProcessInfo.MainModule.FileName, ProcContainer.CreateIconFromProcess(p.ProcessInfo, 2));
102 large_image_list.ImageSize = new Size(large_image.Width, large_image.Height);
103 item.ImageKey = p.ProcessInfo.MainModule.FileName;
104 }
105 // pid
106 item.SubItems.Add(p.ProcessInfo.Id.ToString());
107 // FullPath
108 item.SubItems.Add(p.ProcessInfo.MainModule.FileName);
109 if (!items.Contains(item)) items.Add(item);
110 }
111 }
112 }
113