-
Notifications
You must be signed in to change notification settings - Fork 925
Expand file tree
/
Copy pathTestApp.cs
More file actions
46 lines (38 loc) · 1.38 KB
/
TestApp.cs
File metadata and controls
46 lines (38 loc) · 1.38 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
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace LibGit2Sharp.Tests
{
public class TestApp
{
[DllImport("kernel32")]
private static extern IntPtr GetModuleHandle(string path);
[DllImport("kernel32")]
private static extern int GetModuleFileName(IntPtr handle, [Out] StringBuilder path, int size);
static int Main(string[] args)
{
if (args.Length < 1 || args.Length > 2)
{
Console.Error.WriteLine("Usage: <module-name> <directory>");
return -1;
}
var moduleName = args[0];
var loadFromDirectory = args[1];
var expectedPath = Path.Combine(loadFromDirectory, moduleName + ".dll");
GlobalSettings.NativeLibraryPath = loadFromDirectory;
var isValid = Repository.IsValid(Path.GetTempPath());
var capacity = ushort.MaxValue;
var moduleHandle = GetModuleHandle(moduleName);
var buffer = new StringBuilder(capacity);
int actualLength = GetModuleFileName(moduleHandle, buffer, capacity);
var actualPath = buffer.ToString(0, actualLength);
if (expectedPath != actualPath)
{
Console.WriteLine(actualPath);
return 1;
}
return 0;
}
}
}