5
5
using System ;
6
6
7
7
public class RhinoResolver {
8
+ private const string Coredllpath = "CoreDllPath" ;
8
9
private static string rhinoSystemDirectory ;
10
+ const string RhinoKey = "SOFTWARE\\ McNeel\\ Rhinoceros" ;
9
11
10
12
public static string RhinoSystemDirectory {
11
13
get {
@@ -20,6 +22,7 @@ public static string RhinoSystemDirectory {
20
22
21
23
public static int RhinoMajorVersion { get ; set ; }
22
24
25
+
23
26
public static void Initialize ( ) {
24
27
if ( IntPtr . Size != 8 ) {
25
28
throw new Exception ( "Only 64 bit applications can use Rhino" ) ;
@@ -39,21 +42,20 @@ private static Assembly ResolveForRhinoAssemblies(object sender, ResolveEventArg
39
42
return null ;
40
43
}
41
44
42
- private static string FindRhinoSystemDirectory ( ) {
45
+ public static string FindRhinoSystemDirectory ( ) {
43
46
bool useLatest = RhinoMajorVersion < 0 ;
44
47
45
- string name = "SOFTWARE\\ McNeel\\ Rhinoceros" ;
46
- using ( RegistryKey registryKey = Registry . LocalMachine . OpenSubKey ( name ) ) {
47
- string [ ] subKeyNames = registryKey . GetSubKeyNames ( ) ;
48
- Array . Sort ( subKeyNames ) ;
49
- string text = "" ;
48
+ string [ ] subKeyNames = GetSubKeys ( RhinoKey ) ;
49
+
50
+ using ( RegistryKey registryKey = Registry . LocalMachine . OpenSubKey ( RhinoKey ) ) {
51
+ string text = string . Empty ;
50
52
for ( int num = subKeyNames . Length - 1 ; num >= 0 ; num -- ) {
51
53
if ( double . TryParse ( subKeyNames [ num ] , NumberStyles . Any , CultureInfo . InvariantCulture , out double result ) ) {
52
54
text = subKeyNames [ num ] ;
53
55
if ( useLatest || ( int ) Math . Floor ( result ) == RhinoMajorVersion ) {
54
56
using RegistryKey registryKey2 = registryKey . OpenSubKey ( text + "\\ Install" ) ;
55
57
try {
56
- object value = registryKey2 . GetValue ( "CoreDllPath" ) ;
58
+ object value = registryKey2 . GetValue ( Coredllpath ) ;
57
59
if ( value == null )
58
60
continue ;
59
61
if ( value is string path && File . Exists ( path ) ) {
@@ -70,4 +72,16 @@ private static string FindRhinoSystemDirectory() {
70
72
71
73
return null ;
72
74
}
75
+
76
+ public string [ ] GetRhinoSubKeys ( ) {
77
+ return GetSubKeys ( RhinoKey ) ;
78
+ }
79
+
80
+ public static string [ ] GetSubKeys ( string rhinoKey ) {
81
+ using ( RegistryKey registryKey = Registry . LocalMachine . OpenSubKey ( rhinoKey ) ) {
82
+ string [ ] subKeyNames = registryKey . GetSubKeyNames ( ) ;
83
+ Array . Sort ( subKeyNames ) ;
84
+ return subKeyNames ;
85
+ }
86
+ }
73
87
}
0 commit comments