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