1 | /* $Id: MsiHackExtension.cs 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * MsiHackExtension - Wix Extension that loads MsiHack.dll
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2016-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | using Microsoft.Tools.WindowsInstallerXml;
|
---|
30 | using System; /* For Console. */
|
---|
31 | using System.Reflection; /* For Assembly*(). */
|
---|
32 | using System.Runtime.InteropServices; /* For DllImport. */
|
---|
33 | using System.IO; /* For Path. */
|
---|
34 |
|
---|
35 |
|
---|
36 |
|
---|
37 | [assembly: AssemblyTitle("org.virtualbox.wix.msi.speed.hack")]
|
---|
38 | [assembly: AssemblyDescription("Speeding up MSI.DLL")]
|
---|
39 | [assembly: AssemblyConfiguration("")]
|
---|
40 | [assembly: AssemblyCompany("Oracle Corporation")]
|
---|
41 | [assembly: AssemblyProduct("org.virtualbox.wix.msi.speed.hack")]
|
---|
42 | [assembly: AssemblyCopyright("Copyright (C) 2016")]
|
---|
43 | [assembly: AssemblyTrademark("")]
|
---|
44 | [assembly: AssemblyCulture("")]
|
---|
45 | [assembly: AssemblyDefaultWixExtension(typeof(MsiHackExtension))]
|
---|
46 |
|
---|
47 |
|
---|
48 | static class NativeMethods
|
---|
49 | {
|
---|
50 | [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
---|
51 | public static extern IntPtr LoadLibrary(string strPath);
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | public class MsiHackExtension : WixExtension
|
---|
56 | {
|
---|
57 | public MsiHackExtension()
|
---|
58 | {
|
---|
59 | /* Figure out where we are. */
|
---|
60 | string strCodeBase = Assembly.GetExecutingAssembly().CodeBase;
|
---|
61 | //Console.WriteLine("MsiHackExtension: strCodeBase={0}", strCodeBase);
|
---|
62 |
|
---|
63 | UriBuilder uri = new UriBuilder(strCodeBase);
|
---|
64 | string strPath = Uri.UnescapeDataString(uri.Path);
|
---|
65 | //Console.WriteLine("MsiHackExtension: strPath={0}", strPath);
|
---|
66 |
|
---|
67 | string strDir = Path.GetDirectoryName(strPath);
|
---|
68 | //Console.WriteLine("MsiHackExtension: strDir={0}", strDir);
|
---|
69 |
|
---|
70 | string strHackDll = strDir + "\\MsiHack.dll";
|
---|
71 | //Console.WriteLine("strHackDll={0}", strHackDll);
|
---|
72 |
|
---|
73 | try
|
---|
74 | {
|
---|
75 | IntPtr hHackDll = NativeMethods.LoadLibrary(strHackDll);
|
---|
76 | Console.WriteLine("MsiHackExtension: Loaded {0} at {1}!", strHackDll, hHackDll.ToString("X"));
|
---|
77 | }
|
---|
78 | catch (Exception Xcpt)
|
---|
79 | {
|
---|
80 | Console.WriteLine("MsiHackExtension: Exception loading {0}: {1}", strHackDll, Xcpt);
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|