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; using System.IO; using RomCheater.Logging; 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(string.Format("Could not find any Processes for plugin {0}. Please start an instance of one.",plugin.ToString())); } else { if (owner == null) { base.Show(); } else { base.Show(owner); } } } private DialogResult PreInitDialog(IWin32Window owner) { 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; } 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(); int small_width = 32; int large_width = 48; small_image_list.ImageSize = new Size(small_width, small_width); large_image_list.ImageSize = new Size(large_width, large_width); foreach (ProcContainer p in proc_list) { Bitmap small_image = null; Bitmap large_image = null; string image_key = string.Empty; this.AddProcessItem(p, small_image_list.ImageSize, large_image_list.ImageSize, out image_key, out small_image, out large_image); if (image_key != string.Empty) { if (small_image != null) { small_image_list.Images.Add(image_key, small_image); } if (large_image != null) { large_image_list.Images.Add(image_key, large_image); } ListViewItem item = new ListViewItem(); // process name item.Text = p.Name; // pid item.SubItems.Add(p.ProcessInfo.Id.ToString()); // FullPath item.SubItems.Add(p.FileName); // image key item.ImageKey = p.FileName; if (!items.Contains(item)) items.Add(item); } else { logger.Error.Write("image_key is an empty string!"); if (small_image != null) { logger.Error.Write(" [however small_image is not null]"); } if (large_image != null) { logger.Error.Write(" [however large_image is not null]\n"); } } } lstProcessList.SmallImageList = small_image_list; lstProcessList.LargeImageList = large_image_list; this.lstProcessList.Items.AddRange(items.ToArray()); return true; } private void AddProcessItem(ProcContainer p, Size small, Size large, out string image_key, out Bitmap small_image, out Bitmap large_image) { image_key = ""; small_image = null; large_image = null; ////small_image_list = new ImageList(); ////large_image_list = new ImageList(); //ListViewItem item = new ListViewItem(); //// process //item.Text = p.Name; //if (p.ProcessIcon != null) //{ // //small_image_list.Images.Add( // //large_image_list.Images.Add(p.FileName, p.ProcessIcon); // item.ImageKey = p.FileName; //} //// pid //item.SubItems.Add(p.ProcessInfo.Id.ToString()); //// FullPath //item.SubItems.Add(p.FileName); //if (!items.Contains(item)) items.Add(item); if (p != null) { if (p.ProcessIcon != null) { image_key = p.FileName; small_image = new Bitmap(p.ProcessIcon, small); large_image = new Bitmap(p.ProcessIcon, large); } } } } }