diff options
Diffstat (limited to 'src/test/burn/TestExe')
-rw-r--r-- | src/test/burn/TestExe/Task.cs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/test/burn/TestExe/Task.cs b/src/test/burn/TestExe/Task.cs index 59f774fb..0d283c6c 100644 --- a/src/test/burn/TestExe/Task.cs +++ b/src/test/burn/TestExe/Task.cs | |||
@@ -2,8 +2,10 @@ | |||
2 | 2 | ||
3 | using System; | 3 | using System; |
4 | using System.Collections.Generic; | 4 | using System.Collections.Generic; |
5 | using System.ComponentModel; | ||
5 | using System.Diagnostics; | 6 | using System.Diagnostics; |
6 | using System.IO; | 7 | using System.IO; |
8 | using System.Runtime.InteropServices; | ||
7 | using Microsoft.Win32; | 9 | using Microsoft.Win32; |
8 | 10 | ||
9 | namespace TestExe | 11 | namespace TestExe |
@@ -151,6 +153,67 @@ namespace TestExe | |||
151 | } | 153 | } |
152 | } | 154 | } |
153 | 155 | ||
156 | public class DeleteManifestsTask : Task | ||
157 | { | ||
158 | public DeleteManifestsTask(string Data) : base(Data) { } | ||
159 | |||
160 | public override void RunTask() | ||
161 | { | ||
162 | string filePath = System.Environment.ExpandEnvironmentVariables(this.data); | ||
163 | IntPtr type = new IntPtr(24); //RT_MANIFEST | ||
164 | IntPtr name = new IntPtr(1); //CREATEPROCESS_MANIFEST_RESOURCE_ID | ||
165 | DeleteResource(filePath, type, name, 1033); | ||
166 | } | ||
167 | |||
168 | private static void DeleteResource(string filePath, IntPtr type, IntPtr name, ushort language, bool throwOnError = false) | ||
169 | { | ||
170 | bool discard = true; | ||
171 | IntPtr handle = BeginUpdateResourceW(filePath, false); | ||
172 | try | ||
173 | { | ||
174 | if (handle == IntPtr.Zero) | ||
175 | { | ||
176 | throw new Win32Exception(); | ||
177 | } | ||
178 | |||
179 | if (!UpdateResourceW(handle, type, name, language, IntPtr.Zero, 0)) | ||
180 | { | ||
181 | throw new Win32Exception(); | ||
182 | } | ||
183 | |||
184 | discard = false; | ||
185 | } | ||
186 | catch | ||
187 | { | ||
188 | if (throwOnError) | ||
189 | { | ||
190 | throw; | ||
191 | } | ||
192 | } | ||
193 | finally | ||
194 | { | ||
195 | if (handle != IntPtr.Zero) | ||
196 | { | ||
197 | if (!EndUpdateResourceW(handle, discard) && throwOnError) | ||
198 | { | ||
199 | throw new Win32Exception(); | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | } | ||
204 | |||
205 | [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] | ||
206 | private extern static IntPtr BeginUpdateResourceW(string fileName, [MarshalAs(UnmanagedType.Bool)] bool deleteExistingResources); | ||
207 | |||
208 | [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] | ||
209 | [return: MarshalAs(UnmanagedType.Bool)] | ||
210 | private extern static bool UpdateResourceW(IntPtr hUpdate, IntPtr type, IntPtr name, ushort language, IntPtr pData, uint cb); | ||
211 | |||
212 | [DllImport("kernel32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)] | ||
213 | [return: MarshalAs(UnmanagedType.Bool)] | ||
214 | private extern static bool EndUpdateResourceW(IntPtr hUpdate, [MarshalAs(UnmanagedType.Bool)] bool discard); | ||
215 | } | ||
216 | |||
154 | public class TaskParser | 217 | public class TaskParser |
155 | { | 218 | { |
156 | 219 | ||
@@ -197,6 +260,10 @@ namespace TestExe | |||
197 | t = new FileExistsTask(args[i + 1]); | 260 | t = new FileExistsTask(args[i + 1]); |
198 | tasks.Add(t); | 261 | tasks.Add(t); |
199 | break; | 262 | break; |
263 | case "/dm": | ||
264 | t = new DeleteManifestsTask(args[i + 1]); | ||
265 | tasks.Add(t); | ||
266 | break; | ||
200 | #if NET35 | 267 | #if NET35 |
201 | case "/pinfo": | 268 | case "/pinfo": |
202 | t = new ProcessInfoTask(args[i + 1]); | 269 | t = new ProcessInfoTask(args[i + 1]); |