|
20 | 20 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
21 | 21 |
|
22 | 22 | using System; |
| 23 | +using System.Collections.Generic; |
| 24 | +using System.IO; |
| 25 | +using System.Reflection; |
23 | 26 | using System.Runtime.InteropServices; |
24 | 27 |
|
25 | 28 | namespace CppSharp |
@@ -57,31 +60,27 @@ static SymbolResolver () |
57 | 60 |
|
58 | 61 | public static IntPtr LoadImage (ref string name) |
59 | 62 | { |
60 | | - var pathvalues = Environment.GetEnvironmentVariable("PATH"); |
| 63 | + var pathValues = Environment.GetEnvironmentVariable("PATH"); |
| 64 | + var paths = new List<string>(pathValues == null ? new string[0] : |
| 65 | + pathValues.Split(Path.PathSeparator)); |
| 66 | + paths.Insert(0, Directory.GetCurrentDirectory()); |
| 67 | + paths.Insert(0, Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); |
61 | 68 |
|
62 | 69 | foreach (var format in formats) |
63 | 70 | { |
64 | 71 | // Search the Current or specified directory for the library |
65 | 72 | string filename = string.Format(format, name); |
66 | | - string attempted = System.IO.Path.Combine(Environment.CurrentDirectory, filename); |
67 | | - if (!System.IO.File.Exists(attempted)) |
| 73 | + string attempted = null; |
| 74 | + foreach (var path in paths) |
68 | 75 | { |
69 | | - // Search the Path directories for the library |
70 | | - if (pathvalues == null) |
71 | | - continue; |
72 | | - |
73 | | - foreach (var path in pathvalues.Split(System.IO.Path.PathSeparator)) |
| 76 | + var fullPath = Path.Combine(path, filename); |
| 77 | + if (File.Exists(fullPath)) |
74 | 78 | { |
75 | | - var fullPath = System.IO.Path.Combine(path, filename); |
76 | | - if (System.IO.File.Exists(fullPath)) |
77 | | - { |
78 | | - attempted = fullPath; |
79 | | - break; |
80 | | - } |
81 | | - |
| 79 | + attempted = fullPath; |
| 80 | + break; |
82 | 81 | } |
83 | 82 | } |
84 | | - if (!System.IO.File.Exists(attempted)) |
| 83 | + if (!File.Exists(attempted)) |
85 | 84 | continue; |
86 | 85 |
|
87 | 86 | var ptr = loadImage (attempted); |
|
0 commit comments