/[RomCheater]/trunk/RomCheater.PluginFramework/Core/ProcContainer.cs
ViewVC logotype

Annotation of /trunk/RomCheater.PluginFramework/Core/ProcContainer.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 109 - (hide annotations) (download)
Thu May 10 12:12:26 2012 UTC (9 years, 6 months ago) by william
File size: 6121 byte(s)
fix code to properly display icons in PIDSelector

1 william 88 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5     using System.Diagnostics;
6     using System.Drawing;
7     using System.IO;
8 william 100 using libWin32.Win32.Threading;
9 william 88
10     namespace RomCheater.PluginFramework.Core
11     {
12     public class ProcContainer
13     {
14     public ProcContainer() { this.init(); }
15     public ProcContainer(Process process)
16     : this()
17     {
18 william 100 this.ProcessInfo = process;
19 william 101 FileInfo fi = null;
20     string fname = "";
21     try
22     {
23     fname = ProcessModeleInfoEx.GetMainModulePath(process);
24     fi = new FileInfo(fname);
25     }
26 william 105 catch (Exception)
27 william 101 {
28     throw;
29     }
30 william 88 this.FileName = fi.FullName;
31     this.Name = fi.Name;
32 william 100 this.CreateProcessIcon(4);
33 william 88 }
34     public ProcContainer(Process process, Icon icon)
35     : this()
36     {
37     this.ProcessInfo = process; this.ProcessIcon = icon.ToBitmap();
38 william 101 string fname = ProcessModeleInfoEx.GetMainModulePath(process);
39 william 100 FileInfo fi = new FileInfo(fname);
40 william 88 this.FileName = fi.FullName;
41     this.Name = fi.Name;
42     }
43     public ProcContainer(Process process, Bitmap icon)
44     : this()
45     {
46     this.ProcessInfo = process; this.ProcessIcon = icon;
47 william 101 string fname = ProcessModeleInfoEx.GetMainModulePath(process);
48 william 100 FileInfo fi = new FileInfo(fname);
49 william 88 this.FileName = fi.FullName;
50     this.Name = fi.Name;
51     }
52     private void init() { this.ProcessInfo = null; this.ProcessIcon = null; }
53    
54    
55     public string Name { get; set; }
56     public string FileName { get; set; }
57    
58     private Process _ProcessInfo;
59     public Process ProcessInfo { get { return _ProcessInfo; } set { _ProcessInfo = value; } }
60     private Bitmap _ProcessIcon;
61     public Bitmap ProcessIcon { get { return _ProcessIcon; } set { _ProcessIcon = value; } }
62    
63     public override string ToString()
64     {
65 william 100 return this.FileName;
66 william 88 }
67    
68 william 100 public static Bitmap CreateIconFromProcess(ProcContainer proc)
69 william 88 {
70     if (proc == null) return null;
71 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true);
72     if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false);
73 william 109 Bitmap ret = null;
74     if (large != null)
75     ret = large.ToBitmap();
76 william 107 if (ret == null)
77     {
78 william 109 return null;
79 william 107 }
80     return ret;
81 william 88 }
82 william 100 public static Bitmap CreateIconFromProcess(ProcContainer proc, int Scale)
83 william 88 {
84     if (proc == null) return null;
85 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true);
86     if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false);
87 william 109 Bitmap ret = null;
88     if (large != null)
89     ret = large.ToBitmap();
90 william 107 if (ret == null)
91     {
92 william 109 return null;
93 william 107 }
94 william 88 ret = new Bitmap(ret, ret.Width * Scale, ret.Height * Scale);
95     return ret;
96     }
97 william 100 public static Bitmap CreateIconFromProcess(ProcContainer proc, int Width, int Height)
98 william 88 {
99     if (proc == null) return null;
100 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true);
101     if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false);
102 william 109 Bitmap ret = null;
103     if (large != null)
104     ret = large.ToBitmap();
105 william 107 if (ret == null)
106     {
107 william 109 return null;
108 william 107 }
109 william 88 ret = new Bitmap(ret, Width, Height);
110     return ret;
111     }
112     private void CreateProcessIcon()
113     {
114     if (this.ProcessInfo == null) return;
115 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true);
116     if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false);
117 william 109 Bitmap ret = null;
118     if (large != null)
119     ret = large.ToBitmap();
120 william 107 if (ret == null)
121     {
122 william 109 this.ProcessIcon = null;
123     return;
124 william 107 }
125     this.ProcessIcon = ret;
126 william 88 }
127     private void CreateProcessIcon(int Scale)
128     {
129 william 109 if (this.ProcessInfo == null) return;
130 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true);
131     if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false);
132 william 109 Bitmap ret = null;
133     if (large != null)
134     ret = large.ToBitmap();
135 william 107 if (ret == null)
136     {
137 william 109 this.ProcessIcon = null;
138     return;
139 william 107 }
140 william 109 ////Bitmap bmp = large.ToBitmap();
141     //string save_path = @"c:\temp";
142     //string icon_file = string.Format(@"{0}\{1}.bmp", save_path, new FileInfo(this.FileName).Name);
143    
144    
145     ret = new Bitmap(ret, ret.Width * Scale, ret.Height * Scale);
146     //ret.Save(icon_file, System.Drawing.Imaging.ImageFormat.Bmp);
147 william 88 this.ProcessIcon = ret;
148     }
149     private void CreateProcessIcon(int Width, int Height)
150     {
151     if (this.ProcessInfo == null) return;
152 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true);
153     if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false);
154 william 109 Bitmap ret = null;
155     if (large != null)
156     ret = large.ToBitmap();
157 william 107 if (ret == null)
158     {
159 william 109 this.ProcessIcon = null;
160     return;
161 william 107 }
162     ret = new Bitmap(ret, Width, Height);
163 william 88 this.ProcessIcon = ret;
164     }
165     }
166     }

  ViewVC Help
Powered by ViewVC 1.1.22