2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
4
using System . Reflection ;
5
+ using System . Runtime . InteropServices ;
5
6
using LibGit2Sharp . Core ;
6
7
7
8
namespace LibGit2Sharp
@@ -13,6 +14,7 @@ public static class GlobalSettings
13
14
{
14
15
private static readonly Lazy < Version > version = new Lazy < Version > ( Version . Build ) ;
15
16
private static readonly Dictionary < Filter , FilterRegistration > registeredFilters ;
17
+ private static readonly bool nativeLibraryPathAllowed ;
16
18
17
19
private static LogConfiguration logConfiguration = LogConfiguration . None ;
18
20
@@ -21,7 +23,9 @@ public static class GlobalSettings
21
23
22
24
static GlobalSettings ( )
23
25
{
24
- if ( Platform . OperatingSystem == OperatingSystemType . Windows )
26
+ nativeLibraryPathAllowed = Platform . IsRunningOnNetFramework ( ) ;
27
+
28
+ if ( nativeLibraryPathAllowed )
25
29
{
26
30
/* Assembly.CodeBase is not actually a correctly formatted
27
31
* URI. It's merely prefixed with `file:///` and has its
@@ -148,23 +152,24 @@ public static LogConfiguration LogConfiguration
148
152
}
149
153
150
154
/// <summary>
151
- /// Sets a hint path for searching for native binaries: when
152
- /// specified, native binaries will first be searched in a
153
- /// subdirectory of the given path corresponding to the operating
154
- /// system and architecture (eg, "x86" or "x64") before falling
155
- /// back to the default path ("lib\win32\x86" or "lib\win32\x64"
156
- /// next to the application).
155
+ /// Sets a path for loading native binaries on .NET Framework.
156
+ /// When specified, native .dll will first be searched in a
157
+ /// subdirectory of the given path corresponding to the
158
+ /// architecture ("x86" or "x64") before falling
159
+ /// back to searching the default load directories
160
+ /// (<see cref="DllImportSearchPath.AssemblyDirectory"/>,
161
+ /// <see cref="DllImportSearchPath.ApplicationDirectory"/> and
162
+ /// <see cref="DllImportSearchPath.SafeDirectories"/>).
157
163
/// <para>
158
164
/// This must be set before any other calls to the library,
159
- /// and is not available on Unix platforms: see your dynamic
160
- /// library loader's documentation for details.
165
+ /// and is not available on other platforms than .NET Framework.
161
166
/// </para>
162
167
/// </summary>
163
168
public static string NativeLibraryPath
164
169
{
165
170
get
166
171
{
167
- if ( Platform . OperatingSystem != OperatingSystemType . Windows )
172
+ if ( ! nativeLibraryPathAllowed )
168
173
{
169
174
throw new LibGit2SharpException ( "Querying the native hint path is only supported on Windows platforms" ) ;
170
175
}
@@ -174,7 +179,7 @@ public static string NativeLibraryPath
174
179
175
180
set
176
181
{
177
- if ( Platform . OperatingSystem != OperatingSystemType . Windows )
182
+ if ( ! nativeLibraryPathAllowed )
178
183
{
179
184
throw new LibGit2SharpException ( "Setting the native hint path is only supported on Windows platforms" ) ;
180
185
}
@@ -184,14 +189,21 @@ public static string NativeLibraryPath
184
189
throw new LibGit2SharpException ( "You cannot set the native library path after it has been loaded" ) ;
185
190
}
186
191
187
- nativeLibraryPath = value ;
192
+ try
193
+ {
194
+ nativeLibraryPath = Path . GetFullPath ( value ) ;
195
+ }
196
+ catch ( Exception e )
197
+ {
198
+ throw new LibGit2SharpException ( e . Message ) ;
199
+ }
188
200
}
189
201
}
190
202
191
203
internal static string GetAndLockNativeLibraryPath ( )
192
204
{
193
205
nativeLibraryPathLocked = true ;
194
- return nativeLibraryPath ;
206
+ return Path . Combine ( nativeLibraryPath , Platform . ProcessorArchitecture ) ;
195
207
}
196
208
197
209
/// <summary>
0 commit comments