using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; using System.Drawing; using System.IO; using libWin32.Win32.Threading; namespace RomCheater.PluginFramework.Core { public class ProcContainer { public ProcContainer() { this.init(); } public ProcContainer(Process process) : this() { this.ProcessInfo = process; FileInfo fi = null; string fname = ""; try { fname = ProcessModeleInfoEx.GetMainModulePath(process); fi = new FileInfo(fname); } catch (Exception) { throw; } this.FileName = fi.FullName; this.Name = fi.Name; this.CreateProcessIcon(4); } public ProcContainer(Process process, Icon icon) : this() { this.ProcessInfo = process; this.ProcessIcon = icon.ToBitmap(); string fname = ProcessModeleInfoEx.GetMainModulePath(process); FileInfo fi = new FileInfo(fname); this.FileName = fi.FullName; this.Name = fi.Name; } public ProcContainer(Process process, Bitmap icon) : this() { this.ProcessInfo = process; this.ProcessIcon = icon; string fname = ProcessModeleInfoEx.GetMainModulePath(process); FileInfo fi = new FileInfo(fname); this.FileName = fi.FullName; this.Name = fi.Name; } private void init() { this.ProcessInfo = null; this.ProcessIcon = null; } public string Name { get; set; } public string FileName { get; set; } private Process _ProcessInfo; public Process ProcessInfo { get { return _ProcessInfo; } set { _ProcessInfo = value; } } private Bitmap _ProcessIcon; public Bitmap ProcessIcon { get { return _ProcessIcon; } set { _ProcessIcon = value; } } public override string ToString() { return this.FileName; } public static Bitmap CreateIconFromProcess(ProcContainer proc) { if (proc == null) return null; Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true); if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false); Bitmap ret = null; if (large != null) ret = large.ToBitmap(); if (ret == null) { return null; } return ret; } public static Bitmap CreateIconFromProcess(ProcContainer proc, int Scale) { if (proc == null) return null; Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true); if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false); Bitmap ret = null; if (large != null) ret = large.ToBitmap(); if (ret == null) { return null; } ret = new Bitmap(ret, ret.Width * Scale, ret.Height * Scale); return ret; } public static Bitmap CreateIconFromProcess(ProcContainer proc, int Width, int Height) { if (proc == null) return null; Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true); if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false); Bitmap ret = null; if (large != null) ret = large.ToBitmap(); if (ret == null) { return null; } ret = new Bitmap(ret, Width, Height); return ret; } private void CreateProcessIcon() { if (this.ProcessInfo == null) return; Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true); if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false); Bitmap ret = null; if (large != null) ret = large.ToBitmap(); if (ret == null) { this.ProcessIcon = null; return; } this.ProcessIcon = ret; } private void CreateProcessIcon(int Scale) { if (this.ProcessInfo == null) return; Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true); if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false); Bitmap ret = null; if (large != null) ret = large.ToBitmap(); if (ret == null) { this.ProcessIcon = null; return; } ////Bitmap bmp = large.ToBitmap(); //string save_path = @"c:\temp"; //string icon_file = string.Format(@"{0}\{1}.bmp", save_path, new FileInfo(this.FileName).Name); ret = new Bitmap(ret, ret.Width * Scale, ret.Height * Scale); //ret.Save(icon_file, System.Drawing.Imaging.ImageFormat.Bmp); this.ProcessIcon = ret; } private void CreateProcessIcon(int Width, int Height) { if (this.ProcessInfo == null) return; Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true); if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false); Bitmap ret = null; if (large != null) ret = large.ToBitmap(); if (ret == null) { this.ProcessIcon = null; return; } ret = new Bitmap(ret, Width, Height); this.ProcessIcon = ret; } } }