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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22