private ResolvePathResult ScanPathForLibrary(string path, string library) { var libraryLocation = Path.GetFullPath(Path.Combine(path, library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } // Check the local library directory libraryLocation = Path.GetFullPath(Path.Combine(path, "lib", library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } // Check platform-specific directory var bitness = Environment.Is64BitProcess ? "x64" : "x86"; libraryLocation = Path.GetFullPath(Path.Combine(path, "lib", bitness, library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } return(ResolvePathResult.FromError(new FileNotFoundException("No local copy of the given library could be found.", library))); }
public ResolvePathResult Resolve(string library) { // First, check next to the entry executable if (!(_entryAssemblyDirectory is null)) { var result = ScanPathForLibrary(_entryAssemblyDirectory, library); if (result.IsSuccess) { return(result); } } if (!(_executingAssemblyDirectory is null)) { var result = ScanPathForLibrary(_executingAssemblyDirectory, library); if (result.IsSuccess) { return(result); } } // Then, check the current directory if (!(_currentDirectory is null)) { var result = ScanPathForLibrary(_currentDirectory, library); if (result.IsSuccess) { return(result); } } return(ResolvePathResult.FromError(new FileNotFoundException("No local copy of the given library could be found.", library))); }
public ResolvePathResult Resolve(string library) { var libraryPaths = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH")?.Split(':').Where(p => !string.IsNullOrEmpty(p)); string libraryLocation; if (!(libraryPaths is null)) { foreach (var path in libraryPaths) { libraryLocation = Path.GetFullPath(Path.Combine(path, library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } } } if (File.Exists("/etc/ld.so.cache")) { var cachedLibraries = File.ReadAllText("/etc/ld.so.cache").Split('\0'); var cachedMatch = cachedLibraries.FirstOrDefault ( l => l.EndsWith(library) && Path.GetFileName(l) == Path.GetFileName(library) ); if (!(cachedMatch is null)) { return(ResolvePathResult.FromSuccess(cachedMatch)); } } libraryLocation = Path.GetFullPath(Path.Combine("/lib", library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } libraryLocation = Path.GetFullPath(Path.Combine("/usr/lib", library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } return(ResolvePathResult.FromError(new FileNotFoundException("The specified library was not found in any of the loader search paths.", library))); }
public ResolvePathResult Resolve(string library) { foreach (var variable in EnvironmentVariables) { var libraryPaths = Environment.GetEnvironmentVariable(variable)?.Split(':').Where(p => !string.IsNullOrEmpty(p)); if (libraryPaths is null) { continue; } foreach (var path in libraryPaths) { var libraryLocation = Path.GetFullPath(Path.Combine(path, library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } } } return(ResolvePathResult.FromError(new FileNotFoundException("The specified library was not found in any of the loader search paths.", library))); }
public ResolvePathResult Resolve(string library) { string libraryLocation; var entryAssembly = Assembly.GetEntryAssembly(); if (!(entryAssembly is null) && Directory.GetParent(entryAssembly.Location) is var parentDirectory) { var executingDir = parentDirectory.FullName; libraryLocation = Path.GetFullPath(Path.Combine(executingDir, library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } } var sysDir = Environment.SystemDirectory; libraryLocation = Path.GetFullPath(Path.Combine(sysDir, library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } var windowsDir = Environment.GetFolderPath(Environment.SpecialFolder.Windows); var sys16Dir = Path.Combine(windowsDir, "System"); libraryLocation = Path.GetFullPath(Path.Combine(sys16Dir, library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } libraryLocation = Path.GetFullPath(Path.Combine(windowsDir, library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } var currentDir = Directory.GetCurrentDirectory(); libraryLocation = Path.GetFullPath(Path.Combine(currentDir, library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } var pathVar = Environment.GetEnvironmentVariable("PATH"); if (!(pathVar is null)) { var pathDirs = pathVar.Split(';').Where(p => !string.IsNullOrEmpty(p)); foreach (var path in pathDirs) { libraryLocation = Path.GetFullPath(Path.Combine(path, library)); if (File.Exists(libraryLocation)) { return(ResolvePathResult.FromSuccess(libraryLocation)); } } } return(ResolvePathResult.FromError(new FileNotFoundException("The specified library was not found in any of the loader search paths.", library))); }
private ResolvePathResult ResolveAbsolutePath(string library, bool localFirst) { var candidates = GenerateLibraryCandidates(library).ToList(); if (library.IsValidPath()) { foreach (var candidate in candidates) { if (File.Exists(candidate)) { return(ResolvePathResult.FromSuccess(Path.GetFullPath(candidate))); } } } // Check the native probing paths (.NET Core defines this, Mono doesn't. Users can set this at runtime, too) if (AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES") is string directories) { var paths = directories.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); foreach (var path in paths) { foreach (var candidate in candidates) { var candidatePath = Path.Combine(path, candidate); if (File.Exists(candidatePath)) { return(ResolvePathResult.FromSuccess(Path.GetFullPath(candidatePath))); } } } } if (localFirst) { foreach (var candidate in candidates) { var result = LocalPathResolver.Resolve(candidate); if (result.IsSuccess) { return(result); } } } foreach (var candidate in candidates) { var result = PathResolver.Resolve(candidate); if (result.IsSuccess) { return(result); } } if (library == "__Internal") { // Mono extension: Search the main program. Allowed for all runtimes return(ResolvePathResult.FromSuccess(null)); } return(ResolvePathResult.FromError(new FileNotFoundException("The specified library was not found in any of the loader search paths.", library))); }