Skip to content

Commit aa06026

Browse files
authored
Merge pull request libgit2#1409 from libgit2/ethomson/managedpath
NativePath: use Assembly.CodeBase
2 parents 3fe02ab + 6745f1a commit aa06026

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

LibGit2Sharp/GlobalSettings.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,26 @@ static GlobalSettings()
2323
{
2424
if (Platform.OperatingSystem == OperatingSystemType.Windows)
2525
{
26-
string managedPath = new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath;
26+
/* Assembly.CodeBase is not actually a correctly formatted
27+
* URI. It's merely prefixed with `file:///` and has its
28+
* backslashes flipped. This is superior to EscapedCodeBase,
29+
* which does not correctly escape things, and ambiguates a
30+
* space (%20) with a literal `%20` in the path. Sigh.
31+
*/
32+
var managedPath = Assembly.GetExecutingAssembly().CodeBase;
33+
if (managedPath == null)
34+
{
35+
managedPath = Assembly.GetExecutingAssembly().Location;
36+
}
37+
else if (managedPath.StartsWith("file:///"))
38+
{
39+
managedPath = managedPath.Substring(8).Replace('/', '\\');
40+
}
41+
else if (managedPath.StartsWith("file://"))
42+
{
43+
managedPath = @"\\" + managedPath.Substring(7).Replace('/', '\\');
44+
}
45+
2746
nativeLibraryPath = Path.Combine(Path.Combine(Path.GetDirectoryName(managedPath), "lib"), "win32");
2847
}
2948

0 commit comments

Comments
 (0)