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

Annotation of /trunk/RomCheater/PIDSelector.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 100 - (hide annotations) (download)
Thu May 10 09:03:13 2012 UTC (8 years, 5 months ago) by william
File size: 5612 byte(s)
+ add windows api to get module filename so there won't be errors with 32bit processes being unable to access 64bit process modules

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 william 93 if (!this.RefreshList()) { MessageBox.Show(string.Format("Could not find any Processes for plugin {0}. Please start an instance of one.",plugin.ToString())); }
37 william 88 else { if (owner == null) { base.Show(); } else { base.Show(owner); } }
38     }
39     private DialogResult PreInitDialog(IWin32Window owner)
40     {
41 william 93 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 william 88 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 william 92 this.plugin.Reload();
72 william 88 // 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 william 100 item.Text = p.FileName;
95 william 88 if (p.ProcessIcon != null)
96     {
97 william 100 Bitmap small_image = ProcContainer.CreateIconFromProcess(p, 1);
98     Bitmap large_image = ProcContainer.CreateIconFromProcess(p, 2);
99     small_image_list.Images.Add(p.FileName, ProcContainer.CreateIconFromProcess(p, 1));
100 william 88 small_image_list.ImageSize = new Size(small_image.Width, small_image.Height);
101 william 100 large_image_list.Images.Add(p.ProcessInfo.MainModule.FileName, ProcContainer.CreateIconFromProcess(p, 2));
102 william 88 large_image_list.ImageSize = new Size(large_image.Width, large_image.Height);
103 william 100 item.ImageKey = p.FileName;
104 william 88 }
105     // pid
106     item.SubItems.Add(p.ProcessInfo.Id.ToString());
107     // FullPath
108 william 100 item.SubItems.Add(p.FileName);
109 william 88 if (!items.Contains(item)) items.Add(item);
110     }
111     }
112     }
113    

  ViewVC Help
Powered by ViewVC 1.1.22