forked from content-manager-sdk/Community
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDKLoader.cs
More file actions
70 lines (62 loc) · 1.58 KB
/
Copy pathSDKLoader.cs
File metadata and controls
70 lines (62 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
namespace SampleAddIn
{
internal class SDKLoader
{
private static string FindInstalledTRIMPath()
{
RegistryKey[] registryHives =
{
Registry.LocalMachine,
Registry.CurrentUser
};
string[] registryPaths =
{
@"SOFTWARE\Micro Focus\Content Manager\MSISettings",
@"SOFTWARE\Hewlett-Packard\HP TRIM\MSISettings"
};
string INSTALLDIR = "INSTALLDIR";
foreach (var hive in registryHives)
{
foreach (var regPath in registryPaths)
{
RegistryKey msiSettingsKey = hive.OpenSubKey(regPath);
if (msiSettingsKey != null)
{
string installDir = msiSettingsKey.GetValue(INSTALLDIR) as string;
if (installDir != null && installDir.Length > 0)
{
return installDir;
}
}
}
}
return null;
}
private static Assembly AssemblyResolveEventHandler(object sender, ResolveEventArgs args, string pathToSdkDll)
{
if (args.Name.Contains("HP.HPTRIM.SDK"))
{
Assembly assembly = Assembly.LoadFrom(pathToSdkDll);
return assembly;
}
return null;
}
public static void load()
{
string installDir = FindInstalledTRIMPath();
if (string.IsNullOrWhiteSpace(installDir))
{
throw new Exception("Unable to find path to HP.HPTRIM.SDK in registry.");
}
string pathToSdkDll = Path.Combine(installDir, "HP.HPTRIM.SDK.dll");
AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => AssemblyResolveEventHandler(sender, e, pathToSdkDll);
}
}
}