ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater.PluginFramework/Core/ProcContainer.cs
Revision: 107
Committed: Thu May 10 11:16:03 2012 UTC (10 years, 10 months ago) by william
File size: 5297 byte(s)
Log Message:

File Contents

# User Rev Content
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     Bitmap ret = large.ToBitmap();
74     if (ret == null)
75     {
76     int i = 0;
77     }
78     return ret;
79 william 88 }
80 william 100 public static Bitmap CreateIconFromProcess(ProcContainer proc, int Scale)
81 william 88 {
82     if (proc == null) return null;
83 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true);
84     if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false);
85     Bitmap ret = large.ToBitmap();
86     if (ret == null)
87     {
88     int i = 0;
89     }
90 william 88 ret = new Bitmap(ret, ret.Width * Scale, ret.Height * Scale);
91     return ret;
92     }
93 william 100 public static Bitmap CreateIconFromProcess(ProcContainer proc, int Width, int Height)
94 william 88 {
95     if (proc == null) return null;
96 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(proc.FileName, true);
97     if (large == null) large = ProcessIconEx.ExtractIConFromFile(proc.FileName, false);
98     Bitmap ret = large.ToBitmap();
99     if (ret == null)
100     {
101     int i = 0;
102     }
103 william 88 ret = new Bitmap(ret, Width, Height);
104     return ret;
105     }
106     private void CreateProcessIcon()
107     {
108     if (this.ProcessInfo == null) return;
109 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true);
110     if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false);
111     Bitmap ret = large.ToBitmap();
112     if (ret == null)
113     {
114     int i = 0;
115     }
116     this.ProcessIcon = ret;
117 william 88 }
118     private void CreateProcessIcon(int Scale)
119     {
120 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true);
121     if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false);
122     Bitmap ret = large.ToBitmap();
123     if (ret == null)
124     {
125     int i = 0;
126     }
127     ret = new Bitmap(ret, ret.Width * Scale, ret.Height * Scale);
128 william 88 this.ProcessIcon = ret;
129     }
130     private void CreateProcessIcon(int Width, int Height)
131     {
132     if (this.ProcessInfo == null) return;
133 william 107 Icon large = ProcessIconEx.ExtractIConFromFile(this.FileName, true);
134     if (large == null) large = ProcessIconEx.ExtractIConFromFile(this.FileName, false);
135     Bitmap ret = large.ToBitmap();
136     if (ret == null)
137     {
138     int i = 0;
139     }
140     ret = new Bitmap(ret, Width, Height);
141 william 88 this.ProcessIcon = ret;
142     }
143     }
144     }