using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Diagnostics; using RomCheater.PluginFramework.Interfaces; using RomCheater.PluginFramework.Core; namespace RomCheater { public partial class PIDSelector : Form { private IConfigPlugin plugin = null; //bool isInError = false; public PIDSelector() { InitializeComponent(); this.SelectedPid = -1; } public PIDSelector(IConfigPlugin plugin) : this() { this.plugin = plugin; } // unsued construtor (it's not implmented, may not be) [Obsolete("constructor PIDSelector(int pid) is not implemented", false)] public PIDSelector(int pid) : this() { this.SelectedPid = pid; } [Obsolete("constructor PIDSelector(IConfigPlugin plugin, int pid) is not implemented", false)] public PIDSelector(IConfigPlugin plugin, int pid) : this(plugin) { this.SelectedPid = pid; } private int _SelectedPid; public int SelectedPid { get { return _SelectedPid; } set { _SelectedPid = value; } } public new void Show() { this.Show(null); } public new void Show(IWin32Window owner) { this.PreInitShow(owner); } public new DialogResult ShowDialog() { return this.ShowDialog(null); } public new DialogResult ShowDialog(IWin32Window owner) { return this.PreInitDialog(owner); } private void PreInitShow(IWin32Window owner) { if (!this.RefreshList()) { MessageBox.Show("Could not find any PCSX2 Processes. Please start an instance of one."); } else { if (owner == null) { base.Show(); } else { base.Show(owner); } } } private DialogResult PreInitDialog(IWin32Window owner) { if (!this.RefreshList()) { MessageBox.Show("Could not find any PCSX2 Processes. Please start an instance of one."); return DialogResult.Cancel; } else { if (owner == null) { return base.ShowDialog(); } else { return base.ShowDialog(owner); } } } private void btnLargeIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.LargeIcon; } private void btnDetails_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Details; } private void btnSmallIcon_Click(object sender, EventArgs e) { this.lstProcessList.View = View.SmallIcon; } private void btnList_Click(object sender, EventArgs e) { this.lstProcessList.View = View.List; } private void btnTile_Click(object sender, EventArgs e) { this.lstProcessList.View = View.Tile; } private void btnOK_Click(object sender, EventArgs e) { if (!(lstProcessList.SelectedItems.Count > 0)) return; this.SelectedPid = Convert.ToInt32(lstProcessList.SelectedItems[0].SubItems[1].Text); this.Close(); } private void btnCancel_Click(object sender, EventArgs e) { this.SelectedPid = -1; this.Close(); } private void btnRefresh_Click(object sender, EventArgs e) { this.RefreshList(); } private bool RefreshList() { lstProcessList.Items.Clear(); this.plugin.Reload(); // create a selection of PCSX2 processes List proc_list = plugin.ValidProcessesForPlugin; if (!(proc_list.Count > 0)) { //MessageBox.Show("Could not find any PCSX2 Processes. Please start an instance of one."); return false; } List items = new List(); ImageList small_image_list = new ImageList(); ImageList large_image_list = new ImageList(); foreach (ProcContainer p in proc_list) { this.AddProcessItem(p, ref items, out small_image_list, out large_image_list); } lstProcessList.SmallImageList = small_image_list; lstProcessList.LargeImageList = large_image_list; this.lstProcessList.Items.AddRange(items.ToArray()); return true; } private void AddProcessItem(ProcContainer p, ref List items, out ImageList small_image_list, out ImageList large_image_list) { small_image_list = new ImageList(); large_image_list = new ImageList(); ListViewItem item = new ListViewItem(); // process item.Text = p.ProcessInfo.MainModule.ModuleName; if (p.ProcessIcon != null) { Bitmap small_image = ProcContainer.CreateIconFromProcess(p.ProcessInfo, 1); Bitmap large_image = ProcContainer.CreateIconFromProcess(p.ProcessInfo, 2); small_image_list.Images.Add(p.ProcessInfo.MainModule.FileName, ProcContainer.CreateIconFromProcess(p.ProcessInfo, 1)); small_image_list.ImageSize = new Size(small_image.Width, small_image.Height); large_image_list.Images.Add(p.ProcessInfo.MainModule.FileName, ProcContainer.CreateIconFromProcess(p.ProcessInfo, 2)); large_image_list.ImageSize = new Size(large_image.Width, large_image.Height); item.ImageKey = p.ProcessInfo.MainModule.FileName; } // pid item.SubItems.Add(p.ProcessInfo.Id.ToString()); // FullPath item.SubItems.Add(p.ProcessInfo.MainModule.FileName); if (!items.Contains(item)) items.Add(item); } } }