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

Contents of /trunk/RomCheater/Docking/PIDSelector.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 151 - (show annotations) (download)
Mon May 28 00:17:16 2012 UTC (8 years, 6 months ago) by william
File size: 8411 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22