-
Notifications
You must be signed in to change notification settings - Fork 910
Introduce GlobalSettings.NativeLibraryPath
#992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace LibGit2Sharp.Core | ||
{ | ||
internal enum OperatingSystemType | ||
{ | ||
Windows, | ||
Unix, | ||
MacOSX | ||
} | ||
|
||
internal class Platform | ||
{ | ||
public static string ProcessorArchitecture | ||
{ | ||
get | ||
{ | ||
if (Environment.Is64BitProcess) | ||
{ | ||
return "amd64"; | ||
} | ||
|
||
return "x86"; | ||
} | ||
} | ||
|
||
public static OperatingSystemType OperatingSystem | ||
{ | ||
get | ||
{ | ||
// See http://www.mono-project.com/docs/faq/technical/#how-to-detect-the-execution-platform | ||
var platformId = (int)Environment.OSVersion.Platform; | ||
|
||
switch ((int)Environment.OSVersion.Platform) | ||
{ | ||
case 4: | ||
case 128: | ||
return OperatingSystemType.Unix; | ||
case 6: | ||
return OperatingSystemType.MacOSX; | ||
default: | ||
return OperatingSystemType.Windows; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using LibGit2Sharp.Core; | ||
|
||
namespace LibGit2Sharp | ||
|
@@ -12,6 +14,18 @@ public static class GlobalSettings | |
|
||
private static LogConfiguration logConfiguration = LogConfiguration.None; | ||
|
||
private static string nativeLibraryPath; | ||
private static bool nativeLibraryPathLocked; | ||
|
||
static GlobalSettings() | ||
{ | ||
if (Platform.OperatingSystem == OperatingSystemType.Windows) | ||
{ | ||
string managedPath = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath; | ||
nativeLibraryPath = Path.Combine(Path.GetDirectoryName(managedPath), "NativeBinaries"); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns information related to the current LibGit2Sharp | ||
/// library. | ||
|
@@ -108,5 +122,52 @@ public static LogConfiguration LogConfiguration | |
return logConfiguration; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Sets a hint path for searching for native binaries: when | ||
/// specified, native binaries will first be searched in a | ||
/// subdirectory of the given path corresponding to the architecture | ||
/// (eg, "x86" or "amd64") before falling back to the default | ||
/// path ("NativeBinaries\x86" or "NativeBinaries\amd64" next | ||
/// to the application). | ||
/// <para> | ||
/// This must be set before any other calls to the library, | ||
/// and is not available on Unix platforms: see your dynamic | ||
/// library loader's documentation for details. | ||
/// </para> | ||
/// </summary> | ||
public static string NativeLibraryPath | ||
{ | ||
get | ||
{ | ||
if (Platform.OperatingSystem != OperatingSystemType.Windows) | ||
{ | ||
throw new LibGit2SharpException("Querying the native hint path is only supported on Windows platforms"); | ||
} | ||
|
||
return nativeLibraryPath; | ||
} | ||
|
||
set | ||
{ | ||
if (Platform.OperatingSystem != OperatingSystemType.Windows) | ||
{ | ||
throw new LibGit2SharpException("Setting the native hint path is only supported on Windows platforms"); | ||
} | ||
|
||
if (nativeLibraryPathLocked) | ||
{ | ||
throw new LibGit2SharpException("You cannot set the native library path after it has been loaded"); | ||
} | ||
|
||
nativeLibraryPath = value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would there be a way to throw as well if any call to the native library has already been made? |
||
} | ||
} | ||
|
||
internal static string GetAndLockNativeLibraryPath() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
{ | ||
nativeLibraryPathLocked = true; | ||
return nativeLibraryPath; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/cc @carlosmn @Therzok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what I'm being asked for. :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha. I think he wants you to confirm that my documentation matches reality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like it's ok. http://www.mono-project.com/docs/advanced/pinvoke/#library-handling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Therzok Sorry for having pinged you without any context.
@ethomson ❤️